Commit c21f797c authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis Committed by Christos Stavrakakis
Browse files

TestAuthenticate now works with AstakosClient

parent 8de6ff1a
...@@ -400,103 +400,106 @@ class TestCallAstakos(unittest.TestCase): ...@@ -400,103 +400,106 @@ class TestCallAstakos(unittest.TestCase):
self._getUserCatalogs(True) self._getUserCatalogs(True)
#class TestAuthenticate(unittest.TestCase): class TestAuthenticate(unittest.TestCase):
# """Test cases for function authenticate""" """Test cases for function authenticate"""
#
# # ---------------------------------- # ----------------------------------
# # Test the response we get if we don't have internet access # Test the response we get if we don't have internet access
# def test_Offline(self): def test_Offline(self):
# """Test offline after 3 replies""" """Test offline after 3 retries"""
# global token_1 global token_1
# _mockRequest([_requestOffline]) _mockRequest([_requestOffline])
# try: try:
# astakosclient.authenticate(token_1, "https://example.com") client = AstakosClient(
# except socket.error: token_1, "https://example.com", retry=3)
# pass client.authenticate()
# except Exception: except AstakosClientException:
# self.fail("Should have raised socket exception") pass
# else: else:
# self.fail("Shouldn't succeed") self.fail("Should have raised AstakosClientException exception")
#
# # ---------------------------------- # ----------------------------------
# # Test the response we get for invalid token # Test the response we get for invalid token
# def _invalidToken(self, pool): def _invalidToken(self, pool):
# token = "skaksaFlBl+fasFdaf24sx==" token = "skaksaFlBl+fasFdaf24sx=="
# _mockRequest([_requestOk]) _mockRequest([_requestOk])
# try: try:
# astakosclient.authenticate( client = AstakosClient(
# token, "https://example.com", use_pool=pool) token, "https://example.com", use_pool=pool)
# except Exception as (status, data): client.authenticate()
# if status != 401: except AstakosClientException as err:
# self.fail("Should have returned 401 (Invalide X-Auth-Token)") if err.status != 401:
# else: self.fail("Should have returned 401 (Invalide X-Auth-Token)")
# self.fail("Should have returned 401 (Invalide X-Auth-Token)") else:
# self.fail("Should have returned 401 (Invalide X-Auth-Token)")
# def test_InvalidToken(self):
# """Test _invalidToken without pool""" def test_InvalidToken(self):
# self._invalidToken(False) """Test _invalidToken without pool"""
# self._invalidToken(False)
# def test_InvalidTokenPool(self):
# """Test _invalidToken using pool""" def test_InvalidTokenPool(self):
# self._invalidToken(True) """Test _invalidToken using pool"""
# self._invalidToken(True)
# #- ---------------------------------
# # Test response for user 1 #- ---------------------------------
# def _authUser(self, token, user_info, usage, pool): # Test response for user 1
# _mockRequest([_requestOk]) def _authUser(self, token, user_info, usage, pool):
# try: _mockRequest([_requestOk])
# auth_info = astakosclient.authenticate( try:
# token, "https://example.com/", usage=usage, use_pool=pool) client = AstakosClient(
# except: token, "https://example.com", use_pool=pool)
# self.fail("Shouldn't raise an Exception") auth_info = client.authenticate(usage=usage)
# self.assertEqual(user_info, auth_info) except:
# self.fail("Shouldn't raise an Exception")
# def test_AuthUserOne(self): self.assertEqual(user_info, auth_info)
# """Test _authUser for User 1 without pool, without usage"""
# global token_1, user_1 def test_AuthUserOne(self):
# user_info = dict(user_1) """Test _authUser for User 1 without pool, without usage"""
# del user_info['usage'] global token_1, user_1
# self._authUser(token_1, user_info, False, False) user_info = dict(user_1)
# del user_info['usage']
# def test_AuthUserOneUsage(self): self._authUser(token_1, user_info, False, False)
# """Test _authUser for User 1 without pool, with usage"""
# global token_1, user_1 def test_AuthUserOneUsage(self):
# self._authUser(token_1, user_1, True, False) """Test _authUser for User 1 without pool, with usage"""
# global token_1, user_1
# def test_AuthUserOneUsagePool(self): self._authUser(token_1, user_1, True, False)
# """Test _authUser for User 1 using pool, with usage"""
# global token_1, user_1 def test_AuthUserOneUsagePool(self):
# self._authUser(token_1, user_1, True, True) """Test _authUser for User 1 using pool, with usage"""
# global token_1, user_1
# def test_AuthUserTwo(self): self._authUser(token_1, user_1, True, True)
# """Test _authUser for User 2 without pool, without usage"""
# global token_2, user_2 def test_AuthUserTwo(self):
# user_info = dict(user_2) """Test _authUser for User 2 without pool, without usage"""
# del user_info['usage'] global token_2, user_2
# self._authUser(token_2, user_info, False, False) user_info = dict(user_2)
# del user_info['usage']
# def test_AuthUserTwoUsage(self): self._authUser(token_2, user_info, False, False)
# """Test _authUser for User 2 without pool, with usage"""
# global token_2, user_2 def test_AuthUserTwoUsage(self):
# self._authUser(token_2, user_2, True, False) """Test _authUser for User 2 without pool, with usage"""
# global token_2, user_2
# def test_AuthUserTwoUsagePool(self): self._authUser(token_2, user_2, True, False)
# """Test _authUser for User 2 using pool, with usage"""
# global token_2, user_2 def test_AuthUserTwoUsagePool(self):
# self._authUser(token_2, user_2, True, True) """Test _authUser for User 2 using pool, with usage"""
# global token_2, user_2
# # ---------------------------------- self._authUser(token_2, user_2, True, True)
# # Test retry functionality
# def test_OfflineRetry(self): # ----------------------------------
# """Test retry functionality for authentication""" # Test retry functionality
# global token_1, user_1 def test_OfflineRetry(self):
# _mockRequest([_requestOffline, _requestOffline, _requestOk]) """Test retry functionality for authentication"""
# try: global token_1, user_1
# auth_info = astakosclient.authenticate( _mockRequest([_requestOffline, _requestOffline, _requestOk])
# token_1, "https://example.com", usage=True) try:
# except: client = AstakosClient(
# self.fail("Shouldn't raise an Exception") token_1, "https://example.com", retry=2)
# self.assertEqual(user_1, auth_info) auth_info = client.authenticate(usage=True)
except:
self.fail("Shouldn't raise an Exception")
self.assertEqual(user_1, auth_info)
# ---------------------------- # ----------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment