Skip to content

Commit

Permalink
Added stats usage pagination support (#105)
Browse files Browse the repository at this point in the history
Co-authored-by: David Redondo Durand <david.redondo@system73.com>
  • Loading branch information
davidfrd and drs73 authored Aug 1, 2022
1 parent f2ed0e9 commit c6aa192
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ns1/rest/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ def usage(

return self._make_request(
"GET",
"%s?%s" % (url, urlencode(args)),
url + ('?' + urlencode(args) if args else ''),
callback=callback,
errback=errback,
pagination_handler=stats_usage_pagination,
)


# successive pages just extend the usage list
def stats_usage_pagination(curr_json, next_json):
curr_json.extend(next_json)
return curr_json
24 changes: 24 additions & 0 deletions tests/unit/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,27 @@ def test_qps(stats_config, value, expected):
s._make_request.assert_called_once_with(
"GET", expected, callback=None, errback=None
)


@pytest.mark.parametrize(
"value, expected",
(
({}, "stats/usage"),
(
{"zone": "test.com", "domain": "foo", "type": "A"},
"stats/usage/test.com/foo/A",
),
({"zone": "test.com"}, "stats/usage/test.com"),
),
)
def test_usage(stats_config, value, expected):
s = ns1.rest.stats.Stats(stats_config)
s._make_request = mock.MagicMock()
s.usage(**value)
s._make_request.assert_called_once_with(
"GET",
expected,
callback=None,
errback=None,
pagination_handler=ns1.rest.stats.stats_usage_pagination,
)

0 comments on commit c6aa192

Please sign in to comment.