Skip to content

Commit c6aa192

Browse files
davidfrddrs73
andauthored
Added stats usage pagination support (#105)
Co-authored-by: David Redondo Durand <[email protected]>
1 parent f2ed0e9 commit c6aa192

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

ns1/rest/stats.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ def usage(
5959

6060
return self._make_request(
6161
"GET",
62-
"%s?%s" % (url, urlencode(args)),
62+
url + ('?' + urlencode(args) if args else ''),
6363
callback=callback,
6464
errback=errback,
65+
pagination_handler=stats_usage_pagination,
6566
)
67+
68+
69+
# successive pages just extend the usage list
70+
def stats_usage_pagination(curr_json, next_json):
71+
curr_json.extend(next_json)
72+
return curr_json

tests/unit/test_stats.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,27 @@ def test_qps(stats_config, value, expected):
4444
s._make_request.assert_called_once_with(
4545
"GET", expected, callback=None, errback=None
4646
)
47+
48+
49+
@pytest.mark.parametrize(
50+
"value, expected",
51+
(
52+
({}, "stats/usage"),
53+
(
54+
{"zone": "test.com", "domain": "foo", "type": "A"},
55+
"stats/usage/test.com/foo/A",
56+
),
57+
({"zone": "test.com"}, "stats/usage/test.com"),
58+
),
59+
)
60+
def test_usage(stats_config, value, expected):
61+
s = ns1.rest.stats.Stats(stats_config)
62+
s._make_request = mock.MagicMock()
63+
s.usage(**value)
64+
s._make_request.assert_called_once_with(
65+
"GET",
66+
expected,
67+
callback=None,
68+
errback=None,
69+
pagination_handler=ns1.rest.stats.stats_usage_pagination,
70+
)

0 commit comments

Comments
 (0)