Commit 6dee206f authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis

astakosclient: Replace ValueError with BadValue

All Exceptions that AstakosClient is raising should
be under AstakosClientException class
parent e975f376
...@@ -41,7 +41,7 @@ import simplejson ...@@ -41,7 +41,7 @@ import simplejson
from astakosclient.utils import retry, scheme_to_class from astakosclient.utils import retry, scheme_to_class
from astakosclient.errors import \ from astakosclient.errors import \
AstakosClientException, Unauthorized, BadRequest, NotFound, Forbidden, \ AstakosClientException, Unauthorized, BadRequest, NotFound, Forbidden, \
NoUserName, NoUUID NoUserName, NoUUID, BadValue
# -------------------------------------------------------------------- # --------------------------------------------------------------------
...@@ -89,7 +89,7 @@ class AstakosClient(): ...@@ -89,7 +89,7 @@ class AstakosClient():
if not astakos_url: if not astakos_url:
m = "Astakos url not given" m = "Astakos url not given"
logger.error(m) logger.error(m)
raise ValueError(m) raise BadValue(m)
# Check for supported scheme # Check for supported scheme
p = urlparse.urlparse(astakos_url) p = urlparse.urlparse(astakos_url)
...@@ -97,7 +97,7 @@ class AstakosClient(): ...@@ -97,7 +97,7 @@ class AstakosClient():
if conn_class is None: if conn_class is None:
m = "Unsupported scheme: %s" % p.scheme m = "Unsupported scheme: %s" % p.scheme
logger.error(m) logger.error(m)
raise ValueError(m) raise BadValue(m)
# Save astakos_url etc. in our class # Save astakos_url etc. in our class
self.retry = retry self.retry = retry
...@@ -219,7 +219,7 @@ class AstakosClient(): ...@@ -219,7 +219,7 @@ class AstakosClient():
if not uuid: if not uuid:
m = "No uuid was given" m = "No uuid was given"
self.logger.error(m) self.logger.error(m)
raise ValueError(m) raise BadValue(m)
uuid_dict = self.get_usernames(token, [uuid]) uuid_dict = self.get_usernames(token, [uuid])
if uuid in uuid_dict: if uuid in uuid_dict:
return uuid_dict.get(uuid) return uuid_dict.get(uuid)
...@@ -236,7 +236,7 @@ class AstakosClient(): ...@@ -236,7 +236,7 @@ class AstakosClient():
if not uuid: if not uuid:
m = "No uuid was given" m = "No uuid was given"
self.logger.error(m) self.logger.error(m)
raise ValueError(m) raise BadValue(m)
uuid_dict = self.service_get_usernames(token, [uuid]) uuid_dict = self.service_get_usernames(token, [uuid])
if uuid in uuid_dict: if uuid in uuid_dict:
return uuid_dict.get(uuid) return uuid_dict.get(uuid)
...@@ -278,7 +278,7 @@ class AstakosClient(): ...@@ -278,7 +278,7 @@ class AstakosClient():
if not display_name: if not display_name:
m = "No display_name was given" m = "No display_name was given"
self.logger.error(m) self.logger.error(m)
raise ValueError(m) raise BadValue(m)
name_dict = self.get_uuids(token, [display_name]) name_dict = self.get_uuids(token, [display_name])
if display_name in name_dict: if display_name in name_dict:
return name_dict.get(display_name) return name_dict.get(display_name)
...@@ -295,7 +295,7 @@ class AstakosClient(): ...@@ -295,7 +295,7 @@ class AstakosClient():
if not display_name: if not display_name:
m = "No display_name was given" m = "No display_name was given"
self.logger.error(m) self.logger.error(m)
raise ValueError(m) raise BadValue(m)
name_dict = self.service_get_uuids(token, [display_name]) name_dict = self.service_get_uuids(token, [display_name])
if display_name in name_dict: if display_name in name_dict:
return name_dict.get(display_name) return name_dict.get(display_name)
......
...@@ -42,6 +42,13 @@ class AstakosClientException(Exception): ...@@ -42,6 +42,13 @@ class AstakosClientException(Exception):
self).__init__(self.message, self.details, self.status) self).__init__(self.message, self.details, self.status)
class BadValue(AstakosClientException):
def __init__(self, details):
"""Re-define ValueError Exception under AstakosClientException"""
message = "ValueError"
super(BadValue, self).__init__(message, details)
class BadRequest(AstakosClientException): class BadRequest(AstakosClientException):
status = 400 status = 400
......
...@@ -48,7 +48,7 @@ import astakosclient ...@@ -48,7 +48,7 @@ import astakosclient
from astakosclient import AstakosClient from astakosclient import AstakosClient
from astakosclient.errors import \ from astakosclient.errors import \
AstakosClientException, Unauthorized, BadRequest, NotFound, \ AstakosClientException, Unauthorized, BadRequest, NotFound, \
NoUserName, NoUUID NoUserName, NoUUID, BadValue
# Use backported unittest functionality if Python < 2.7 # Use backported unittest functionality if Python < 2.7
try: try:
...@@ -409,12 +409,12 @@ class TestCallAstakos(unittest.TestCase): ...@@ -409,12 +409,12 @@ class TestCallAstakos(unittest.TestCase):
try: try:
client = AstakosClient("ftp://example.com", use_pool=pool) client = AstakosClient("ftp://example.com", use_pool=pool)
client._call_astakos(token_1, "/im/authenticate") client._call_astakos(token_1, "/im/authenticate")
except ValueError: except BadValue:
pass pass
except Exception: except Exception:
self.fail("Should have raise ValueError Exception") self.fail("Should have raise BadValue Exception")
else: else:
self.fail("Should have raise ValueError Exception") self.fail("Should have raise BadValue Exception")
def test_unsupported_scheme(self): def test_unsupported_scheme(self):
"""Test _unsupported_scheme without pool""" """Test _unsupported_scheme without pool"""
......
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