Skip to content

Commit

Permalink
Merge pull request #67 from TheFriendlyCoder/page_fix
Browse files Browse the repository at this point in the history
Fixes #65 Fixed paged results when only one page exists
  • Loading branch information
TheFriendlyCoder committed Apr 20, 2018
2 parents 2660eb9 + 8bbe00b commit 47a45b6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/friendlypins/utils/rest_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def get_pages(self, path, properties=None):
result = self.get(path, properties)
yield result

if "page" not in result:
break
if "cursor" not in result["page"]:
break
if not result["page"]["cursor"]:
break

Expand Down
24 changes: 24 additions & 0 deletions unit_tests/test_rest_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ def test_get_method(mock_requests):
assert "access_token" in mock_requests.get.call_args[1]['params']
assert mock_requests.get.call_args[1]['params']['access_token'] == expected_token

@mock.patch("friendlypins.utils.rest_io.requests")
def test_get_pages_one_page(mock_requests):
expected_token = "1234abcd"
obj = RestIO(expected_token)

expected_path = "me/boards"
expected_result = {
"id": "abcd1234"
}
mock_response = mock.MagicMock()
mock_response.json.return_value = expected_result
mock_requests.get.return_value = mock_response
res = list()
for cur_res in obj.get_pages(expected_path):
res.append(cur_res)

assert len(res) == 1
assert res[0] == expected_result
mock_requests.get.assert_called_once()
mock_response.raise_for_status.assert_called_once()
assert expected_path in mock_requests.get.call_args[0][0]
assert "access_token" in mock_requests.get.call_args[1]['params']
assert mock_requests.get.call_args[1]['params']['access_token'] == expected_token

@mock.patch("friendlypins.utils.rest_io.requests")
def test_get_headers(mock_requests):
obj = RestIO("1234abcd")
Expand Down

0 comments on commit 47a45b6

Please sign in to comment.