Best Python code snippet using tempest_python
test_authorization.py
Source:test_authorization.py
...178 params,179 metadata=(('token', self.owner_token),)180 )181 self.project_groups.append(self.project_group)182 def _test_create_project(self, project_group_id=None):183 if project_group_id is None:184 self._test_create_project_group()185 params = {186 'name': utils.random_string(),187 'domain_id': self.domain.domain_id188 }189 if project_group_id is None:190 params['project_group_id'] = self.project_group.project_group_id191 else:192 params['project_group_id'] = project_group_id193 self.project = self.identity_v1.Project.create(194 params,195 metadata=(('token', self.owner_token),)196 )197 self.projects.append(self.project)198 def _test_create_domain_role_binding(self, permissions=None):199 if permissions is None:200 permissions = ['*']201 self._test_create_policy(permissions)202 self._test_create_role([{203 'policy_type': 'CUSTOM',204 'policy_id': self.policy.policy_id}], 'DOMAIN')205 params = {206 'resource_type': 'identity.User',207 'resource_id': self.user.user_id,208 'domain_id': self.domain.domain_id,209 'role_id': self.role.role_id210 }211 self.role_binding = self.identity_v1.RoleBinding.create(212 params,213 metadata=(('token', self.owner_token),)214 )215 self.role_bindings.append(self.role_binding)216 self._print_data(self.user, '_test_create_domain_role_binding')217 def _test_create_system_role_binding(self, permissions=None):218 if permissions is None:219 permissions = ['*']220 self._test_create_policy(permissions)221 self._test_create_role([{222 'policy_type': 'CUSTOM',223 'policy_id': self.policy.policy_id}], 'SYSTEM')224 params = {225 'resource_type': 'identity.User',226 'resource_id': self.user.user_id,227 'domain_id': self.domain.domain_id,228 'role_id': self.role.role_id229 }230 self.role_binding = self.identity_v1.RoleBinding.create(231 params,232 metadata=(('token', self.owner_token),)233 )234 self.role_bindings.append(self.role_binding)235 self._print_data(self.user, '_test_create_system_role_binding')236 def _test_create_project_role_binding(self, project_id=None, project_group_id=None, permissions=None):237 if permissions is None:238 permissions = ['*']239 self._test_create_policy(permissions)240 self._test_create_role(241 [{242 'policy_type': 'CUSTOM',243 'policy_id': self.policy.policy_id244 }], 'PROJECT'245 )246 params = {247 'resource_type': 'identity.User',248 'resource_id': self.user.user_id,249 'domain_id': self.domain.domain_id,250 'role_id': self.role.role_id,251 'project_id': project_id,252 'project_group_id': project_group_id253 }254 self.role_binding = self.identity_v1.RoleBinding.create(255 params,256 metadata=(('token', self.owner_token),)257 )258 self.role_bindings.append(self.role_binding)259 self._print_data(self.user, '_test_create_project_role_binding')260 def _test_issue_user_token(self):261 token_params = {262 'user_type': 'USER',263 'user_id': self.user.user_id,264 'credentials': {265 'password': self.user_password266 },267 'domain_id': self.domain.domain_id268 }269 response = self.identity_v1.Token.issue(token_params)270 self.user_token = response.access_token271 def test_authorization_verify_no_roles(self):272 self._test_create_user()273 self._test_issue_user_token()274 params = {275 'service': 'identity',276 'resource': 'User',277 'verb': 'list',278 'scope': 'DOMAIN'279 }280 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):281 self.identity_v1.Authorization.verify(282 params,283 metadata=(('token', self.user_token),))284 def test_authorization_verify_no_roles_access_default_permissions_my_id(self):285 self._test_create_user()286 self._test_issue_user_token()287 params = {288 'service': 'identity',289 'resource': 'User',290 'verb': 'get',291 'scope': 'DOMAIN',292 'user_id': self.user.user_id293 }294 response = self.identity_v1.Authorization.verify(295 params,296 metadata=(('token', self.user_token),))297 self._print_data(response, 'test_authorization_verify_no_roles_access_default_permissions')298 self.assertEqual('USER', response.role_type)299 def test_authorization_verify_no_roles_access_default_permissions_other_id(self):300 self._test_create_user()301 self._test_issue_user_token()302 params = {303 'service': 'identity',304 'resource': 'User',305 'verb': 'get',306 'scope': 'DOMAIN',307 'user_id': utils.random_string() + '@mz.co.kr'308 }309 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):310 self.identity_v1.Authorization.verify(311 params,312 metadata=(('token', self.user_token),))313 def test_authorization_verify_domain_role_no_permissions(self):314 self._test_create_user()315 self._test_create_domain_role_binding(['identity.Domain.*'])316 self._test_issue_user_token()317 params = {318 'service': 'identity',319 'resource': 'User',320 'verb': 'list',321 'scope': 'DOMAIN'322 }323 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):324 self.identity_v1.Authorization.verify(325 params,326 metadata=(('token', self.user_token),))327 def test_authorization_verify_domain_role_with_no_domain_id(self):328 self._test_create_user()329 self._test_create_domain_role_binding()330 self._test_issue_user_token()331 params = {332 'service': 'identity',333 'resource': 'User',334 'verb': 'list',335 'scope': 'DOMAIN'336 }337 response = self.identity_v1.Authorization.verify(338 params,339 metadata=(('token', self.user_token),))340 self._print_data(response, 'test_authorization_verify_domain_role_with_no_domain_id')341 self.assertEqual('DOMAIN', response.role_type)342 def test_authorization_verify_domain_role_with_same_domain_id(self):343 self._test_create_user()344 self._test_create_domain_role_binding()345 self._test_issue_user_token()346 params = {347 'service': 'identity',348 'resource': 'User',349 'verb': 'list',350 'scope': 'DOMAIN',351 'domain_id': self.domain.domain_id352 }353 response = self.identity_v1.Authorization.verify(354 params,355 metadata=(('token', self.user_token),))356 self._print_data(response, 'test_authorization_verify_domain_role_with_same_domain_id')357 self.assertEqual('DOMAIN', response.role_type)358 def test_authorization_verify_domain_role_with_other_domain_id(self):359 self._test_create_user()360 self._test_create_domain_role_binding()361 self._test_issue_user_token()362 params = {363 'service': 'identity',364 'resource': 'User',365 'verb': 'list',366 'scope': 'DOMAIN',367 'domain_id': utils.generate_id('domain')368 }369 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):370 self.identity_v1.Authorization.verify(371 params,372 metadata=(('token', self.user_token),))373 def test_authorization_verify_system_role_no_permissions(self):374 self._test_create_user()375 self._test_create_domain_role_binding(['identity.Domain.get_public_key'])376 self._test_issue_user_token()377 params = {378 'service': 'identity',379 'resource': 'User',380 'verb': 'list',381 'scope': 'DOMAIN'382 }383 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):384 self.identity_v1.Authorization.verify(385 params,386 metadata=(('token', self.user_token),))387 def test_authorization_verify_domain_role_access_system_api(self):388 self._test_create_user()389 self._test_create_domain_role_binding()390 self._test_issue_user_token()391 params = {392 'service': 'identity',393 'resource': 'User',394 'verb': 'list',395 'scope': 'SYSTEM',396 'domain_id': utils.generate_id('domain')397 }398 # with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):399 # self.identity_v1.Authorization.verify(400 # params,401 # metadata=(('token', self.user_token),))402 def test_authorization_verify_domain_role_access_project_api_not_in_project(self):403 self._test_create_user()404 self._test_create_domain_role_binding()405 self._test_issue_user_token()406 params = {407 'service': 'identity',408 'resource': 'User',409 'verb': 'list',410 'scope': 'PROJECT',411 'project_id': utils.generate_id('project')412 }413 response = self.identity_v1.Authorization.verify(414 params,415 metadata=(('token', self.user_token),))416 self._print_data(response, 'test_authorization_verify_domain_role_access_project_api_not_in_project')417 self.assertEqual('DOMAIN', response.role_type)418 def test_authorization_verify_domain_role_access_project_api_in_project_has_permissions(self):419 self._test_create_user()420 self._test_create_domain_role_binding()421 self._test_create_project()422 self._test_create_project_role_binding(project_id=self.project.project_id,423 permissions=['identity.User.*'])424 self._test_issue_user_token()425 params = {426 'service': 'identity',427 'resource': 'User',428 'verb': 'list',429 'scope': 'PROJECT',430 'project_id': self.project.project_id431 }432 response = self.identity_v1.Authorization.verify(433 params,434 metadata=(('token', self.user_token),))435 self._print_data(response, 'test_authorization_verify_domain_role_access_project_api_in_project_has_permissions')436 self.assertEqual('DOMAIN', response.role_type)437 def test_authorization_verify_domain_role_access_project_api_in_project_group_has_permissions(self):438 self._test_create_user()439 self._test_create_domain_role_binding()440 self._test_create_project()441 self._test_create_project_role_binding(project_group_id=self.project_group.project_group_id,442 permissions=['identity.User.*'])443 self._test_issue_user_token()444 params = {445 'service': 'identity',446 'resource': 'User',447 'verb': 'list',448 'scope': 'PROJECT',449 'project_id': self.project.project_id450 }451 response = self.identity_v1.Authorization.verify(452 params,453 metadata=(('token', self.user_token),))454 self._print_data(response, 'test_authorization_verify_domain_role_access_project_api_in_project_group_has_permissions')455 self.assertEqual('DOMAIN', response.role_type)456 def test_authorization_verify_domain_role_access_project_api_override_no_permissions(self):457 self._test_create_user()458 self._test_create_domain_role_binding()459 self._test_create_project()460 self._test_create_project_role_binding(project_group_id=self.project_group.project_group_id,461 permissions=['identity.User.*'])462 self._test_create_project_role_binding(project_id=self.project.project_id,463 permissions=['identity.Domain.*'])464 self._test_issue_user_token()465 params = {466 'service': 'identity',467 'resource': 'User',468 'verb': 'list',469 'scope': 'PROJECT',470 'project_id': self.project.project_id471 }472 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):473 self.identity_v1.Authorization.verify(474 params,475 metadata=(('token', self.user_token),))476 def test_authorization_verify_domain_role_access_project_api_in_project_no_permissions(self):477 self._test_create_user()478 self._test_create_domain_role_binding()479 self._test_create_project()480 self._test_create_project_role_binding(project_id=self.project.project_id,481 permissions=['identity.Domain.*'])482 self._test_issue_user_token()483 params = {484 'service': 'identity',485 'resource': 'User',486 'verb': 'list',487 'scope': 'PROJECT',488 'project_id': self.project.project_id489 }490 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):491 self.identity_v1.Authorization.verify(492 params,493 metadata=(('token', self.user_token),))494 def test_authorization_verify_system_role_with_no_domain_id(self):495 self._test_create_user()496 self._test_create_system_role_binding()497 self._test_issue_user_token()498 params = {499 'service': 'identity',500 'resource': 'User',501 'verb': 'list',502 'scope': 'SYSTEM'503 }504 response = self.identity_v1.Authorization.verify(505 params,506 metadata=(('token', self.user_token),))507 self._print_data(response, 'test_authorization_verify_system_role_with_no_domain_id')508 self.assertEqual('SYSTEM', response.role_type)509 def test_authorization_verify_system_role_with_other_domain_id(self):510 self._test_create_user()511 self._test_create_system_role_binding()512 self._test_issue_user_token()513 params = {514 'service': 'identity',515 'resource': 'User',516 'verb': 'list',517 'scope': 'SYSTEM',518 'domain_id': utils.generate_id('domain')519 }520 response = self.identity_v1.Authorization.verify(521 params,522 metadata=(('token', self.user_token),))523 self._print_data(response, 'test_authorization_verify_system_role_with_other_domain_id')524 self.assertEqual('SYSTEM', response.role_type)525 def test_authorization_verify_system_role_access_domain_api(self):526 self._test_create_user()527 self._test_create_system_role_binding()528 self._test_issue_user_token()529 params = {530 'service': 'identity',531 'resource': 'User',532 'verb': 'list',533 'scope': 'DOMAIN',534 'domain_id': utils.generate_id('domain')535 }536 response = self.identity_v1.Authorization.verify(537 params,538 metadata=(('token', self.user_token),))539 self._print_data(response, 'test_authorization_verify_system_role_access_domain_api')540 self.assertEqual('SYSTEM', response.role_type)541 def test_authorization_verify_system_role_access_project_api(self):542 self._test_create_user()543 self._test_create_system_role_binding()544 self._test_issue_user_token()545 params = {546 'service': 'identity',547 'resource': 'User',548 'verb': 'list',549 'scope': 'PROJECT',550 'domain_id': utils.generate_id('domain')551 }552 response = self.identity_v1.Authorization.verify(553 params,554 metadata=(('token', self.user_token),))555 self._print_data(response, 'test_authorization_verify_system_role_access_project_api')556 self.assertEqual('SYSTEM', response.role_type)557 def test_authorization_verify_project_role_no_permissions(self):558 self._test_create_user()559 self._test_create_project()560 self._test_create_project_role_binding(project_id=self.project.project_id, permissions=['identity.Domain.*'])561 self._test_issue_user_token()562 params = {563 'service': 'identity',564 'resource': 'User',565 'verb': 'list',566 'scope': 'DOMAIN'567 }568 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):569 self.identity_v1.Authorization.verify(570 params,571 metadata=(('token', self.user_token),))572 def test_authorization_verify_project_role_with_no_project_id(self):573 self._test_create_user()574 self._test_create_project()575 self._test_create_project_role_binding(project_id=self.project.project_id)576 self._test_issue_user_token()577 params = {578 'service': 'identity',579 'resource': 'User',580 'verb': 'list',581 'scope': 'PROJECT'582 }583 response = self.identity_v1.Authorization.verify(584 params,585 metadata=(('token', self.user_token),))586 self._print_data(response, 'test_authorization_verify_project_role_with_no_project_id')587 self.assertEqual('PROJECT', response.role_type)588 def test_authorization_verify_project_role_with_no_project_id_require_project_id(self):589 self._test_create_user()590 self._test_create_project()591 self._test_create_project_role_binding(project_id=self.project.project_id)592 self._test_issue_user_token()593 params = {594 'service': 'identity',595 'resource': 'User',596 'verb': 'list',597 'scope': 'PROJECT',598 'require_project_id': True599 }600 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):601 self.identity_v1.Authorization.verify(602 params,603 metadata=(('token', self.user_token),))604 def test_authorization_verify_project_role_with_no_project_group_id_require_project_group_id(self):605 self._test_create_user()606 self._test_create_project()607 self._test_create_project_role_binding(project_id=self.project.project_id)608 self._test_issue_user_token()609 params = {610 'service': 'identity',611 'resource': 'User',612 'verb': 'list',613 'scope': 'PROJECT',614 'require_project_group_id': True615 }616 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):617 self.identity_v1.Authorization.verify(618 params,619 metadata=(('token', self.user_token),))620 def test_authorization_verify_project_role_with_no_domain_id(self):621 self._test_create_user()622 self._test_create_project()623 self._test_create_project_role_binding(project_id=self.project.project_id)624 self._test_issue_user_token()625 params = {626 'service': 'identity',627 'resource': 'User',628 'verb': 'list',629 'scope': 'PROJECT',630 'project_id': self.project.project_id631 }632 response = self.identity_v1.Authorization.verify(633 params,634 metadata=(('token', self.user_token),))635 self._print_data(response, 'test_authorization_verify_project_role_with_no_domain_id')636 self.assertEqual('PROJECT', response.role_type)637 def test_authorization_verify_project_role_with_other_domain_id(self):638 self._test_create_user()639 self._test_create_project()640 self._test_create_project_role_binding(project_id=self.project.project_id)641 self._test_issue_user_token()642 params = {643 'service': 'identity',644 'resource': 'User',645 'verb': 'list',646 'scope': 'PROJECT',647 'domain_id': utils.generate_id('domain'),648 'project_id': self.project.project_id649 }650 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):651 self.identity_v1.Authorization.verify(652 params,653 metadata=(('token', self.user_token),))654 def test_authorization_verify_project_role_with_other_project_id(self):655 self._test_create_user()656 self._test_create_project()657 self._test_create_project_role_binding(project_id=self.project.project_id)658 self._test_issue_user_token()659 params = {660 'service': 'identity',661 'resource': 'User',662 'verb': 'list',663 'scope': 'PROJECT',664 'domain_id': self.domain.domain_id,665 'project_id': utils.generate_id('project')666 }667 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):668 self.identity_v1.Authorization.verify(669 params,670 metadata=(('token', self.user_token),))671 def test_authorization_verify_project_role_with_same_project_id(self):672 self._test_create_user()673 self._test_create_project()674 self._test_create_project_role_binding(project_id=self.project.project_id)675 self._test_issue_user_token()676 params = {677 'service': 'identity',678 'resource': 'User',679 'verb': 'list',680 'scope': 'PROJECT',681 'project_id': self.project.project_id682 }683 response = self.identity_v1.Authorization.verify(684 params,685 metadata=(('token', self.user_token),))686 self._print_data(response, 'test_authorization_verify_project_role_with_same_project_id')687 self.assertEqual('PROJECT', response.role_type)688 def test_authorization_verify_project_role_with_same_project_group_id(self):689 self._test_create_user()690 self._test_create_project()691 self._test_create_project_role_binding(project_group_id=self.project_group.project_group_id)692 self._test_issue_user_token()693 params = {694 'service': 'identity',695 'resource': 'User',696 'verb': 'list',697 'scope': 'PROJECT',698 'project_group_id': self.project_group.project_group_id699 }700 response = self.identity_v1.Authorization.verify(701 params,702 metadata=(('token', self.user_token),))703 self._print_data(response, 'test_authorization_verify_project_role_with_same_project_group_id')704 self.assertEqual('PROJECT', response.role_type)705 def test_authorization_verify_project_role_with_child_project_group_id(self):706 self._test_create_user()707 self._test_create_project_group()708 self._test_create_project_group(self.project_group.project_group_id)709 self._test_create_project_group(self.project_group.project_group_id)710 self._test_create_project(self.project_group.project_group_id)711 self._test_create_project(self.project_group.project_group_id)712 self._test_create_project(self.project_group.project_group_id)713 self._test_create_project_role_binding(project_group_id=self.project_groups[0].project_group_id,714 permissions=['identity.User.*'])715 self._test_issue_user_token()716 params = {717 'service': 'identity',718 'resource': 'User',719 'verb': 'list',720 'scope': 'PROJECT',721 'project_group_id': self.project_group.project_group_id722 }723 response = self.identity_v1.Authorization.verify(724 params,725 metadata=(('token', self.user_token),))726 self._print_data(response, 'test_authorization_verify_project_role_with_no_domain_id_and_project_id')727 self.assertEqual('PROJECT', response.role_type)728 def test_authorization_verify_project_role_with_child_project_id(self):729 self._test_create_user()730 self._test_create_project_group()731 self._test_create_project_group(self.project_group.project_group_id)732 self._test_create_project_group(self.project_group.project_group_id)733 self._test_create_project(self.project_group.project_group_id)734 self._test_create_project(self.project_group.project_group_id)735 self._test_create_project(self.project_group.project_group_id)736 self._test_create_project_role_binding(project_group_id=self.project_groups[0].project_group_id,737 permissions=['identity.User.*'])738 self._test_issue_user_token()739 params = {740 'service': 'identity',741 'resource': 'User',742 'verb': 'list',743 'scope': 'PROJECT',744 'project_id': self.project.project_id745 }746 response = self.identity_v1.Authorization.verify(747 params,748 metadata=(('token', self.user_token),))749 self._print_data(response, 'test_authorization_verify_project_role_with_no_domain_id_and_project_id')750 self.assertEqual('PROJECT', response.role_type)751 def test_authorization_verify_project_role_with_child_override_no_permissions_project_group(self):752 self._test_create_user()753 self._test_create_project_group()754 self._test_create_project_group(self.project_group.project_group_id)755 self._test_create_project_group(self.project_group.project_group_id)756 self._test_create_project(self.project_group.project_group_id)757 self._test_create_project(self.project_group.project_group_id)758 self._test_create_project(self.project_group.project_group_id)759 self._test_create_project_role_binding(project_group_id=self.project_groups[0].project_group_id,760 permissions=['identity.User.*'])761 self._test_create_project_role_binding(project_group_id=self.project_group.project_group_id,762 permissions=['identity.Domain.*'])763 self._test_issue_user_token()764 params = {765 'service': 'identity',766 'resource': 'User',767 'verb': 'list',768 'scope': 'PROJECT',769 'project_id': self.project.project_id770 }771 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):772 self.identity_v1.Authorization.verify(773 params,774 metadata=(('token', self.user_token),))775 def test_authorization_verify_project_role_with_child_override_no_permissions_project(self):776 self._test_create_user()777 self._test_create_project_group()778 self._test_create_project_group(self.project_group.project_group_id)779 self._test_create_project_group(self.project_group.project_group_id)780 self._test_create_project(self.project_group.project_group_id)781 self._test_create_project(self.project_group.project_group_id)782 self._test_create_project(self.project_group.project_group_id)783 self._test_create_project_role_binding(project_group_id=self.project_groups[0].project_group_id,784 permissions=['identity.User.*'])785 self._test_create_project_role_binding(project_id=self.project.project_id,786 permissions=['identity.Domain.*'])787 self._test_issue_user_token()788 params = {789 'service': 'identity',790 'resource': 'User',791 'verb': 'list',792 'scope': 'PROJECT',793 'project_id': self.project.project_id794 }795 with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):796 self.identity_v1.Authorization.verify(797 params,798 metadata=(('token', self.user_token),))799 def test_authorization_verify_project_role_access_system_api(self):800 self._test_create_user()801 self._test_create_project()802 self._test_create_project_role_binding(project_id=self.project.project_id)803 self._test_issue_user_token()804 params = {805 'service': 'identity',806 'resource': 'User',807 'verb': 'list',808 'scope': 'SYSTEM',809 'domain_id': utils.generate_id('domain')810 }811 # with self.assertRaisesRegex(Exception, 'ERROR_PERMISSION_DENIED'):812 # self.identity_v1.Authorization.verify(813 # params,814 # metadata=(('token', self.user_token),))815 def test_authorization_verify_project_role_access_domain_api(self):816 self._test_create_user()817 self._test_create_project()818 self._test_create_project_role_binding(project_id=self.project.project_id)819 self._test_issue_user_token()820 params = {821 'service': 'identity',822 'resource': 'User',823 'verb': 'list',824 'scope': 'DOMAIN',825 'domain_id': self.domain.domain_id826 }827 response = self.identity_v1.Authorization.verify(828 params,829 metadata=(('token', self.user_token),))830 self._print_data(response, 'test_authorization_verify_project_role_access_domain_api')831 self.assertEqual('PROJECT', response.role_type)832 def test_authorization_verify_project_role_list_users(self):833 self._test_create_user()834 self._test_create_project()835 self._test_create_project_role_binding(project_id=self.project.project_id)836 self._test_issue_user_token()837 params = {838 'user_id': self.user.user_id,839 'domain_id': self.domain.domain_id840 }841 response = self.identity_v1.User.list(842 params,843 metadata=(('token', self.user_token),))844 self._print_data(response, 'test_authorization_verify_project_role_get_user')845if __name__ == "__main__":...
test_project_group.py
Source:test_project_group.py
...201 metadata=(('token', self.owner_token),)202 )203 self.users.append(self.user)204 return self.user205 def _test_create_project(self, project_group_id=None):206 if project_group_id is None:207 self.test_create_project_group()208 name = f'project-{utils.random_string()}'209 params = {210 'name': name,211 'tags': {212 utils.random_string(4): utils.random_string(4),213 utils.random_string(4):utils.random_string(4)214 },215 'domain_id': self.domain.domain_id216 }217 if project_group_id is None:218 params['project_group_id'] = self.project_group.project_group_id219 else:220 params['project_group_id'] = project_group_id221 self.project = self.identity_v1.Project.create(222 params,223 metadata=(('token', self.owner_token),)224 )225 self.projects.append(self.project)226 def test_create_project_group(self, parent_project_group_id=None, name=None):227 if name is None:228 name = f'pg-{utils.random_string()}'229 params = {230 'name': name,231 'tags': {232 utils.random_string(4): utils.random_string(4),233 utils.random_string(4):utils.random_string(4)234 },235 'domain_id': self.domain.domain_id236 }237 if parent_project_group_id:238 params['parent_project_group_id'] = parent_project_group_id239 self.project_group = self.identity_v1.ProjectGroup.create(240 params,241 metadata=(('token', self.owner_token),)242 )243 self.project_groups.append(self.project_group)244 self.assertEqual(self.project_group.name, name)245 return self.project_group246 def test_create_parent_project_group(self, parent_project_group_id=None):247 name = f'parent-pg-{utils.random_string()}'248 params = {249 'name': name,250 'domain_id': self.domain.domain_id251 }252 if parent_project_group_id:253 params['parent_project_group_id'] = parent_project_group_id254 self.parent_project_group = self.identity_v1.ProjectGroup.create(255 params,256 metadata=(('token', self.owner_token),)257 )258 self.parent_project_groups.append(self.parent_project_group)259 self.assertEqual(self.parent_project_group.name, name)260 return self.parent_project_group261 def test_create_project_group_with_parent(self):262 self.test_create_parent_project_group()263 self.test_create_project_group(self.parent_project_group.project_group_id)264 self.assertEqual(self.project_group.parent_project_group_info.project_group_id,265 self.parent_project_group.project_group_id)266 def test_update_project_group_name(self):267 self.test_create_project_group()268 name = 'update-project-group'269 params = {270 'name': name,271 'project_group_id': self.project_group.project_group_id,272 'domain_id': self.domain.domain_id273 }274 self.project_group = self.identity_v1.ProjectGroup.update(275 params,276 metadata=(('token', self.owner_token),)277 )278 self.assertEqual(self.project_group.name, name)279 def test_update_project_group_parent(self, parent_project_group=None):280 self.test_create_project_group_with_parent()281 if parent_project_group is None:282 parent_project_group = self.test_create_parent_project_group()283 params = {284 'project_group_id': self.project_group.project_group_id,285 'parent_project_group_id': parent_project_group.project_group_id,286 'domain_id': self.domain.domain_id287 }288 self.project_group = self.identity_v1.ProjectGroup.update(289 params,290 metadata=(('token', self.owner_token),)291 )292 self.assertEqual(self.project_group.parent_project_group_info.project_group_id,293 parent_project_group.project_group_id)294 def test_update_project_group_self(self):295 self.test_create_project_group()296 param = {297 'project_group_id': self.project_group.project_group_id,298 'parent_project_group_id': self.project_group.project_group_id,299 'domain_id': self.domain.domain_id300 }301 with self.assertRaises(Exception):302 self.identity_v1.ProjectGroup.update(303 param,304 metadata=(('token', self.owner_token),)305 )306 def test_delete_project_group_exist_child(self):307 self.test_create_project_group_with_parent()308 with self.assertRaises(Exception) as e:309 self.identity_v1.ProjectGroup.delete(310 {311 'project_group_id': self.parent_project_group.project_group_id,312 'domain_id': self.domain.domain_id313 },314 metadata=(('token', self.owner_token),)315 )316 self.assertIn("ERROR_EXIST_RESOURCE", str(e.exception))317 def test_get_project_group(self):318 self.test_create_project_group()319 project_group = self.identity_v1.ProjectGroup.get(320 {321 'project_group_id': self.project_group.project_group_id,322 'domain_id': self.domain.domain_id323 },324 metadata=(('token', self.owner_token),)325 )326 self.assertEqual(self.project_group.project_group_id,327 project_group.project_group_id)328 def test_get_project_group_not_exist(self):329 self.test_create_project_group()330 with self.assertRaises(Exception):331 self.identity_v1.ProjectGroup.get(332 {333 'project_group_id': 'jihyungsong',334 'domain_id': self.domain.domain_id335 },336 metadata=(('token', self.owner_token),)337 )338 def test_list_project_groups_with_parent(self):339 parent_num = 3340 for x in range(parent_num):341 self.test_create_parent_project_group()342 num = 10343 for x in range(num):344 if len(self.parent_project_groups) > x:345 self.test_create_project_group(self.parent_project_groups[x].project_group_id)346 else:347 self.test_create_project_group()348 query = {349 # 'count_only': True,350 # 'minimal': True,351 # 'page': {'limit': 2},352 'filter': [353 {354 'k': 'parent_project_group_id',355 'v': 'pg-',356 'o': 'contain'357 }358 ]359 }360 project_groups = self.identity_v1.ProjectGroup.list(361 {'query': query, 'domain_id': self.domain.domain_id},362 metadata=(('token', self.owner_token),)363 )364 self.assertEqual(parent_num, project_groups.total_count)365 def test_list_root_project_groups_in_query(self):366 parent_num = 3367 for x in range(parent_num):368 self.test_create_parent_project_group()369 num = 10370 for x in range(num):371 if len(self.parent_project_groups) > x:372 self.test_create_project_group(self.parent_project_groups[x].project_group_id)373 else:374 self.test_create_project_group()375 query = {376 'filter': [377 {378 'k': 'parent_project_group',379 'v': None,380 'o': 'eq'381 }382 ]383 }384 project_groups = self.identity_v1.ProjectGroup.list(385 {'query': query, 'domain_id': self.domain.domain_id},386 metadata=(('token', self.owner_token),)387 )388 self.assertEqual(num, project_groups.total_count)389 def test_list_project_groups_1(self):390 num = 10391 for x in range(num):392 self.test_create_project_group(name='blah-blah-blah-blah')393 query = {394 'filter': [395 {'k': 'name', 'v': 'blah-blah-blah-blah', 'o': 'contain'}396 ]397 }398 project_group = self.identity_v1.ProjectGroup.list(399 {'query': query, 'domain_id': self.domain.domain_id},400 metadata=(('token', self.owner_token),)401 )402 self.assertEqual(num, project_group.total_count)403 def test_list_project_groups_2(self):404 num = 2405 for x in range(num):406 self.test_create_project_group()407 query = {408 'filter': [409 {'k': 'parent_project_group_id', 'v': None, 'o': 'eq'}410 ]411 }412 project_group = self.identity_v1.ProjectGroup.list(413 {'query': query, 'domain_id': self.domain.domain_id},414 metadata=(('token', self.owner_token),)415 )416 self.assertEqual(num, project_group.total_count)417 def test_add_project_group_member(self, project_group=None, user=None):418 if user is None:419 user = self._test_create_user()420 self._test_create_role('PROJECT')421 if project_group is None:422 project_group = self.test_create_project_group()423 params = {424 'project_group_id': project_group.project_group_id,425 'user_id': user.user_id,426 'role_id': self.role.role_id,427 'domain_id': self.domain.domain_id428 }429 project_group_member = self.identity_v1.ProjectGroup.add_member(430 params,431 metadata=(('token', self.owner_token),)432 )433 self._print_data(project_group_member, 'test_add_project_group_member')434 self.assertEqual(project_group_member.resource_type, 'identity.User')435 self.assertEqual(project_group_member.resource_id, user.user_id)436 self.assertEqual(project_group_member.role_info.role_id, self.role.role_id)437 def test_add_project_group_member_exist_member(self):438 self.test_add_project_group_member()439 params = {440 'project_group_id': self.project_group.project_group_id,441 'user_id': self.user.user_id,442 'role_id': self.role.role_id,443 'domain_id': self.domain.domain_id444 }445 with self.assertRaises(Exception) as cm:446 self.identity_v1.ProjectGroup.add_member(447 params,448 metadata=(('token', self.owner_token),)449 )450 self.assertIn("ERROR_DUPLICATE_RESOURCE_IN_PROJECT", str(cm.exception))451 def test_modify_project_group_member(self):452 self.test_add_project_group_member()453 labels = ['developer', 'operator']454 params = {455 'project_group_id': self.project_group.project_group_id,456 'user_id': self.user.user_id,457 'labels': labels,458 'domain_id': self.domain.domain_id459 }460 project_member = self.identity_v1.ProjectGroup.modify_member(461 params,462 metadata=(('token', self.owner_token),)463 )464 self._print_data(project_member, 'test_modify_project_group_member')465 self.assertEqual(sorted(project_member.labels), sorted(labels))466 def test_modify_project_group_member_not_exist_member(self):467 self.test_add_project_group_member()468 params = {469 'project_id': self.project_group.project_group_id,470 'user_id': 'blah-blah-blah-blah',471 'domain_id': self.domain.domain_id472 }473 with self.assertRaises(Exception):474 self.identity_v1.ProjectGroup.modify_member(475 params,476 metadata=(('token', self.owner_token),)477 )478 def test_remove_project_group_member(self):479 self.test_add_project_group_member()480 self.identity_v1.ProjectGroup.remove_member(481 {482 'project_group_id': self.project_group.project_group_id,483 'user_id': self.user.user_id,484 'domain_id': self.domain.domain_id485 },486 metadata=(('token', self.owner_token),)487 )488 project_members = self.identity_v1.ProjectGroup.list_members(489 {490 'project_group_id': self.project_group.project_group_id,491 'domain_id': self.domain.domain_id492 },493 metadata=(('token', self.owner_token),)494 )495 self.assertEqual(0, project_members.total_count)496 def test_remove_project_group_member_not_exist_member(self):497 self.test_add_project_group_member()498 params = {499 'project_group_id': self.project_group.project_group_id,500 'user_id': 'blah-blah'501 }502 with self.assertRaises(Exception):503 self.identity_v1.ProjectGroup.remove_member(504 params,505 metadata=(('token', self.owner_token),)506 )507 def test_list_project_group_members_2(self):508 self.test_create_project_group()509 self._test_create_user()510 self._test_create_user()511 self._test_create_user()512 for user in self.users:513 self.test_add_project_group_member(self.project_group, user)514 response = self.identity_v1.ProjectGroup.list_members(515 {516 'project_group_id': self.project_group.project_group_id,517 'domain_id': self.domain.domain_id518 },519 metadata=(('token', self.owner_token),)520 )521 self.assertEqual(len(self.users), response.total_count)522 def test_list_project_group_members_with_user_id(self):523 self.test_create_project_group()524 self._test_create_user()525 self._test_create_user()526 self._test_create_user()527 for user in self.users:528 self.test_add_project_group_member(self.project_group, user)529 params = {530 'project_group_id': self.project_group.project_group_id,531 'user_id': self.user.user_id,532 'domain_id': self.domain.domain_id533 }534 response = self.identity_v1.ProjectGroup.list_members(535 params,536 metadata=(('token', self.owner_token),)537 )538 self.assertEqual(1, response.total_count)539 def test_list_project_group_members_not_exist_user(self):540 self.test_create_project_group()541 self._test_create_user()542 self._test_create_user()543 self._test_create_user()544 for user in self.users:545 self.test_add_project_group_member(self.project_group, user)546 params = {547 'project_group_id': self.project_group.project_group_id,548 'user_id': 'TEST',549 'domain_id': self.domain.domain_id550 }551 response = self.identity_v1.ProjectGroup.list_members(552 params,553 metadata=(('token', self.owner_token),)554 )555 self.assertEqual(0, response.total_count)556 def test_list_projects_in_project(self):557 self.test_create_parent_project_group()558 self.test_create_project_group(self.parent_project_group.project_group_id)559 self.test_create_project_group(self.parent_project_group.project_group_id)560 self._test_create_project(self.project_groups[0].project_group_id)561 self._test_create_project(self.project_groups[0].project_group_id)562 self._test_create_project(self.project_groups[0].project_group_id)563 self._test_create_project(self.project_groups[1].project_group_id)564 self._test_create_project(self.project_groups[1].project_group_id)565 response = self.identity_v1.ProjectGroup.list_projects(566 {567 'query': {},568 'project_group_id': self.project_groups[0].project_group_id,569 'domain_id': self.domain.domain_id570 },571 metadata=(('token', self.owner_token),)572 )573 self._print_data(response, 'test_list_projects_in_project')574 self.assertEqual(3, response.total_count)575 def test_list_projects_in_project_recursive(self):576 self.test_create_parent_project_group()577 self.test_create_parent_project_group(self.parent_project_group.project_group_id)578 self.test_create_project_group(self.parent_project_groups[0].project_group_id)579 self.test_create_project_group(self.parent_project_groups[1].project_group_id)580 self._test_create_project(self.parent_project_groups[0].project_group_id)581 self._test_create_project(self.parent_project_groups[0].project_group_id)582 self._test_create_project(self.parent_project_groups[1].project_group_id)583 self._test_create_project(self.parent_project_groups[1].project_group_id)584 self._test_create_project(self.parent_project_groups[1].project_group_id)585 self._test_create_project(self.parent_project_groups[1].project_group_id)586 self._test_create_project(self.project_groups[0].project_group_id)587 self._test_create_project(self.project_groups[0].project_group_id)588 self._test_create_project(self.project_groups[0].project_group_id)589 self._test_create_project(self.project_groups[1].project_group_id)590 self._test_create_project(self.project_groups[1].project_group_id)591 response = self.identity_v1.ProjectGroup.list_projects(592 {593 'recursive': True,594 'query': {},595 'project_group_id': self.parent_project_groups[0].project_group_id,596 'domain_id': self.domain.domain_id597 },598 metadata=(('token', self.owner_token),)599 )600 self._print_data(response, 'test_list_projects_in_project_recursive')601 self.assertEqual(11, response.total_count)602 def test_stat_project_group(self):603 self.test_add_project_group_member()604 self.test_add_project_group_member()...
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!!