Skip to content

Commit

Permalink
implements pages with error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
discdiver committed May 20, 2019
1 parent 62046c6 commit 6f9cac6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
28 changes: 25 additions & 3 deletions pybraries/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def __check_prerelease(*args, **kwargs):
if r:
if r.status_code == 204:
response = f"Successfully unsubscribed from {package}"
# print(f"Successfully unsubscribed from {kwargs['package']})
else:
response = r.json()
r.raise_for_status()
Expand All @@ -139,7 +138,7 @@ def __check_prerelease(*args, **kwargs):
url_end_list = url_end_list + more_args

if thing == 'pproject_dependencies':
url_end_list.append("latest/") # could make option to subscribe to other versions
url_end_list.append("latest") # could make option to subscribe to other versions
url_end_list.append("dependencies")

if thing == 'pproject_dependents':
Expand Down Expand Up @@ -529,10 +528,33 @@ def unsubscribe(self, *args, **kwargs):
Returns:
response (str or int): response header status from libraries.io
"""

return self.__call_api("delete_subscribe", *args, **kwargs)

def set_pages(self, per_page=30, page=1):
"""
Change pagination settings.
Args:
per_page (int): default=30 number of items per page. max=100
page (int): default=1 package name
Returns:
response (str): message with pagination information
"""

if not all(isinstance(i, int) for i in [page, per_page]):
raise TypeError("Must be an integer")
if page < 1:
raise ValueError("page must be an integer > 1")
if per_page > 100 or per_page < 1:
raise ValueError("perpage must be an integer between 1 and 100, inclusive")

sess.params['page'] = page # 1 returns page 1 of results, 2 returns page 2, etc.
sess.params['per_page'] = per_page # 30 is libraries api default, max is 100

return f"per_page set to {per_page} and page set to {page}."

# From the command line you can call any public function by name with arguments
if __name__ == "__main__":
Expand Down
10 changes: 10 additions & 0 deletions tests/test_pybraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,13 @@ def test_unsubscribe_unsubscribes():
# check and make sure not subscribed
pass


def test_set_pages_page_return_type():
"""call to set_pages returns a string"""
set_p = api.set_pages(page=1)
assert type(set_p) is str

def test_set_pages_big_value():
"""set_pages returns a value error for too large per_page argument"""
with pytest.raises(ValueError):
set_pages = api.set_pages(per_page=101)

0 comments on commit 6f9cac6

Please sign in to comment.