Best Python code snippet using tempest_python
cred_client.py
Source: cred_client.py
...40 def create_project(self, name, description):41 pass42 def _check_role_exists(self, role_name):43 try:44 roles = self._list_roles()45 role = next(r for r in roles if r['name'] == role_name)46 except StopIteration:47 return None48 return role49 def create_user_role(self, role_name):50 if not self._check_role_exists(role_name):51 self.identity_client.create_role(role_name)52 def assign_user_role(self, user, project, role_name):53 role = self._check_role_exists(role_name)54 if not role:55 msg = 'No "%s" role found' % role_name56 raise lib_exc.NotFound(msg)57 try:58 self.identity_client.assign_user_role(project['id'], user['id'],59 role['id'])60 except lib_exc.Conflict:61 LOG.debug("Role %s already assigned on project %s for user %s" % (62 role['id'], project['id'], user['id']))63 @abc.abstractmethod64 def get_credentials(self, user, project, password):65 pass66 def delete_user(self, user_id):67 self.identity_client.delete_user(user_id)68 def _list_roles(self):69 roles = self.identity_client.list_roles()['roles']70 return roles71class V2CredsClient(CredsClient):72 def create_project(self, name, description):73 tenant = self.identity_client.create_tenant(74 name=name, description=description)['tenant']75 return tenant76 def get_credentials(self, user, project, password):77 return cred_provider.get_credentials(78 identity_version='v2',79 username=user['name'], user_id=user['id'],80 tenant_name=project['name'], tenant_id=project['id'],81 password=password)82 def delete_project(self, project_id):83 self.identity_client.delete_tenant(project_id)84class V3CredsClient(CredsClient):85 def __init__(self, identity_client, domain_name):86 super(V3CredsClient, self).__init__(identity_client)87 try:88 # Domain names must be unique, in any case a list is returned,89 # selecting the first (and only) element90 self.creds_domain = self.identity_client.list_domains(91 params={'name': domain_name})['domains'][0]92 except lib_exc.NotFound:93 # TODO(andrea) we could probably create the domain on the fly94 msg = "Configured domain %s could not be found" % domain_name95 raise exceptions.InvalidConfiguration(msg)96 def create_project(self, name, description):97 project = self.identity_client.create_project(98 name=name, description=description,99 domain_id=self.creds_domain['id'])['project']100 return project101 def get_credentials(self, user, project, password):102 return cred_provider.get_credentials(103 identity_version='v3',104 username=user['name'], user_id=user['id'],105 project_name=project['name'], project_id=project['id'],106 password=password,107 project_domain_name=self.creds_domain['name'])108 def delete_project(self, project_id):109 self.identity_client.delete_project(project_id)110 def _list_roles(self):111 roles = self.identity_client.list_roles()['roles']112 return roles113def get_creds_client(identity_client, project_domain_name=None):114 if isinstance(identity_client, v2_identity.IdentityClient):115 return V2CredsClient(identity_client)116 else:...
sensu.py
Source: sensu.py
...34 """35 """36 ret = []37 if role is None:38 roles = _list_roles()39 else:40 roles = [role]41 for role in roles:42 path = '/etc/sensu/conf.d/checks-' + role + '.json'43 if role in _list_roles() \44 and not __salt__['file.file_exists'](path):45 __salt__['state.sls'](role)46 __salt__['state.sls'](role + '.relate-sensu-api',47 pillar={'test': True})48 ret += _list_values(key='checks', pattern='checks-' + role)49 return ret50def list_clients():51 """52 """53 return _list_values(key='clients')54def list_commands(55 role=None,56 handler='default'):57 """58 """59 ret = []60 for (name, val) in list_checks(role=role):61 handlers = val.get('handlers', [])62 if handler in handlers:63 command = val.get('command', '').split()64 if command[0].split('.')[-1] == 'rb':65 command = [u'/opt/sensu/embedded/bin/ruby'] + command66 ret += [(name, command)]67 return ret68def list_handlers():69 """70 """71 return _list_values(key='handlers')72def list_mutators():73 """74 """75 return _list_values(key='mutators')76def _list_values(77 key=None,78 pattern='*'):79 """80 """81 ret = []82 paths = glob('/etc/sensu/conf.d/' + pattern + '.json')83 for path in paths:84 with open(path) as json:85 val = load(json).get(key)86 if isinstance(val, dict):87 ret += list(val.items())88 else:89 ret += [val] if val is not None else []90 return ret91def _list_roles():92 """93 """94 return set([r for r in list(__salt__['config.get']('roles')) +...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
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!!