def test_client_init(self, mock_post):
     
     basic = authentication.Basic(username = "******",
                                  password = "******"
                                 )
     
     oauth2 = authentication.OAuth2(api_key = 'thisisnotanapikey')
     
     self.logger.info('test_client_init')
     
     got_exception = False
     
     try:
         client = cl.Client(authentication = oauth2)
     except Exception as ex:
         got_exception = True
     
     self.assertFalse(got_exception)
     self.assertEqual(client.host, "https://pairs.res.ibm.com")
     self.assertEqual(client.headers, constants.CLIENT_JSON_HEADER)
     self.assertEqual(client.authentication.api_key, "thisisnotanapikey")
     self.assertEqual(client.authentication.jwt_token, "thisisnotanaccesstoken")
     self.assertEqual(client.body, None)
     
     self.logger.info('test_client_init: set attributes')
     
     got_exception = False
     
     try:
         client.host                     = "https://pairs.res.ibm.com"
         client.headers                  = constants.CLIENT_JSON_HEADER
         client.authentication.api_key   = "thisisnotanapikey"
         client.authentication.jwt_token = "thisisnotanaccesstoken"
     except Exception as ex:
         got_exception = True
         
     self.assertFalse(got_exception)
    def test_basic_init(self):
        self.logger.info('test_basic_init')

        got_exception = False

        try:
            basic = authentication.Basic(username="******",
                                         password="******")
            basic.host = "https://pairs.res.ibm.com"
            basic.username = "******"
            basic.password = "******"
            basic.password_file = "auth/basic.txt"
        except Exception as ex:
            got_exception = True

        self.assertFalse(got_exception)
        self.assertEqual(basic.host, "pairs.res.ibm.com")
        self.assertEqual(basic.username, "*****@*****.**")
        self.assertEqual(basic.password, "thisisnotapassword")
        cwd = os.getcwd()
        self.assertEqual(basic.password_file, cwd + "/auth/basic.txt")

        self.logger.info('test_basic_init: file find password')

        self.logger.info('writing \'basic-unittest.txt\'')
        f = open("basic-unittest.txt", "a")
        f.write("pairs.res.ibm.com:[email protected]:thisisnotapassword")
        f.close()

        credentials2 = None

        try:
            credentials2 = authentication.Basic(
                password_file='basic-unittest.txt',
                username='******')
        except Exception as ex:
            got_exception = True

        self.assertFalse(got_exception)
        self.assertEqual(credentials2.username, "*****@*****.**")
        self.assertEqual(credentials2.password, "thisisnotapassword")

        self.logger.info('removing \'basic-unittest.txt\'')
        if os.path.isfile(os.path.join(os.getcwd(), 'basic-unittest.txt')):
            os.remove(os.path.join(os.getcwd(), 'basic-unittest.txt'))

        self.logger.info('test_basic_init: password is present')

        credentials3 = None

        try:
            credentials3 = authentication.Basic(username='******',
                                                password='******')
        except Exception as ex:
            got_exception = True

        self.assertFalse(got_exception)
        self.assertEqual(credentials3.username, "*****@*****.**")
        self.assertEqual(credentials3.password, "thisisnotapassword")

        self.logger.info('test_oauth2_init: no api_key')

        credentials4 = None

        try:
            credentials4 = authentication.Basic(password='******')
        except Exception as ex:
            self.assertEqual(
                str(ex),
                "AUTHENTICATION FAILED: A username and password could not be gathered from the provided attributes."
            )
            got_exception = True

        self.assertTrue(got_exception)
 def test_client_delete(self, mock_post, mock_delete):
     self.logger.info('test_client_delete')
     
     basic = authentication.Basic(username = "******",
                                  password = "******"
                                 )
     
     oauth2 = authentication.OAuth2(api_key = 'thisisnotanapikey')
     
     got_exception = False
     
     try:
        client = cl.Client(authentication = oauth2)
     except Exception as ex:
         got_exception = True
     
     self.assertFalse(got_exception)
     
     got_exception2 = False
     
     self.assertEqual(client.authentication.jwt_token, "thisisnotanaccesstoken")
     
     self.logger.info('test_client_delete: expired token core')
     
     try:
         resp = client.delete(url  = "https://token.refresh")
     except:
         got_exception2 = True
 
     self.assertFalse(got_exception2)
     self.assertEqual(resp.json(), r'''{"message":"success"}''')
     self.assertEqual(client.authentication.jwt_token, "thisisnotanewaccesstoken")
     self.assertEqual(client.authentication.oauth2_return.access_token, "thisisnotanewaccesstoken")
     self.assertEqual(client.authentication.oauth2_return.refresh_token, "thisisnotanewrefreshtoken")
     
     self.logger.info('test_client_delete: expired token upload')
         
     got_exception3 = False
     
     try:
         oauth2_2 = authentication.OAuth2(api_key = 'thisisnotanapikey')
         client2 = cl.Client(authentication = oauth2_2)
         resp2 = client2.delete(url  = "https://token.refreshed")
     except:
         got_exception3 = True
 
     self.assertFalse(got_exception3)
     self.assertEqual(resp2.json(), r'''{"message":"success"}''')
     self.assertEqual(client.authentication.jwt_token, "thisisnotanewaccesstoken")
     self.assertEqual(client.authentication.oauth2_return.access_token, "thisisnotanewaccesstoken")
     self.assertEqual(client.authentication.oauth2_return.refresh_token, "thisisnotanewrefreshtoken")
     
     self.logger.info('test_client_delete: 404')
     
     got_exception4 = False
     
     try:
         resp3 = client.delete(url  = "https://token.refreshing")
     except:
         got_exception4 = True
 
     self.assertFalse(got_exception4)
     self.assertEqual(resp3.status_code, 404)
     self.assertEqual(resp3.json(), None)
     self.assertEqual(client.authentication.jwt_token, "thisisnotanewaccesstoken")
     self.assertEqual(client.authentication.oauth2_return.access_token, "thisisnotanewaccesstoken")
     self.assertEqual(client.authentication.oauth2_return.refresh_token, "thisisnotanewrefreshtoken")