Skip to content

Commit

Permalink
Fix Endpoint.get test error
Browse files Browse the repository at this point in the history
  • Loading branch information
timizuoebideri1 committed Apr 10, 2022
1 parent a81a7ba commit 3956bd9
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pynautobot/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def all(self, api_version=None):

return response_loader(req.get(), self.return_obj, self)

def get(self, api_version=None, *args, **kwargs):
def get(self, *args, **kwargs):
r"""Queries the DetailsView of a given endpoint.
:arg int,optional key: id for the item to be
Expand Down Expand Up @@ -141,6 +141,9 @@ def get(self, api_version=None, *args, **kwargs):
except IndexError:
key = None

is_api_version = kwargs.pop("api_version") if kwargs.get("api_version") else None
api_version = is_api_version or self.api.api_version

if not key:
filter_lookup = self.filter(**kwargs)
if filter_lookup:
Expand All @@ -154,8 +157,6 @@ def get(self, api_version=None, *args, **kwargs):
return filter_lookup[0]
return None

api_version = api_version or self.api.api_version

req = Request(
key=key, base=self.url, token=self.token, http_session=self.api.http_session, api_version=api_version,
)
Expand Down Expand Up @@ -406,11 +407,7 @@ def __init__(self, parent_obj, name, custom_return=None):
self.custom_return = custom_return
self.url = "{}/{}/{}/".format(parent_obj.endpoint.url, parent_obj.id, name)

self.request_kwargs = dict(
base=self.url,
token=parent_obj.api.token,
http_session=parent_obj.api.http_session,
)
self.request_kwargs = dict(base=self.url, token=parent_obj.api.token, http_session=parent_obj.api.http_session,)

def list(self, api_version=None, **kwargs):
r"""The view operation for a detail endpoint
Expand All @@ -426,7 +423,7 @@ def list(self, api_version=None, **kwargs):
Nautobot.
"""
api_version = api_version or self.parent_obj.api.api_version

req = Request(api_version=api_version, **self.request_kwargs).get(add_params=kwargs)

if self.custom_return:
Expand All @@ -450,7 +447,7 @@ def create(self, data=None, api_version=None):
"""
data = data or {}
api_version = api_version or self.parent_obj.api.api_version

req = Request(api_version=api_version, **self.request_kwargs).post(data)
if self.custom_return:
return response_loader(req, self.custom_return, self.parent_obj.endpoint)
Expand Down

0 comments on commit 3956bd9

Please sign in to comment.