Пример #1
0
    def test_config_from_init(self):
        """Test credentials instantiation from JSON file, with config."""
        inst = PIDClientCredentials(handle_server_url=self.url,
                                    username=self.user,
                                    password=self.randompassword,
                                    foo='bar',
                                    bar='baz')

        self.assertEqual(inst.get_config()['foo'], 'bar',
            'Config not the same as in json file.')

        self.assertEqual(inst.get_config()['bar'], 'baz',
            'Config not the same as in json file.')
 def test_credentials_constructor3(self):
     """Test credentials instantiation. No exception occurs if server url does not exist. """
     inst = PIDClientCredentials(client=self.client,
                                 handle_server_url='blablabla',
                                 username=self.user,
                                 password=self.randompassword)
     self.assertIsInstance(inst, PIDClientCredentials)
 def test_credentials_constructor2(self):
     """Test credentials instantiation. No exception occurs if username does not exist. """
     inst = PIDClientCredentials(client=self.client,
                                 handle_server_url=self.url,
                                 username='******',
                                 password=self.randompassword)
     self.assertIsInstance(inst, PIDClientCredentials)
 def test_credentials_constructor1(self):
     """Test credentials instantiation. No exception occurs if password wrong. """
     inst = PIDClientCredentials(client=self.client,
                                 handle_server_url=self.url,
                                 username=self.user,
                                 password=self.randompassword)
     self.assertIsInstance(inst, PIDClientCredentials)
 def test_credentials_invalid_handleowner(self):
     """Exception occurs when handle owner is not index:prefix/suffix."""
     with self.assertRaises(HandleSyntaxError):
         inst = PIDClientCredentials(handle_server_url=self.url,
                                     username=self.handle,
                                     password=self.randompassword,
                                     prefix=self.prefix,
                                     handleowner='300myhandleowner')
Пример #6
0
 def test_credentials_constructor4(self):
     """Test credentials instantiation. Prefix and handleowner can be passed. """
     inst = PIDClientCredentials(handle_server_url = self.url,
                                 username = self.user,
                                 password = self.randompassword,
                                 prefix = self.prefix,
                                 handleowner = self.owner)
     self.assertIsInstance(inst, PIDClientCredentials)
Пример #7
0
    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.')
Пример #8
0
    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)