Best Python code snippet using tempest_python
test_identity_provider.py
Source:test_identity_provider.py
...60 exist61 """62 pass63 @abc.abstractmethod64 def test_identity_delete_identity_provider(self):65 """Test identity:delete_identity_provider policy.66 This test must check67 * whether the persona can delete an identity provider68 * whether the persona can delete an identity provider that does not69 exist70 """71 pass72class SystemAdminTests(IdentityV3RbacIdentityProviderTests,73 base.BaseIdentityTest):74 credentials = ['system_admin']75 def test_identity_create_identity_provider(self):76 idp = self.do_request(77 'create_identity_provider', expected_status=201,78 idp_id=data_utils.rand_name()79 )['identity_provider']80 self.addCleanup(81 self.admin_client.domains_client.delete_domain, idp['domain_id'])82 self.addCleanup(83 self.admin_client.domains_client.update_domain,84 idp['domain_id'], enabled=False)85 self.addCleanup(86 self.admin_idp_client.delete_identity_provider, idp['id'])87 def test_identity_get_identity_provider(self):88 idp = self.admin_idp_client.create_identity_provider(89 idp_id=data_utils.rand_name())['identity_provider']90 self.addCleanup(91 self.admin_client.domains_client.delete_domain, idp['domain_id'])92 self.addCleanup(93 self.admin_client.domains_client.update_domain,94 idp['domain_id'], enabled=False)95 self.addCleanup(96 self.admin_idp_client.delete_identity_provider, idp['id'])97 self.do_request('show_identity_provider', idp_id=idp['id'])98 # user gets a 404 for nonexistent idp99 self.do_request('show_identity_provider',100 expected_status=exceptions.NotFound,101 idp_id=data_utils.rand_uuid_hex())102 def test_identity_list_identity_providers(self):103 idp = self.admin_idp_client.create_identity_provider(104 idp_id=data_utils.rand_name())['identity_provider']105 self.addCleanup(106 self.admin_client.domains_client.delete_domain, idp['domain_id'])107 self.addCleanup(108 self.admin_client.domains_client.update_domain,109 idp['domain_id'], enabled=False)110 self.addCleanup(111 self.admin_idp_client.delete_identity_provider, idp['id'])112 resp = self.do_request('list_identity_providers')113 self.assertIn(idp['id'], [i['id'] for i in resp['identity_providers']])114 def test_identity_update_identity_provider(self):115 idp = self.admin_idp_client.create_identity_provider(116 idp_id=data_utils.rand_name())['identity_provider']117 self.addCleanup(118 self.admin_client.domains_client.delete_domain, idp['domain_id'])119 self.addCleanup(120 self.admin_client.domains_client.update_domain,121 idp['domain_id'], enabled=False)122 self.addCleanup(123 self.admin_idp_client.delete_identity_provider, idp['id'])124 self.do_request('update_identity_provider',125 idp_id=idp['id'],126 description=data_utils.arbitrary_string())127 # user gets a 404 for nonexistent idp128 self.do_request('update_identity_provider',129 expected_status=exceptions.NotFound,130 idp_id=data_utils.rand_uuid_hex(),131 description=data_utils.arbitrary_string())132 def test_identity_delete_identity_provider(self):133 idp = self.admin_idp_client.create_identity_provider(134 idp_id=data_utils.rand_name())['identity_provider']135 self.addCleanup(136 self.admin_client.domains_client.delete_domain, idp['domain_id'])137 self.addCleanup(138 self.admin_client.domains_client.update_domain,139 idp['domain_id'], enabled=False)140 self.do_request('delete_identity_provider', expected_status=204,141 idp_id=idp['id'])142 # user gets a 404 for nonexistent idp143 self.do_request('delete_identity_provider',144 expected_status=exceptions.NotFound,145 idp_id=data_utils.rand_uuid_hex())146class SystemMemberTests(SystemAdminTests, base.BaseIdentityTest):147 credentials = ['system_member', 'system_admin']148 def test_identity_create_identity_provider(self):149 self.do_request('create_identity_provider',150 expected_status=exceptions.Forbidden,151 idp_id=data_utils.rand_name())152 def test_identity_update_identity_provider(self):153 idp = self.admin_idp_client.create_identity_provider(154 idp_id=data_utils.rand_name())['identity_provider']155 self.addCleanup(156 self.admin_client.domains_client.delete_domain, idp['domain_id'])157 self.addCleanup(158 self.admin_client.domains_client.update_domain,159 idp['domain_id'], enabled=False)160 self.addCleanup(161 self.admin_idp_client.delete_identity_provider, idp['id'])162 self.do_request('update_identity_provider',163 expected_status=exceptions.Forbidden,164 idp_id=idp['id'],165 description=data_utils.arbitrary_string())166 # user gets a 403 for nonexistent idp167 self.do_request('update_identity_provider',168 expected_status=exceptions.Forbidden,169 idp_id=data_utils.rand_uuid_hex(),170 description=data_utils.arbitrary_string())171 def test_identity_delete_identity_provider(self):172 idp = self.admin_idp_client.create_identity_provider(173 idp_id=data_utils.rand_name())['identity_provider']174 self.addCleanup(175 self.admin_client.domains_client.delete_domain, idp['domain_id'])176 self.addCleanup(177 self.admin_client.domains_client.update_domain,178 idp['domain_id'], enabled=False)179 self.addCleanup(180 self.admin_idp_client.delete_identity_provider, idp['id'])181 self.do_request('delete_identity_provider',182 expected_status=exceptions.Forbidden,183 idp_id=idp['id'])184 # user gets a 403 for nonexistent idp185 self.do_request('delete_identity_provider',...
federation_idp.py
Source:federation_idp.py
...92 _idp = idp.to_dict()93 _idp['enabled'] = idp['is_enabled']94 _idp['name'] = idp['id']95 return _idp96 def delete_identity_provider(self, idp):97 """98 Delete an existing Identity Provider99 returns: the "Changed" state100 """101 if idp is None:102 return False103 if self.ansible.check_mode:104 return True105 self.conn.identity.delete_identity_provider(idp)106 return True107 def create_identity_provider(self, name):108 """109 Create a new Identity Provider110 returns: the "Changed" state and the new identity provider111 """112 if self.ansible.check_mode:113 return True, None114 description = self.params.get('description')115 enabled = self.params.get('enabled')116 domain_id = self.params.get('domain_id')117 remote_ids = self.params.get('remote_ids')118 if enabled is None:119 enabled = True120 if remote_ids is None:121 remote_ids = []122 attributes = {123 'domain_id': domain_id,124 'enabled': enabled,125 'remote_ids': remote_ids,126 }127 if description is not None:128 attributes['description'] = description129 idp = self.conn.identity.create_identity_provider(id=name, **attributes)130 return (True, idp)131 def update_identity_provider(self, idp):132 """133 Update an existing Identity Provider134 returns: the "Changed" state and the new identity provider135 """136 description = self.params.get('description')137 enabled = self.params.get('enabled')138 domain_id = self.params.get('domain_id')139 remote_ids = self.params.get('remote_ids')140 attributes = {}141 if (description is not None) and (description != idp.description):142 attributes['description'] = description143 if (enabled is not None) and (enabled != idp.is_enabled):144 attributes['enabled'] = enabled145 if (domain_id is not None) and (domain_id != idp.domain_id):146 attributes['domain_id'] = domain_id147 if (remote_ids is not None) and (remote_ids != idp.remote_ids):148 attributes['remote_ids'] = remote_ids149 if not attributes:150 return False, idp151 if self.ansible.check_mode:152 return True, None153 new_idp = self.conn.identity.update_identity_provider(idp, **attributes)154 return (True, new_idp)155 def run(self):156 """ Module entry point """157 name = self.params.get('name')158 state = self.params.get('state')159 changed = False160 idp = self.conn.identity.find_identity_provider(name)161 if state == 'absent':162 if idp is not None:163 changed = self.delete_identity_provider(idp)164 self.exit_json(changed=changed)165 # state == 'present'166 else:167 if idp is None:168 if self.params.get('domain_id') is None:169 self.fail_json(msg='A domain_id must be passed when creating'170 ' an identity provider')171 (changed, idp) = self.create_identity_provider(name)172 idp = self.normalize_idp(idp)173 self.exit_json(changed=changed, identity_provider=idp)174 (changed, new_idp) = self.update_identity_provider(idp)175 new_idp = self.normalize_idp(new_idp)176 self.exit_json(changed=changed, identity_provider=new_idp)177def 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!!