Skip to content

Commit 33a152e

Browse files
author
Martin Kudlej
committed
change super to call directly init functions, add setter for parent property
1 parent 4aeed3d commit 33a152e

File tree

4 files changed

+69
-63
lines changed

4 files changed

+69
-63
lines changed

threescale_api/auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class UserKeyAuth(BaseClientAuth):
3737
"""Provides user_key authentication for api client calls"""
3838

3939
def __init__(self, app, location=None):
40-
super(UserKeyAuth, self).__init__(app, location)
40+
BaseClientAuth.__init__(self, app, location)
4141
self.credentials = {
4242
self.app.service.proxy.list()["auth_user_key"]: self.app["user_key"]
4343
}
@@ -46,19 +46,19 @@ def __call__(self, request):
4646
if self.location == "authorization":
4747
auth = requests.auth.HTTPBasicAuth(next(iter(self.credentials.values())), "")
4848
return auth(request)
49-
return super().__call__(request)
49+
return BaseClientAuth.__call__(self, request)
5050

5151

5252
class AppIdKeyAuth(BaseClientAuth):
5353
"""Provides app_id/app_key pair based authentication for api client calls"""
5454

5555
def __init__(self, app, location=None):
56-
super(AppIdKeyAuth, self).__init__(app, location)
56+
BaseClientAuth.__init__(self, app, location)
5757
proxy = self.app.service.proxy.list()
5858
self.credentials = {
5959
proxy["auth_app_id"]: self.app["application_id"],
6060
proxy["auth_app_key"]: self.app.keys.list()["keys"][0]["key"]["value"]
6161
}
6262

6363
def __call__(self, request):
64-
return super().__call__(request)
64+
return BaseClientAuth.__call__(self, request)

threescale_api/defaults.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def fetch(self, entity_id: int = None, **kwargs) -> dict:
129129
Returns(dict): Resource dict from the 3scale
130130
"""
131131
log.debug(self._log_message("[FETCH] Fetch ", entity_id=entity_id, args=kwargs))
132+
print(self._log_message("[FETCH] Fetch ", entity_id=entity_id, args=kwargs))
132133
url = self._entity_url(entity_id=entity_id)
133134
response = self.rest.get(url=url, **kwargs)
134135
return utils.extract_response(response=response, entity=self._entity_name)
@@ -230,6 +231,7 @@ def _list(self, **kwargs) -> List['DefaultResource']:
230231
return instance
231232

232233
def _entity_url(self, entity_id=None) -> str:
234+
print(str(self.url), str(entity_id), str(self.threescale_client.admin_api_url))
233235
if not entity_id:
234236
return self.url
235237
return self.url + '/' + str(entity_id)
@@ -261,7 +263,7 @@ def __make_instance(self, extracted: dict, klass):
261263

262264
class DefaultResource(collections.abc.MutableMapping):
263265
def __init__(self, client: DefaultClient = None, entity_id: int = None, entity_name: str = None,
264-
entity: dict = None):
266+
entity: dict = None, **kwargs):
265267
"""Create instance of the resource
266268
Args:
267269
client: Client instance of the resource
@@ -281,6 +283,10 @@ def threescale_client(self) -> 'ThreeScaleClient':
281283
@property
282284
def parent(self) -> 'DefaultResource':
283285
return self.client.parent
286+
287+
@parent.setter
288+
def parent(self, parent):
289+
self.client.parent = parent
284290

285291
@parent.setter
286292
def parent(self, parent):
@@ -412,7 +418,7 @@ def get_default(self, **kwargs) -> Optional['DefaultResource']:
412418

413419
class DefaultPlanResource(DefaultResource):
414420
def __init__(self, entity_name='system_name', **kwargs):
415-
super().__init__(entity_name=entity_name, **kwargs)
421+
DefaultResource.__init__(self, entity_name=entity_name, **kwargs)
416422

417423
def set_default(self, **kwargs) -> 'DefaultStateResource':
418424
"""Set the plan default
@@ -458,7 +464,7 @@ def set_state(self, state: str, **kwargs) -> 'DefaultStateResource':
458464

459465
class DefaultUserResource(DefaultStateResource):
460466
def __init__(self, entity_name='username', **kwargs):
461-
super().__init__(entity_name=entity_name, **kwargs)
467+
DefaultStateResource.__init__(self, entity_name=entity_name, **kwargs)
462468

463469
def suspend(self, **kwargs) -> 'DefaultUserResource':
464470
"""Suspends the user

threescale_api/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class ThreeScaleApiError(Exception):
22
def __init__(self, message, *args):
33
self.message = message
4-
super(ThreeScaleApiError, self).__init__(message, *args)
4+
Exception.__init__(self, message, *args)
55

66

77
class ApiClientError(ThreeScaleApiError):
@@ -13,4 +13,4 @@ def __init__(self, code, reason, body, message: str = None):
1313
msg = f"Response({self.code} {reason}): {body}"
1414
if message:
1515
msg += f"; {message}"
16-
super(ApiClientError, self).__init__(msg)
16+
ThreeScaleApiError.__init__(self, msg)

0 commit comments

Comments
 (0)