Best Python code snippet using tempest_python
test_projects.py
Source:test_projects.py
...21 @decorators.idempotent_id('0ecf465c-0dc4-4532-ab53-91ffeb74d12d')22 def test_project_create_with_description(self):23 # Create project with a description24 project_desc = data_utils.rand_name('desc')25 project = self.setup_test_project(description=project_desc)26 project_id = project['id']27 desc1 = project['description']28 self.assertEqual(desc1, project_desc, 'Description should have '29 'been sent in response for create')30 body = self.projects_client.show_project(project_id)['project']31 desc2 = body['description']32 self.assertEqual(desc2, project_desc, 'Description does not appear'33 'to be set')34 @decorators.idempotent_id('5f50fe07-8166-430b-a882-3b2ee0abe26f')35 def test_project_create_with_domain(self):36 # Create project with a domain37 domain = self.setup_test_domain()38 project_name = data_utils.rand_name('project')39 project = self.setup_test_project(40 name=project_name, domain_id=domain['id'])41 project_id = project['id']42 self.assertEqual(project_name, project['name'])43 self.assertEqual(domain['id'], project['domain_id'])44 body = self.projects_client.show_project(project_id)['project']45 self.assertEqual(project_name, body['name'])46 self.assertEqual(domain['id'], body['domain_id'])47 @decorators.idempotent_id('1854f9c0-70bc-4d11-a08a-1c789d339e3d')48 def test_project_create_with_parent(self):49 # Create root project without providing a parent_id50 domain = self.setup_test_domain()51 domain_id = domain['id']52 root_project_name = data_utils.rand_name('root_project')53 root_project = self.setup_test_project(54 name=root_project_name, domain_id=domain_id)55 root_project_id = root_project['id']56 parent_id = root_project['parent_id']57 self.assertEqual(root_project_name, root_project['name'])58 # If not provided, the parent_id must point to the top level59 # project in the hierarchy, i.e. its domain60 self.assertEqual(domain_id, parent_id)61 # Create a project using root_project_id as parent_id62 project_name = data_utils.rand_name('project')63 project = self.setup_test_project(64 name=project_name, domain_id=domain_id, parent_id=root_project_id)65 parent_id = project['parent_id']66 self.assertEqual(project_name, project['name'])67 self.assertEqual(root_project_id, parent_id)68 @decorators.idempotent_id('a7eb9416-6f9b-4dbb-b71b-7f73aaef59d5')69 def test_create_is_domain_project(self):70 project = self.setup_test_project(domain_id=None, is_domain=True)71 # To delete a domain, we need to disable it first72 self.addCleanup(self.projects_client.update_project, project['id'],73 enabled=False)74 # Check if the is_domain project is correctly returned by both75 # project and domain APIs76 projects_list = self.projects_client.list_projects(77 params={'is_domain': True})['projects']78 self.assertIn(project, projects_list)79 # The domains API return different attributes for the entity, so we80 # compare the entities IDs81 domains_ids = [d['id'] for d in self.domains_client.list_domains()[82 'domains']]83 self.assertIn(project['id'], domains_ids)84 @decorators.idempotent_id('1f66dc76-50cc-4741-a200-af984509e480')85 def test_project_create_enabled(self):86 # Create a project that is enabled87 project = self.setup_test_project(enabled=True)88 project_id = project['id']89 en1 = project['enabled']90 self.assertTrue(en1, 'Enable should be True in response')91 body = self.projects_client.show_project(project_id)['project']92 en2 = body['enabled']93 self.assertTrue(en2, 'Enable should be True in lookup')94 @decorators.idempotent_id('78f96a9c-e0e0-4ee6-a3ba-fbf6dfd03207')95 def test_project_create_not_enabled(self):96 # Create a project that is not enabled97 project = self.setup_test_project(enabled=False)98 en1 = project['enabled']99 self.assertEqual('false', str(en1).lower(),100 'Enable should be False in response')101 body = self.projects_client.show_project(project['id'])['project']102 en2 = body['enabled']103 self.assertEqual('false', str(en2).lower(),104 'Enable should be False in lookup')105 @decorators.idempotent_id('f608f368-048c-496b-ad63-d286c26dab6b')106 def test_project_update_name(self):107 # Update name attribute of a project108 p_name1 = data_utils.rand_name('project')109 project = self.setup_test_project(name=p_name1)110 resp1_name = project['name']111 p_name2 = data_utils.rand_name('project2')112 body = self.projects_client.update_project(project['id'],113 name=p_name2)['project']114 resp2_name = body['name']115 self.assertNotEqual(resp1_name, resp2_name)116 body = self.projects_client.show_project(project['id'])['project']117 resp3_name = body['name']118 self.assertNotEqual(resp1_name, resp3_name)119 self.assertEqual(p_name1, resp1_name)120 self.assertEqual(resp2_name, resp3_name)121 @decorators.idempotent_id('f138b715-255e-4a7d-871d-351e1ef2e153')122 def test_project_update_desc(self):123 # Update description attribute of a project124 p_desc = data_utils.rand_name('desc')125 project = self.setup_test_project(description=p_desc)126 resp1_desc = project['description']127 p_desc2 = data_utils.rand_name('desc2')128 body = self.projects_client.update_project(129 project['id'], description=p_desc2)['project']130 resp2_desc = body['description']131 self.assertNotEqual(resp1_desc, resp2_desc)132 body = self.projects_client.show_project(project['id'])['project']133 resp3_desc = body['description']134 self.assertNotEqual(resp1_desc, resp3_desc)135 self.assertEqual(p_desc, resp1_desc)136 self.assertEqual(resp2_desc, resp3_desc)137 @decorators.idempotent_id('b6b25683-c97f-474d-a595-55d410b68100')138 def test_project_update_enable(self):139 # Update the enabled attribute of a project140 p_en = False141 project = self.setup_test_project(enabled=p_en)142 resp1_en = project['enabled']143 p_en2 = True144 body = self.projects_client.update_project(project['id'],145 enabled=p_en2)['project']146 resp2_en = body['enabled']147 self.assertNotEqual(resp1_en, resp2_en)148 body = self.projects_client.show_project(project['id'])['project']149 resp3_en = body['enabled']150 self.assertNotEqual(resp1_en, resp3_en)151 self.assertEqual('false', str(resp1_en).lower())152 self.assertEqual(resp2_en, resp3_en)153 @decorators.idempotent_id('59398d4a-5dc5-4f86-9a4c-c26cc804d6c6')154 def test_associate_user_to_project(self):155 # Associate a user to a project156 # Create a Project157 project = self.setup_test_project()158 # Create a User159 u_name = data_utils.rand_name('user')160 u_desc = u_name + 'description'161 u_email = u_name + '@testmail.tm'162 u_password = data_utils.rand_password()163 user = self.users_client.create_user(164 name=u_name, description=u_desc, password=u_password,165 email=u_email, project_id=project['id'])['user']166 # Delete the User at the end of this method167 self.addCleanup(self.users_client.delete_user, user['id'])168 # Get User To validate the user details169 new_user_get = self.users_client.show_user(user['id'])['user']170 # Assert response body of GET171 self.assertEqual(u_name, new_user_get['name'])...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!