Skip to content

Commit

Permalink
Merge pull request #92 from HewlettPackard/get-back-to-basics
Browse files Browse the repository at this point in the history
Move get() back to ApiWrapper class
  • Loading branch information
jofegan committed Nov 15, 2020
2 parents 9b20ba3 + c9d7216 commit 46c6532
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
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

0 comments on commit 46c6532

Please sign in to comment.