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