Best Python code snippet using tempest_python
accounts.py
Source:accounts.py  
...104        creds = self._get_creds()105        primary_credential = auth.get_credentials(**creds)106        self.isolated_creds['primary'] = primary_credential107        return primary_credential108    def get_alt_creds(self):109        if self.isolated_creds.get('alt'):110            return self.isolated_creds.get('alt')111        creds = self._get_creds()112        alt_credential = auth.get_credentials(**creds)113        self.isolated_creds['alt'] = alt_credential114        return alt_credential115    def clear_isolated_creds(self):116        for creds in self.isolated_creds.values():117            self.remove_credentials(creds)118    def get_admin_creds(self):119        msg = ('If admin credentials are available tenant_isolation should be'120               ' used instead')121        raise NotImplementedError(msg)122class NotLockingAccounts(Accounts):123    """Credentials provider which always returns the first and second124    configured accounts as primary and alt users.125    This credential provider can be used in case of serial test execution126    to preserve the current behaviour of the serial tempest run.127    """128    def is_multi_user(self):129        if self.use_default_creds:130            # Verify that the configured users are valid and distinct131            try:132                user = self.get_primary_creds()133                alt_user = self.get_alt_creds()134                return user.username != alt_user.username135            except exceptions.InvalidCredentials as ic:136                msg = "At least one of the configured credentials is " \137                      "not valid: %s" % ic.message138                raise exceptions.InvalidConfiguration(msg)139        else:140            # TODO(andreaf) Add a uniqueness check here141            return len(self.hash_dict) > 1142    def get_creds(self, id):143        try:144            # No need to sort the dict as within the same python process145            # the HASH seed won't change, so subsequent calls to keys()146            # will return the same result147            _hash = self.hash_dict.keys()[id]148        except IndexError:149            msg = 'Insufficient number of users provided'150            raise exceptions.InvalidConfiguration(msg)151        return self.hash_dict[_hash]152    def get_primary_creds(self):153        if self.isolated_creds.get('primary'):154            return self.isolated_creds.get('primary')155        if not self.use_default_creds:156            creds = self.get_creds(0)157            primary_credential = auth.get_credentials(**creds)158        else:159            primary_credential = auth.get_default_credentials('user')160        self.isolated_creds['primary'] = primary_credential161        return primary_credential162    def get_alt_creds(self):163        if self.isolated_creds.get('alt'):164            return self.isolated_creds.get('alt')165        if not self.use_default_creds:166            creds = self.get_creds(1)167            alt_credential = auth.get_credentials(**creds)168        else:169            alt_credential = auth.get_default_credentials('alt_user')170        self.isolated_creds['alt'] = alt_credential171        return alt_credential172    def clear_isolated_creds(self):173        self.isolated_creds = {}174    def get_admin_creds(self):...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!!
