Commit 4ce259a6 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

Rename AstakosClient's authenticate method to getUserInfo

parent e3ae6f4d
...@@ -168,8 +168,8 @@ class AstakosClient(): ...@@ -168,8 +168,8 @@ class AstakosClient():
return simplejson.loads(unicode(data)) return simplejson.loads(unicode(data))
# ------------------------ # ------------------------
def authenticate(self, token, usage=False): def getUserInfo(self, token, usage=False):
"""Check if user is authenticated Astakos user """Authenticate user and get user's info as a dictionary
Keyword arguments: Keyword arguments:
token -- user's token (string) token -- user's token (string)
......
...@@ -429,7 +429,7 @@ class TestCallAstakos(unittest.TestCase): ...@@ -429,7 +429,7 @@ class TestCallAstakos(unittest.TestCase):
class TestAuthenticate(unittest.TestCase): class TestAuthenticate(unittest.TestCase):
"""Test cases for function authenticate""" """Test cases for function getUserInfo"""
# ---------------------------------- # ----------------------------------
# Test the response we get if we don't have internet access # Test the response we get if we don't have internet access
...@@ -439,7 +439,7 @@ class TestAuthenticate(unittest.TestCase): ...@@ -439,7 +439,7 @@ class TestAuthenticate(unittest.TestCase):
_mockRequest([_requestOffline]) _mockRequest([_requestOffline])
try: try:
client = AstakosClient("https://example.com", retry=3) client = AstakosClient("https://example.com", retry=3)
client.authenticate(token_1) client.getUserInfo(token_1)
except AstakosClientException: except AstakosClientException:
pass pass
else: else:
...@@ -452,7 +452,7 @@ class TestAuthenticate(unittest.TestCase): ...@@ -452,7 +452,7 @@ class TestAuthenticate(unittest.TestCase):
_mockRequest([_requestOk]) _mockRequest([_requestOk])
try: try:
client = AstakosClient("https://example.com", use_pool=pool) client = AstakosClient("https://example.com", use_pool=pool)
client.authenticate(token) client.getUserInfo(token)
except Unauthorized: except Unauthorized:
pass pass
except Exception: except Exception:
...@@ -474,7 +474,7 @@ class TestAuthenticate(unittest.TestCase): ...@@ -474,7 +474,7 @@ class TestAuthenticate(unittest.TestCase):
_mockRequest([_requestOk]) _mockRequest([_requestOk])
try: try:
client = AstakosClient("https://example.com", use_pool=pool) client = AstakosClient("https://example.com", use_pool=pool)
auth_info = client.authenticate(token, usage=usage) auth_info = client.getUserInfo(token, usage=usage)
except: except:
self.fail("Shouldn't raise an Exception") self.fail("Shouldn't raise an Exception")
self.assertEqual(user_info, auth_info) self.assertEqual(user_info, auth_info)
...@@ -516,12 +516,12 @@ class TestAuthenticate(unittest.TestCase): ...@@ -516,12 +516,12 @@ class TestAuthenticate(unittest.TestCase):
# ---------------------------------- # ----------------------------------
# Test retry functionality # Test retry functionality
def test_OfflineRetry(self): def test_OfflineRetry(self):
"""Test retry functionality for authentication""" """Test retry functionality for getUserInfo"""
global token_1, user_1 global token_1, user_1
_mockRequest([_requestOffline, _requestOffline, _requestOk]) _mockRequest([_requestOffline, _requestOffline, _requestOk])
try: try:
client = AstakosClient("https://example.com", retry=2) client = AstakosClient("https://example.com", retry=2)
auth_info = client.authenticate(token_1, usage=True) auth_info = client.getUserInfo(token_1, usage=True)
except: except:
self.fail("Shouldn't raise an Exception") self.fail("Shouldn't raise an Exception")
self.assertEqual(user_1, auth_info) self.assertEqual(user_1, auth_info)
......
...@@ -34,7 +34,7 @@ demonstrates how to get user's info using ``astakosclient``. ...@@ -34,7 +34,7 @@ demonstrates how to get user's info using ``astakosclient``.
from astakosclient import AstakosClient from astakosclient import AstakosClient
client = AstakosClient("https://accounts.example.com") client = AstakosClient("https://accounts.example.com")
user_info = client.authenticate("UQpYas7ElzWGD5yCcEXtjw==") user_info = client.getUserInfo("UQpYas7ElzWGD5yCcEXtjw==")
print user_info['username'] print user_info['username']
Another example where we ask for the username of a user with UUID: Another example where we ask for the username of a user with UUID:
...@@ -67,7 +67,7 @@ retry=0, use_pool=False, pool_size=8, logger=None\ **)** ...@@ -67,7 +67,7 @@ retry=0, use_pool=False, pool_size=8, logger=None\ **)**
This class provides the following methods: This class provides the following methods:
**authenticate(**\ token, usage=False\ **)** **getUserInfo(**\ token, usage=False\ **)**
Given a valid authentication token it returns a dict with the Given a valid authentication token it returns a dict with the
correspoinding user's info. If usage is set to True more correspoinding user's info. If usage is set to True more
information about user's resources will be returned. information about user's resources will be returned.
......
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