def test_config_from_json(self): """Test credentials instantiation from JSON file, with config.""" path_to_json_credentials = PATH_CRED+'/credentials_correct_withconfig_PUBLIC.json' inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials) jsonfilecontent = json.loads(open(path_to_json_credentials, 'r').read()) self.assertEqual(inst.get_config()['foo'], jsonfilecontent['foo'], 'Config not the same as in json file.') self.assertEqual(inst.get_config()['bar'], jsonfilecontent['bar'], 'Config not the same as in json file.')
def test_getters(self): """Test credentials instantiation from JSON file.""" path_to_json_credentials = PATH_CRED+'/credentials_correct_PUBLIC.json' inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials) jsonfilecontent = json.loads(open(path_to_json_credentials, 'r').read()) self.assertEqual(inst.get_username(), jsonfilecontent['username'], 'Username not the same as in json file.') self.assertEqual(inst.get_password(), jsonfilecontent['password'], 'Password not the same as in json file.') self.assertEqual(inst.get_server_URL(), jsonfilecontent['handle_server_url'], 'Server URL not the same as in json file.') self.assertEqual(inst.get_prefix(), jsonfilecontent['prefix'], 'Server URL not the same as in json file.') self.assertEqual(inst.get_handleowner(), jsonfilecontent['handleowner'], 'Server URL not the same as in json file.')
def test_credentials_from_json_missing_client(self): """Occurs when no client is provided.""" path_to_json_credentials = PATH_CRED + '/credentials_clientmissing_PUBLIC.json' with self.assertRaises(CredentialsFormatError): _inst = PIDClientCredentials.load_from_JSON( path_to_json_credentials)
def test_credentials_from_json(self): """Test credentials instantiation from JSON file.""" path_to_json_credentials = PATH_CRED + '/credentials_correct_PUBLIC.json' inst = PIDClientCredentials.load_from_JSON(path_to_json_credentials) self.assertIsInstance(inst, PIDClientCredentials)
def test_credentials_from_json_empty_items(self): """Exception occurs if items are empty in json credentials file.""" path_to_json_credentials = PATH_CRED + '/credentials_usernameempty_PUBLIC.json' with self.assertRaises(CredentialsFormatError): _inst = PIDClientCredentials.load_from_JSON( path_to_json_credentials)
def test_credentials_from_json_invalid_username(self): """Exception occurs if user name in json file is not index:prefix/suffix.""" path_to_json_credentials = PATH_CRED + '/credentials_wrongusername_PUBLIC.json' with self.assertRaises(HandleSyntaxError): _inst = PIDClientCredentials.load_from_JSON( path_to_json_credentials)
def test_credentials_from_json_username_without_index(self): """Exception occurs if user name in json file does not have an index.""" path_to_json_credentials = PATH_CRED + '/credentials_noindex_PUBLIC.json' with self.assertRaises(HandleSyntaxError): _inst = PIDClientCredentials.load_from_JSON( path_to_json_credentials)
def test_credentials_from_json_broken_syntax(self): """""" path_to_json_credentials = PATH_CRED + '/credentials_brokensyntax_PUBLIC.json' with self.assertRaises(CredentialsFormatError): _inst = PIDClientCredentials.load_from_JSON( path_to_json_credentials)
def test_credentials_from_json_empty_client(self): """Occurs when client is empty.""" path_to_json_credentials = PATH_CRED + '/credentials_clientempty_PUBLIC.json' with self.assertRaises(CredentialsFormatError): _inst = PIDClientCredentials.load_from_JSON( path_to_json_credentials)