How to use create_test_server method in tempest

Best Python code snippet using tempest_python

test_servers.py

Source: test_servers.py Github

copy

Full Screen

...19from mogan.tests.unit.db import base20from mogan.tests.unit.db import utils21class DbServerTestCase(base.DbTestCase):22 def test_server_create(self):23 utils.create_test_server()24 def test_server_create_with_same_uuid(self):25 utils.create_test_server(uuid='uuid', name='server1')26 self.assertRaises(exception.ServerAlreadyExists,27 utils.create_test_server,28 uuid='uuid',29 name='server2')30 def test_server_get_by_uuid(self):31 server = utils.create_test_server()32 res = self.dbapi.server_get(self.context, server.uuid)33 self.assertEqual(server.uuid, res.uuid)34 def test_server_get_not_exist(self):35 self.assertRaises(exception.ServerNotFound,36 self.dbapi.server_get,37 self.context,38 '12345678-9999-0000-aaaa-123456789012')39 def test_server_get_all(self):40 servers_project_1 = []41 servers_project_2 = []42 servers_project_all = []43 for i in range(0, 3):44 server = utils.create_test_server(45 uuid=uuidutils.generate_uuid(),46 project_id='project_1',47 name=str(i))48 servers_project_1.append(server)49 for i in range(3, 5):50 server = utils.create_test_server(51 uuid=uuidutils.generate_uuid(),52 project_id='project_2',53 name=str(i))54 servers_project_2.append(server)55 servers_project_all.extend(servers_project_1)56 servers_project_all.extend(servers_project_2)57 # Set project_only to False58 # get all servers from all projects59 res = self.dbapi.server_get_all(self.context, project_only=False)60 for i, item in enumerate(res):61 self.assertEqual(servers_project_all[i].uuid, item.uuid)62 # Filter by server name test63 res = self.dbapi.server_get_all(self.context, project_only=False,64 filters={"name": "1"})65 self.assertEqual(len(res), 1)66 self.assertEqual(res[0].name, "1")67 # Filter by server status test68 res = self.dbapi.server_get_all(self.context, project_only=False,69 filters={"status": "active"})70 for i, item in enumerate(res):71 self.assertEqual(item.status, "active")72 # Filter by flavor_uuid test73 res = self.dbapi.server_get_all(self.context, project_only=False,74 filters={"flavor_uuid":75 servers_project_all[0].76 flavor_uuid})77 for i, item in enumerate(res):78 self.assertEqual(item.flavor_uuid,79 servers_project_all[0].flavor_uuid)80 # Filter by image_uuid test81 res = self.dbapi.server_get_all(self.context, project_only=False,82 filters={"image_uuid":83 servers_project_all[0].84 image_uuid})85 for i, item in enumerate(res):86 self.assertEqual(item.image_uuid,87 servers_project_all[0].image_uuid)88 # Set project_only to True89 # get servers from current project (project_1)90 self.context.tenant = 'project_1'91 res = self.dbapi.server_get_all(self.context, project_only=True)92 res_uuids = [r.uuid for r in res]93 uuids_project_1 = [r.uuid for r in servers_project_1]94 six.assertCountEqual(self, uuids_project_1, res_uuids)95 # Set project_only to True96 # get servers from current project (project_2)97 self.context.tenant = 'project_2'98 res = self.dbapi.server_get_all(self.context, project_only=True)99 res_uuids = [r.uuid for r in res]100 uuids_project_2 = [r.uuid for r in servers_project_2]101 six.assertCountEqual(self, uuids_project_2, res_uuids)102 def test_server_destroy(self):103 server = utils.create_test_server()104 self.dbapi.server_destroy(self.context, server.uuid)105 self.assertRaises(exception.ServerNotFound,106 self.dbapi.server_get,107 self.context,108 server.uuid)109 def test_server_destroy_not_exist(self):110 self.assertRaises(exception.ServerNotFound,111 self.dbapi.server_destroy,112 self.context,113 '12345678-9999-0000-aaaa-123456789012')114 def test_server_update(self):115 server = utils.create_test_server()116 old_extra = server.extra117 new_extra = {'foo': 'bar'}118 self.assertNotEqual(old_extra, new_extra)119 res = self.dbapi.server_update(self.context,120 server.uuid,121 {'extra': new_extra})122 self.assertEqual(new_extra, res.extra)123 def test_server_update_with_invalid_parameter_value(self):124 server = utils.create_test_server()125 self.assertRaises(exception.InvalidParameterValue,126 self.dbapi.server_update,127 self.context,128 server.uuid,129 {'uuid': '12345678-9999-0000-aaaa-123456789012'})130 def test_server_update_not_exist(self):131 self.assertRaises(exception.ServerNotFound,132 self.dbapi.server_update,133 self.context,134 '12345678-9999-0000-aaaa-123456789012',135 {'foo': 'bar'})136 def test_tags_get_destroyed_after_destroying_a_server(self):137 server = utils.create_test_server(id=123)138 tag = utils.create_test_server_tag(self.context, server_id=server.id)139 self.assertTrue(self.dbapi.server_tag_exists(self.context,140 server.id, tag.tag))141 self.dbapi.server_destroy(self.context, server.id)142 self.assertRaises(exception.ServerNotFound,143 self.dbapi.server_tag_exists,144 self.context, server.id, tag.tag)145 def test_tags_get_destroyed_after_destroying_a_server_by_uuid(self):146 server = utils.create_test_server(id=124)147 tag = utils.create_test_server_tag(self.context, server_id=server.id)148 self.assertTrue(self.dbapi.server_tag_exists(self.context,149 server.id, tag.tag))150 self.dbapi.server_destroy(self.context, server.uuid)151 self.assertRaises(exception.ServerNotFound,152 self.dbapi.server_tag_exists,...

