How to use _parse_resp method in tempest

Best Python code snippet using tempest_python

identity_client.py

Source:identity_client.py Github

copy

Full Screen

...34 }35 post_body = json.dumps({'role': post_body})36 resp, body = self.post('OS-KSADM/roles', post_body)37 self.expected_success(200, resp.status)38 return service_client.ResponseBody(resp, self._parse_resp(body))39 def get_role(self, role_id):40 """Get a role by its id."""41 resp, body = self.get('OS-KSADM/roles/%s' % role_id)42 self.expected_success(200, resp.status)43 body = json.loads(body)44 return service_client.ResponseBody(resp, body['role'])45 def create_tenant(self, name, **kwargs):46 """47 Create a tenant48 name (required): New tenant name49 description: Description of new tenant (default is none)50 enabled <true|false>: Initial tenant status (default is true)51 """52 post_body = {53 'name': name,54 'description': kwargs.get('description', ''),55 'enabled': kwargs.get('enabled', True),56 }57 post_body = json.dumps({'tenant': post_body})58 resp, body = self.post('tenants', post_body)59 self.expected_success(200, resp.status)60 return service_client.ResponseBody(resp, self._parse_resp(body))61 def delete_role(self, role_id):62 """Delete a role."""63 resp, body = self.delete('OS-KSADM/roles/%s' % str(role_id))64 self.expected_success(204, resp.status)65 return resp, body66 def list_user_roles(self, tenant_id, user_id):67 """Returns a list of roles assigned to a user for a tenant."""68 url = '/tenants/%s/users/%s/roles' % (tenant_id, user_id)69 resp, body = self.get(url)70 self.expected_success(200, resp.status)71 return service_client.ResponseBodyList(resp, self._parse_resp(body))72 def assign_user_role(self, tenant_id, user_id, role_id):73 """Add roles to a user on a tenant."""74 resp, body = self.put('/tenants/%s/users/%s/roles/OS-KSADM/%s' %75 (tenant_id, user_id, role_id), "")76 self.expected_success(200, resp.status)77 return service_client.ResponseBody(resp, self._parse_resp(body))78 def remove_user_role(self, tenant_id, user_id, role_id):79 """Removes a role assignment for a user on a tenant."""80 resp, body = self.delete('/tenants/%s/users/%s/roles/OS-KSADM/%s' %81 (tenant_id, user_id, role_id))82 self.expected_success(204, resp.status)83 return service_client.ResponseBody(resp, body)84 def delete_tenant(self, tenant_id):85 """Delete a tenant."""86 resp, body = self.delete('tenants/%s' % str(tenant_id))87 self.expected_success(204, resp.status)88 return service_client.ResponseBody(resp, body)89 def get_tenant(self, tenant_id):90 """Get tenant details."""91 resp, body = self.get('tenants/%s' % str(tenant_id))92 self.expected_success(200, resp.status)93 return service_client.ResponseBody(resp, self._parse_resp(body))94 def list_roles(self):95 """Returns roles."""96 resp, body = self.get('OS-KSADM/roles')97 self.expected_success(200, resp.status)98 return service_client.ResponseBodyList(resp, self._parse_resp(body))99 def list_tenants(self):100 """Returns tenants."""101 resp, body = self.get('tenants')102 self.expected_success(200, resp.status)103 body = json.loads(body)104 return service_client.ResponseBodyList(resp, body['tenants'])105 def get_tenant_by_name(self, tenant_name):106 tenants = self.list_tenants()107 for tenant in tenants:108 if tenant['name'] == tenant_name:109 return tenant110 raise lib_exc.NotFound('No such tenant')111 def update_tenant(self, tenant_id, **kwargs):112 """Updates a tenant."""113 body = self.get_tenant(tenant_id)114 name = kwargs.get('name', body['name'])115 desc = kwargs.get('description', body['description'])116 en = kwargs.get('enabled', body['enabled'])117 post_body = {118 'id': tenant_id,119 'name': name,120 'description': desc,121 'enabled': en,122 }123 post_body = json.dumps({'tenant': post_body})124 resp, body = self.post('tenants/%s' % tenant_id, post_body)125 self.expected_success(200, resp.status)126 return service_client.ResponseBody(resp, self._parse_resp(body))127 def create_user(self, name, password, tenant_id, email, **kwargs):128 """Create a user."""129 post_body = {130 'name': name,131 'password': password,132 'email': email133 }134 if tenant_id is not None:135 post_body['tenantId'] = tenant_id136 if kwargs.get('enabled') is not None:137 post_body['enabled'] = kwargs.get('enabled')138 post_body = json.dumps({'user': post_body})139 resp, body = self.post('users', post_body)140 self.expected_success(200, resp.status)141 return service_client.ResponseBody(resp, self._parse_resp(body))142 def update_user(self, user_id, **kwargs):143 """Updates a user."""144 put_body = json.dumps({'user': kwargs})145 resp, body = self.put('users/%s' % user_id, put_body)146 self.expected_success(200, resp.status)147 return service_client.ResponseBody(resp, self._parse_resp(body))148 def get_user(self, user_id):149 """GET a user."""150 resp, body = self.get("users/%s" % user_id)151 self.expected_success(200, resp.status)152 return service_client.ResponseBody(resp, self._parse_resp(body))153 def delete_user(self, user_id):154 """Delete a user."""155 resp, body = self.delete("users/%s" % user_id)156 self.expected_success(204, resp.status)157 return service_client.ResponseBody(resp, body)158 def get_users(self):159 """Get the list of users."""160 resp, body = self.get("users")161 self.expected_success(200, resp.status)162 return service_client.ResponseBodyList(resp, self._parse_resp(body))163 def enable_disable_user(self, user_id, enabled):164 """Enables or disables a user."""165 put_body = {166 'enabled': enabled167 }168 put_body = json.dumps({'user': put_body})169 resp, body = self.put('users/%s/enabled' % user_id, put_body)170 self.expected_success(200, resp.status)171 return service_client.ResponseBody(resp, self._parse_resp(body))172 def get_token(self, token_id):173 """Get token details."""174 resp, body = self.get("tokens/%s" % token_id)175 self.expected_success(200, resp.status)176 return service_client.ResponseBody(resp, self._parse_resp(body))177 def delete_token(self, token_id):178 """Delete a token."""179 resp, body = self.delete("tokens/%s" % token_id)180 self.expected_success(204, resp.status)181 return service_client.ResponseBody(resp, body)182 def list_users_for_tenant(self, tenant_id):183 """List users for a Tenant."""184 resp, body = self.get('/tenants/%s/users' % tenant_id)185 self.expected_success(200, resp.status)186 return service_client.ResponseBodyList(resp, self._parse_resp(body))187 def get_user_by_username(self, tenant_id, username):188 users = self.list_users_for_tenant(tenant_id)189 for user in users:190 if user['name'] == username:191 return user192 raise lib_exc.NotFound('No such user')193 def create_service(self, name, type, **kwargs):194 """Create a service."""195 post_body = {196 'name': name,197 'type': type,198 'description': kwargs.get('description')199 }200 post_body = json.dumps({'OS-KSADM:service': post_body})201 resp, body = self.post('/OS-KSADM/services', post_body)202 self.expected_success(200, resp.status)203 return service_client.ResponseBody(resp, self._parse_resp(body))204 def get_service(self, service_id):205 """Get Service."""206 url = '/OS-KSADM/services/%s' % service_id207 resp, body = self.get(url)208 self.expected_success(200, resp.status)209 return service_client.ResponseBody(resp, self._parse_resp(body))210 def list_services(self):211 """List Service - Returns Services."""212 resp, body = self.get('/OS-KSADM/services')213 self.expected_success(200, resp.status)214 return service_client.ResponseBodyList(resp, self._parse_resp(body))215 def delete_service(self, service_id):216 """Delete Service."""217 url = '/OS-KSADM/services/%s' % service_id218 resp, body = self.delete(url)219 self.expected_success(204, resp.status)220 return service_client.ResponseBody(resp, body)221 def update_user_password(self, user_id, new_pass):222 """Update User Password."""223 put_body = {224 'password': new_pass,225 'id': user_id226 }227 put_body = json.dumps({'user': put_body})228 resp, body = self.put('users/%s/OS-KSADM/password' % user_id, put_body)229 self.expected_success(200, resp.status)230 return service_client.ResponseBody(resp, self._parse_resp(body))231 def list_extensions(self):232 """List all the extensions."""233 resp, body = self.get('/extensions')234 self.expected_success(200, resp.status)235 body = json.loads(body)236 return service_client.ResponseBodyList(resp,237 body['extensions']['values'])238 def create_user_ec2_credentials(self, user_id, tenant_id):239 post_body = json.dumps({'tenant_id': tenant_id})240 resp, body = self.post('/users/%s/credentials/OS-EC2' % user_id,241 post_body)242 self.expected_success(200, resp.status)243 return service_client.ResponseBody(resp, self._parse_resp(body))244 def list_user_ec2_credentials(self, user_id):245 resp, body = self.get('/users/%s/credentials/OS-EC2' % user_id)246 self.expected_success(200, resp.status)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful