Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move get() back to ApiWrapper class #92

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions opsramp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ def b64encode_payload(fname):
content = base64.b64encode(f.read())
return content.decode()

def get(self, suffix='', headers=None):
return self.api.get(suffix, headers)

def search(self, pattern='', headers=None, suffix='search'):
if pattern:
if pattern[0] != '?':
Expand Down
3 changes: 3 additions & 0 deletions opsramp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,6 @@ def __init__(self, apiobject, suffix=''):

def __str__(self):
return '%s %s' % (str(type(self)), self.api)

def get(self, suffix='', headers=None):
return self.api.get(suffix, headers)
17 changes: 17 additions & 0 deletions tests/test_api_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,20 @@ def test_patch(self):
m.patch(url, text=expected)
actual = self.ao.patch()
assert actual == expected

# We're not testing an exhaustive set of suffix patterns here because
# that is already being done by the ApiObject unit tests. Just
# get() and get(something) is enough.
def test_wrapped_get(self):
with requests_mock.Mocker() as m:
url = self.awrapper.api.compute_url()
expected = 'unit test wrapped get result'
m.get(url, text=expected, complete_qs=True)
actual = self.awrapper.get()
assert actual == expected
with requests_mock.Mocker() as m:
suffix = 'some/where/random'
url = self.awrapper.api.compute_url(suffix)
m.get(url, text=expected, complete_qs=True)
actual = self.awrapper.get(suffix)
assert actual == expected