Full Screen

Full Screen

test_component.py

Source: test_component.py Github

copy

Full Screen

1import json2from server import create_test_server3def test_report():4 flask_app = create_test_server(500, 500, 100, 0)5 with flask_app.test_client() as test_client:6 response = test_client.get('/​coffee-maker/​report')7 assert response.status_code == 2008 assert b'current resource values. e.g. \n water: 500ml \n milk: 500ml \n coffee: 100gm \n money: 0$' in response.data9def test_order_creation_insufficient_coins_scenario():10 flask_app = create_test_server(500, 500, 100, 0)11 with flask_app.test_client() as test_client:12 request = {13 'coffeeType': 'espresso',14 'quarters': 3,15 'dimes': 0,16 'nickels': 0,17 'pennies': 018 }19 response = test_client.post('/​coffee-maker/​order',20 data=json.dumps(request),21 content_type="application/​json",22 )23 assert response.status_code == 42224 assert b"Sorry that's not enough money. Money refunded." in response.data25def test_order_creation_insufficient_resources_scenario():26 flask_app = create_test_server(10, 10, 0, 0)27 with flask_app.test_client() as test_client:28 request = {29 'coffeeType': 'espresso',30 'quarters': 30,31 'dimes': 0,32 'nickels': 0,33 'pennies': 034 }35 response = test_client.post('/​coffee-maker/​order',36 data=json.dumps(request),37 content_type="application/​json",38 )39 assert response.status_code == 50040 assert b"Sorry resources are not available!" in response.data41def test_order_creation_scenario():42 flask_app = create_test_server(500, 500, 100, 0)43 with flask_app.test_client() as test_client:44 request = {45 'coffeeType': 'espresso',46 'quarters': 300,47 'dimes': 0,48 'nickels': 0,49 'pennies': 050 }51 response = test_client.post('/​coffee-maker/​order',52 data=json.dumps(request),53 content_type="application/​json",54 )55 assert response.status_code == 20056def test_order_get_not_found_scenario():57 flask_app = create_test_server(500, 500, 100, 0)58 with flask_app.test_client() as test_client:59 response = test_client.get('/​coffee-maker/​orders/​0')60 assert response.status_code == 40461def test_orders_get_found_scenario():62 flask_app = create_test_server(500, 500, 100, 0)63 with flask_app.test_client() as test_client:64 request = {65 'coffeeType': 'espresso',66 'quarters': 300,67 'dimes': 0,68 'nickels': 0,69 'pennies': 070 }71 response = test_client.post('/​coffee-maker/​order',72 data=json.dumps(request),73 content_type="application/​json",74 )75 data = response.get_data()76 # TODO: Below line tells that response should be a json instead of string, fix it later77 order_id = str(data).split(':')[1].split('.')[0]78 response = test_client.get(f'/​coffee-maker/​orders/​{order_id}')79 assert response.status_code == 20080def test_orders_get_all_scenario():81 flask_app = create_test_server(500, 500, 100, 0)82 with flask_app.test_client() as test_client:83 request = {84 'coffeeType': 'espresso',85 'quarters': 300,86 'dimes': 0,87 'nickels': 0,88 'pennies': 089 }90 test_client.post('/​coffee-maker/​order',91 data=json.dumps(request),92 content_type="application/​json",93 )94 test_client.post('/​coffee-maker/​order',95 data=json.dumps(request),...

Full Screen

Full Screen

test_ping.py

Source: test_ping.py Github

copy

Full Screen

...25 @classmethod26 def resource_cleanup(cls):27 super(PingTest, cls).resource_cleanup()28 def test_server(self):29 server = self.create_test_server(volume_backed=False)30 self.wait_until_server_is_reachable(server)31 def test_ping_2_servers(self):32 server1 = self.create_test_server(volume_backed=False,33 availability_zone='nova:%s'34 % OpenstackEnv.hypervisors.items()[0][0])35 server2 = self.create_test_server(volume_backed=False,36 availability_zone='nova:%s'37 % OpenstackEnv.hypervisors.items()[1][0])38 self.wait_until_server_is_reachable(server1)39 self.wait_until_server_is_reachable(server2)40 ip = server2.openstack_info['addresses'].items()[0][1][0]['addr']41 server1.ping(ip)42 def test_ping_one_vm_on_all_hosts(self):43 servers = []44 for (name, hypervisor) in OpenstackEnv.hypervisors.iteritems():45 servers.append(self.create_test_server(volume_backed=False,46 availability_zone='nova:%s'47 % hypervisor.name))48 ip_server_dict = {}49 for server in servers:50 self.wait_until_server_is_reachable(server)51 ip_server_dict[(server.openstack_info['addresses'].items()[0][1][0]['addr'])] = server52 atleast_one_failed = False53 for server in servers:54 for ip in ip_server_dict:55 try:56 server.ping(ip)57 except Exception:58 atleast_one_failed = True59 LOG.error("Server: %(src_server)s was not able to "...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Rebuild Confidence in Your Test Automation

These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.

What will come after “agile”?

I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.

Test strategy and how to communicate it

I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.

Do you possess the necessary characteristics to adopt an Agile testing mindset?

To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.

How To Refresh Page Using Selenium C# [Complete Tutorial]

When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful