Skip to content

Commit b43927c

Browse files
committed
test: reproduce missing pagination headers in tests
1 parent 701ad6b commit b43927c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/unit/test_gitlab.py

+30
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import pickle
2020
import warnings
21+
from copy import deepcopy
2122

2223
import pytest
2324
import responses
@@ -104,6 +105,35 @@ def test_gitlab_build_list(gl, resp_page_1, resp_page_2):
104105
assert test_list[1]["c"] == "d"
105106

106107

108+
def _strip_pagination_headers(response):
109+
"""
110+
https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers
111+
"""
112+
stripped = deepcopy(response)
113+
114+
del stripped["headers"]["X-Total-Pages"]
115+
del stripped["headers"]["X-Total"]
116+
117+
return stripped
118+
119+
120+
@pytest.mark.xfail(reason="See #1686")
121+
@responses.activate
122+
def test_gitlab_build_list_missing_headers(gl, resp_page_1, resp_page_2):
123+
stripped_page_1 = _strip_pagination_headers(resp_page_1)
124+
stripped_page_2 = _strip_pagination_headers(resp_page_2)
125+
126+
responses.add(**stripped_page_1)
127+
obj = gl.http_list("/tests", as_list=False)
128+
assert len(obj) == 0 # Lazy generator has no knowledge of total items
129+
assert obj.total_pages is None
130+
assert obj.total is None
131+
132+
responses.add(**stripped_page_2)
133+
test_list = list(obj)
134+
assert len(test_list) == 2 # List has total items after making the API calls
135+
136+
107137
@responses.activate
108138
def test_gitlab_all_omitted_when_as_list(gl, resp_page_1, resp_page_2):
109139
responses.add(**resp_page_1)

0 commit comments

Comments
 (0)