def __init__(self, config_file: str = "credentials.json"): """ Playstore object constructor. :param config_file: The path to the json configuration file, which contains the credentials. """ self.logger = logging.getLogger(f"{__name__}.{self.__class__.__name__}") # Load all the necessary configuration data and perform the login. If something # goes wrong in this phase, no further operations can be executed. try: self._load_configuration(config_file) self.android_id: str = self.configuration["ANDROID_ID"] self.email: str = self.configuration["USERNAME"] self.encrypted_password: bytes = EncryptedCredentials( self.configuration["USERNAME"], self.configuration["PASSWORD"] ).get_encrypted_credentials() self.lang_code: str = self.configuration["LANG_CODE"] self.lang: str = self.configuration["LANG"] except json.decoder.JSONDecodeError as ex: self.logger.critical(f"The configuration file is not a valid json: {ex}") raise except KeyError as ex: self.logger.critical(f"The configuration file is missing the {ex} field") raise self._login()
def __init__(self, config_file: str = 'credentials.json'): """ Playstore object constructor. :param config_file: The path to the json configuration file, which contains the credentials. """ self.logger = logging.getLogger('{0}.{1}'.format( __name__, self.__class__.__name__)) # Load all the necessary configuration data and perform the login. If something goes # wrong in this phase, no further operations can be executed. try: self._load_configuration(config_file) self.android_id: str = self.configuration['ANDROID_ID'] self.email: str = self.configuration['USERNAME'] self.encrypted_password: bytes = EncryptedCredentials( self.configuration['USERNAME'], self.configuration['PASSWORD']).get_encrypted_credentials() self.lang_code: str = self.configuration['LANG_CODE'] self.lang: str = self.configuration['LANG'] self.sdk_version: str = self.configuration['SDK_VERSION'] except json.decoder.JSONDecodeError as ex: self.logger.critical( 'The configuration file is not a valid json: {0}'.format(ex)) raise except KeyError as ex: self.logger.critical( 'The configuration file is missing the {0} field'.format(ex)) raise self._login()
def __init__(self, credential: dict = {"USERNAME":"","PASSWORD":"","ANDROID_ID":"","LANG_CODE":"en_US","LANG":"us"}): self.logger = logging.getLogger(f"{__name__}.{self.__class__.__name__}") self.configuration = credential try: self.android_id: str = credential["ANDROID_ID"] self.email: str = credential["USERNAME"] self.encrypted_password: bytes = EncryptedCredentials( credential["USERNAME"], credential["PASSWORD"] ).get_encrypted_credentials() self.lang_code: str = credential["LANG_CODE"] self.lang: str = credential["LANG"] except json.decoder.JSONDecodeError as ex: self.logger.critical(f"The configuration file is not a valid json: {ex}") raise except KeyError as ex: self.logger.critical(f"The configuration file is missing the {ex} field") raise self._login()
def test_valid_credentials(self): credentials_test = EncryptedCredentials("username", "password") assert credentials_test.get_encrypted_credentials() is not None
def test_bad_credentials(self): with pytest.raises(ValueError): EncryptedCredentials("", "")
def test_valid_credentials(self): credentials_test = EncryptedCredentials('username', 'password') assert credentials_test.get_encrypted_credentials() is not None