FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore: add a UserWarning if both `iterator=True` and `page=X` are used by JohnVillalovos · Pull Request #2462 · python-gitlab/python-gitlab · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 13 additions & 0 deletions gitlab/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,19 @@ def http_list(

page = kwargs.get("page")

if iterator and page is not None:
arg_used_message = f"iterator={iterator}"
if as_list is not None:
arg_used_message = f"as_list={as_list}"
utils.warn(
message=(
f"`{arg_used_message}` and `page={page}` were both specified. "
f"`{arg_used_message}` will be ignored and a `list` will be "
f"returned."
),
category=UserWarning,
)

if iterator and page is None:
# Generator requested
return GitlabList(self, url, query_data, **kwargs)
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/test_gitlab_http_methods.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,22 @@ def test_list_request_page_and_iterator(gl):
response_dict["match"] = [responses.matchers.query_param_matcher({"page": "1"})]
responses.add(**response_dict)

result = gl.http_list("/projects", iterator=True, page=1)
with pytest.warns(
UserWarning, match="`iterator=True` and `page=1` were both specified"
):
result = gl.http_list("/projects", iterator=True, page=1)
assert isinstance(result, list)
assert len(result) == 20
assert len(responses.calls) == 1

with pytest.warns(
UserWarning, match="`as_list=False` and `page=1` were both specified"
):
result = gl.http_list("/projects", as_list=False, page=1)
assert isinstance(result, list)
assert len(result) == 20
assert len(responses.calls) == 2


large_list_response = {
"method": responses.GET,
Expand Down

Back | FazBrowse Home | New Git URL