Best Python code snippet using localstack_python
test_core.py
Source:test_core.py
...59 self.assertDictEqual(role, role_ref_dict)60 role_ref = PROVIDERS.role_api.get_unique_role_by_name(role_name)61 self.assertEqual(role['id'], role_ref['id'])62 role['name'] = uuid.uuid4().hex63 updated_role_ref = PROVIDERS.role_api.update_role(role['id'], role)64 role_ref = PROVIDERS.role_api.get_role(role['id'])65 role_ref_dict = {x: role_ref[x] for x in role_ref}66 self.assertDictEqual(role, role_ref_dict)67 self.assertDictEqual(role_ref_dict, updated_role_ref)68 PROVIDERS.role_api.delete_role(role['id'])69 self.assertRaises(exception.RoleNotFound,70 PROVIDERS.role_api.get_role,71 role['id'])72 def test_role_crud_without_description(self):73 role = {74 'id': uuid.uuid4().hex,75 'name': uuid.uuid4().hex,76 'domain_id': None,77 'options': {}78 }79 self.role_api.create_role(role['id'], role)80 role_ref = self.role_api.get_role(role['id'])81 role_ref_dict = {x: role_ref[x] for x in role_ref}82 self.assertIsNone(role_ref_dict['description'])83 role_ref_dict.pop('description')84 self.assertDictEqual(role, role_ref_dict)85 role['name'] = uuid.uuid4().hex86 updated_role_ref = self.role_api.update_role(role['id'], role)87 role_ref = self.role_api.get_role(role['id'])88 role_ref_dict = {x: role_ref[x] for x in role_ref}89 self.assertIsNone(updated_role_ref['description'])90 self.assertDictEqual(role_ref_dict, updated_role_ref)91 self.role_api.delete_role(role['id'])92 self.assertRaises(exception.RoleNotFound,93 self.role_api.get_role,94 role['id'])95 def test_update_role_returns_not_found(self):96 role = unit.new_role_ref()97 self.assertRaises(exception.RoleNotFound,98 PROVIDERS.role_api.update_role,99 role['id'],100 role)101 def test_list_roles(self):102 roles = PROVIDERS.role_api.list_roles()103 self.assertEqual(len(default_fixtures.ROLES), len(roles))104 role_ids = set(role['id'] for role in roles)105 expected_role_ids = set(role['id'] for role in default_fixtures.ROLES)106 self.assertEqual(expected_role_ids, role_ids)107 @unit.skip_if_cache_disabled('role')108 def test_cache_layer_role_crud(self):109 role = unit.new_role_ref()110 role_id = role['id']111 # Create role112 PROVIDERS.role_api.create_role(role_id, role)113 role_ref = PROVIDERS.role_api.get_role(role_id)114 updated_role_ref = copy.deepcopy(role_ref)115 updated_role_ref['name'] = uuid.uuid4().hex116 # Update role, bypassing the role api manager117 PROVIDERS.role_api.driver.update_role(role_id, updated_role_ref)118 # Verify get_role still returns old ref119 self.assertDictEqual(role_ref, PROVIDERS.role_api.get_role(role_id))120 # Invalidate Cache121 PROVIDERS.role_api.get_role.invalidate(PROVIDERS.role_api, role_id)122 # Verify get_role returns the new role_ref123 self.assertDictEqual(updated_role_ref,124 PROVIDERS.role_api.get_role(role_id))125 # Update role back to original via the assignment api manager126 PROVIDERS.role_api.update_role(role_id, role_ref)127 # Verify get_role returns the original role ref128 self.assertDictEqual(role_ref, PROVIDERS.role_api.get_role(role_id))129 # Delete role bypassing the role api manager130 PROVIDERS.role_api.driver.delete_role(role_id)131 # Verify get_role still returns the role_ref132 self.assertDictEqual(role_ref, PROVIDERS.role_api.get_role(role_id))133 # Invalidate cache134 PROVIDERS.role_api.get_role.invalidate(PROVIDERS.role_api, role_id)135 # Verify RoleNotFound is now raised136 self.assertRaises(exception.RoleNotFound,137 PROVIDERS.role_api.get_role,138 role_id)139 # recreate role140 PROVIDERS.role_api.create_role(role_id, role)141 PROVIDERS.role_api.get_role(role_id)142 # delete role via the assignment api manager143 PROVIDERS.role_api.delete_role(role_id)144 # verity RoleNotFound is now raised145 self.assertRaises(exception.RoleNotFound,146 PROVIDERS.role_api.get_role,147 role_id)148 def test_create_role_immutable(self):149 role = unit.new_role_ref()150 role_id = role['id']151 role['options'][ro_opt.IMMUTABLE_OPT.option_name] = True152 role_created = PROVIDERS.role_api.create_role(role_id, role)153 role_via_manager = PROVIDERS.role_api.get_role(role_id)154 self.assertTrue('options' in role_created)155 self.assertTrue('options' in role_via_manager)156 self.assertTrue(157 role_via_manager['options'][ro_opt.IMMUTABLE_OPT.option_name])158 self.assertTrue(159 role_created['options'][ro_opt.IMMUTABLE_OPT.option_name])160 def test_cannot_update_immutable_role(self):161 role = unit.new_role_ref()162 role_id = role['id']163 role['options'][ro_opt.IMMUTABLE_OPT.option_name] = True164 PROVIDERS.role_api.create_role(role_id, role)165 update_role = {'name': uuid.uuid4().hex}166 self.assertRaises(exception.ResourceUpdateForbidden,167 PROVIDERS.role_api.update_role,168 role_id,169 update_role)170 def test_cannot_update_immutable_role_while_unsetting_immutable(self):171 role = unit.new_role_ref()172 role_id = role['id']173 role['options'][ro_opt.IMMUTABLE_OPT.option_name] = True174 PROVIDERS.role_api.create_role(role_id, role)175 update_role = {176 'name': uuid.uuid4().hex,177 'options': {178 ro_opt.IMMUTABLE_OPT.option_name: True179 }180 }181 self.assertRaises(exception.ResourceUpdateForbidden,182 PROVIDERS.role_api.update_role,183 role_id,184 update_role)185 def test_cannot_delete_immutable_role(self):186 role = unit.new_role_ref()187 role_id = role['id']188 role['options'][ro_opt.IMMUTABLE_OPT.option_name] = True189 PROVIDERS.role_api.create_role(role_id, role)190 self.assertRaises(exception.ResourceDeleteForbidden,191 PROVIDERS.role_api.delete_role,192 role_id)193 def test_update_role_set_immutable(self):194 role = unit.new_role_ref()195 role_id = role['id']196 PROVIDERS.role_api.create_role(role_id, role)197 update_role = {198 'options': {199 ro_opt.IMMUTABLE_OPT.option_name: True200 }201 }202 role_via_manager = PROVIDERS.role_api.get_role(role_id)203 self.assertTrue('options' in role_via_manager)204 self.assertFalse(205 ro_opt.IMMUTABLE_OPT.option_name in role_via_manager['options'])206 role_update = PROVIDERS.role_api.update_role(role_id, update_role)207 role_via_manager = PROVIDERS.role_api.get_role(role_id)208 self.assertTrue(209 ro_opt.IMMUTABLE_OPT.option_name in role_update['options'])210 self.assertTrue(211 role_update['options'][ro_opt.IMMUTABLE_OPT.option_name])212 self.assertTrue(213 ro_opt.IMMUTABLE_OPT.option_name in role_via_manager['options'])214 self.assertTrue(215 role_via_manager['options'][ro_opt.IMMUTABLE_OPT.option_name])216 def test_update_role_set_immutable_with_additional_updates(self):217 role = unit.new_role_ref()218 role_id = role['id']219 PROVIDERS.role_api.create_role(role_id, role)220 update_role = {221 'name': uuid.uuid4().hex,222 'options': {223 ro_opt.IMMUTABLE_OPT.option_name: True224 }225 }226 role_via_manager = PROVIDERS.role_api.get_role(role_id)227 self.assertTrue('options' in role_via_manager)228 self.assertFalse(229 ro_opt.IMMUTABLE_OPT.option_name in role_via_manager['options'])230 role_update = PROVIDERS.role_api.update_role(role_id, update_role)231 role_via_manager = PROVIDERS.role_api.get_role(role_id)232 self.assertEqual(role_update['name'], update_role['name'])233 self.assertEqual(role_via_manager['name'], update_role['name'])234 self.assertTrue(235 ro_opt.IMMUTABLE_OPT.option_name in role_update['options'])236 self.assertTrue(237 role_update['options'][ro_opt.IMMUTABLE_OPT.option_name])238 self.assertTrue(239 ro_opt.IMMUTABLE_OPT.option_name in role_via_manager['options'])240 self.assertTrue(241 role_via_manager['options'][ro_opt.IMMUTABLE_OPT.option_name])242 def test_update_role_unset_immutable(self):243 role = unit.new_role_ref()244 role_id = role['id']245 role['options'][ro_opt.IMMUTABLE_OPT.option_name] = True246 PROVIDERS.role_api.create_role(role_id, role)247 role_via_manager = PROVIDERS.role_api.get_role(role_id)248 self.assertTrue('options' in role_via_manager)249 self.assertTrue(250 role_via_manager['options'][ro_opt.IMMUTABLE_OPT.option_name])251 update_role = {252 'options': {253 ro_opt.IMMUTABLE_OPT.option_name: False254 }255 }256 PROVIDERS.role_api.update_role(role_id, update_role)257 role_via_manager = PROVIDERS.role_api.get_role(role_id)258 self.assertTrue('options' in role_via_manager)259 self.assertTrue(260 ro_opt.IMMUTABLE_OPT.option_name in role_via_manager['options'])261 self.assertFalse(262 role_via_manager['options'][ro_opt.IMMUTABLE_OPT.option_name])263 update_role = {264 'options': {265 ro_opt.IMMUTABLE_OPT.option_name: None266 }267 }268 role_updated = PROVIDERS.role_api.update_role(role_id, update_role)269 role_via_manager = PROVIDERS.role_api.get_role(role_id)270 self.assertTrue('options' in role_updated)271 self.assertTrue('options' in role_via_manager)272 self.assertFalse(273 ro_opt.IMMUTABLE_OPT.option_name in role_updated['options'])274 self.assertFalse(...
update_role_test.py
Source:update_role_test.py
...33 type(mock_response).status_code = mock.PropertyMock(return_value=400)34 mock_response.raise_for_status.side_effect = (35 requests.requests.exceptions.HTTPError())36 with self.assertRaises(requests.requests.exceptions.HTTPError):37 update_role.update_role(mock_session, "", False)38 @mock.patch.object(requests, "AuthorizedSession", autospec=True)39 @mock.patch.object(requests.requests, "Response", autospec=True)40 def test_update_role(self, mock_response, mock_session):41 mock_session.request.return_value = mock_response42 type(mock_response).status_code = mock.PropertyMock(return_value=200)43 role_id = "Test"44 is_default = True45 expected = {46 "name":47 "Test",48 "title":49 "Test role",50 "description":51 "The Test role",52 "createTime":53 "2020-11-05T00:00:00Z",54 "isDefault":55 True,56 "permissions": [{57 "name": "Test",58 "title": "Test permission",59 "description": "The Test permission",60 "createTime": "2020-11-05T00:00:00Z",61 },]62 }63 mock_response.json.return_value = expected64 actual = update_role.update_role(mock_session, role_id, is_default)65 self.assertEqual(actual, expected)66if __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!!