Best Python code snippet using tempest_python
test_trunk.py
Source:test_trunk.py
...38 self.assertTrue(39 policy.enforce(self.context, 'update_trunk', self.target))40 self.assertTrue(41 policy.enforce(self.context, 'update_trunk', self.alt_target))42 def test_delete_trunk(self):43 self.assertTrue(44 policy.enforce(self.context, 'delete_trunk', self.target))45 self.assertTrue(46 policy.enforce(self.context, 'delete_trunk', self.alt_target))47 def test_get_subports(self):48 self.assertTrue(49 policy.enforce(self.context, 'get_subports', self.target))50 self.assertTrue(51 policy.enforce(self.context, 'get_subports', self.alt_target))52 def test_add_subports(self):53 self.assertTrue(54 policy.enforce(self.context, 'add_subports', self.target))55 self.assertTrue(56 policy.enforce(self.context, 'add_subports', self.alt_target))57 def test_remove_subports(self):58 self.assertTrue(59 policy.enforce(self.context, 'remove_subports', self.target))60 self.assertTrue(61 policy.enforce(self.context, 'remove_subports', self.alt_target))62class SystemMemberTests(SystemAdminTests):63 def setUp(self):64 super(SystemMemberTests, self).setUp()65 self.context = self.system_member_ctx66 def test_create_trunk(self):67 self.assertRaises(68 base_policy.PolicyNotAuthorized,69 policy.enforce,70 self.context, 'create_trunk', self.target)71 self.assertRaises(72 base_policy.PolicyNotAuthorized,73 policy.enforce,74 self.context, 'create_trunk', self.alt_target)75 def test_update_trunk(self):76 self.assertRaises(77 base_policy.PolicyNotAuthorized,78 policy.enforce,79 self.context, 'update_trunk', self.target)80 self.assertRaises(81 base_policy.PolicyNotAuthorized,82 policy.enforce,83 self.context, 'update_trunk', self.alt_target)84 def test_delete_trunk(self):85 self.assertRaises(86 base_policy.PolicyNotAuthorized,87 policy.enforce,88 self.context, 'delete_trunk', self.target)89 self.assertRaises(90 base_policy.PolicyNotAuthorized,91 policy.enforce,92 self.context, 'delete_trunk', self.alt_target)93 def test_add_subports(self):94 self.assertRaises(95 base_policy.PolicyNotAuthorized,96 policy.enforce,97 self.context, 'add_subports', self.target)98 self.assertRaises(99 base_policy.PolicyNotAuthorized,100 policy.enforce,101 self.context, 'add_subports', self.alt_target)102 def test_remove_subports(self):103 self.assertRaises(104 base_policy.PolicyNotAuthorized,105 policy.enforce,106 self.context, 'remove_subports', self.target)107 self.assertRaises(108 base_policy.PolicyNotAuthorized,109 policy.enforce,110 self.context, 'remove_subports', self.alt_target)111class SystemReaderTests(SystemMemberTests):112 def setUp(self):113 super(SystemReaderTests, self).setUp()114 self.context = self.system_reader_ctx115class ProjectAdminTests(TrunkAPITestCase):116 def setUp(self):117 super(ProjectAdminTests, self).setUp()118 self.context = self.project_admin_ctx119 def test_create_trunk(self):120 self.assertTrue(121 policy.enforce(self.context, 'create_trunk', self.target))122 self.assertRaises(123 base_policy.PolicyNotAuthorized,124 policy.enforce,125 self.context, 'create_trunk', self.alt_target)126 def test_get_trunk(self):127 self.assertTrue(128 policy.enforce(self.context, 'get_trunk', self.target))129 self.assertRaises(130 base_policy.PolicyNotAuthorized,131 policy.enforce,132 self.context, 'get_trunk', self.alt_target)133 def test_update_trunk(self):134 self.assertTrue(135 policy.enforce(self.context, 'update_trunk', self.target))136 self.assertRaises(137 base_policy.PolicyNotAuthorized,138 policy.enforce,139 self.context, 'update_trunk', self.alt_target)140 def test_delete_trunk(self):141 self.assertTrue(142 policy.enforce(self.context, 'delete_trunk', self.target))143 self.assertRaises(144 base_policy.PolicyNotAuthorized,145 policy.enforce,146 self.context, 'delete_trunk', self.alt_target)147 def test_get_subports(self):148 self.assertTrue(149 policy.enforce(self.context, 'get_subports', self.target))150 self.assertRaises(151 base_policy.PolicyNotAuthorized,152 policy.enforce,153 self.context, 'get_subports', self.alt_target)154 def test_add_subports(self):155 self.assertTrue(156 policy.enforce(self.context, 'add_subports', self.target))157 self.assertRaises(158 base_policy.PolicyNotAuthorized,159 policy.enforce,160 self.context, 'add_subports', self.alt_target)161 def test_remove_subports(self):162 self.assertTrue(163 policy.enforce(self.context, 'remove_subports', self.target))164 self.assertRaises(165 base_policy.PolicyNotAuthorized,166 policy.enforce,167 self.context, 'remove_subports', self.alt_target)168class ProjectMemberTests(ProjectAdminTests):169 def setUp(self):170 super(ProjectMemberTests, self).setUp()171 self.context = self.project_member_ctx172class ProjectReaderTests(ProjectMemberTests):173 def setUp(self):174 super(ProjectReaderTests, self).setUp()175 self.context = self.project_reader_ctx176 def test_create_trunk(self):177 self.assertRaises(178 base_policy.PolicyNotAuthorized,179 policy.enforce,180 self.context, 'create_trunk', self.target)181 self.assertRaises(182 base_policy.PolicyNotAuthorized,183 policy.enforce,184 self.context, 'create_trunk', self.alt_target)185 def test_update_trunk(self):186 self.assertRaises(187 base_policy.PolicyNotAuthorized,188 policy.enforce,189 self.context, 'update_trunk', self.target)190 self.assertRaises(191 base_policy.PolicyNotAuthorized,192 policy.enforce,193 self.context, 'update_trunk', self.alt_target)194 def test_delete_trunk(self):195 self.assertRaises(196 base_policy.PolicyNotAuthorized,197 policy.enforce,198 self.context, 'delete_trunk', self.target)199 self.assertRaises(200 base_policy.PolicyNotAuthorized,201 policy.enforce,202 self.context, 'delete_trunk', self.alt_target)203 def test_add_subports(self):204 self.assertRaises(205 base_policy.PolicyNotAuthorized,206 policy.enforce,207 self.context, 'add_subports', self.target)208 self.assertRaises(...
trunk.py
Source:trunk.py
...143 return self.post(config.NEUTRON_TRUNKS, payload)144 def update_trunk(self, trunkid, payload):145 logging.info('update trunk: ' + trunkid)146 return self.put(config.NEUTRON_TRUNKS + '/' + trunkid, payload)147 def delete_trunk(self, trunkid):148 logging.info('delete trunk: ' + trunkid)149 return self.delete(config.NEUTRON_TRUNKS + '/' + trunkid)150 @staticmethod151 def perform_tests(servername, username, count=0):152 logging.info('perform trunk tests, server: %s, user: %s' % (servername, username))153 tester = Trunk(servername, username)154 utils.assert_status(tester.get_trunks(), 200)155 trunk_one = tester.create_trunk(change_id(TRUNK_ONE, count))156 utils.assert_status(trunk_one, 201)157 if trunk_one.status_code == 201:158 trunk_one_id = json.loads(trunk_one.text)['trunk']['id']159 utils.assert_status(tester.get_trunk(trunk_one_id), 200)160 utils.assert_status(tester.create_trunk(change_id(TRUNK_DEFAULT, count)), 201)161 utils.assert_status(tester.update_trunk(change_id(TRUNK_UPDATE['trunk'], count)['trunk']['id'],162 change_id(TRUNK_UPDATE['trunk'], count)), 201)163 if count == 0:164 utils.assert_status(tester.create_trunk(TRUNKS_BULK), 201)165 utils.assert_status(tester.delete_trunk(TRUNKS_BULK['trunks'][0]['id']), 204)166 utils.assert_status(tester.get_trunk(TRUNKS_BULK['trunks'][0]['id']), 404)167 trunks = tester.get_trunks()168 for trunk in json.loads(trunks.text)['trunks']:169 utils.assert_status(tester.delete_trunk(trunk['id']), 204)170if __name__ == '__main__':...
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!!