diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d5bb9dfcb7a361b0540bd0f9bf2bd78d835530ff..1297caf4b486553511907ffd891b8d23fe4da5d1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -100,4 +100,4 @@ bump-python-deps: - schedules script: - - devops python-deps requirements.txt + - devops python-deps requirements.txt tests-requirements.txt diff --git a/tests-requirements.txt b/tests-requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..b38c5845aa2d90ced995f9f3da56c9ce9354a44d --- /dev/null +++ b/tests-requirements.txt @@ -0,0 +1,3 @@ +pytest==7.2.2 +pytest-mock==3.10.0 +pytest-responses==0.5.1 diff --git a/tests/test_pagination.py b/tests/test_pagination.py index fb0fcb04a46630c1b93dddad80bbddad57caa111..ae78ad76d21d7eb570158c1d738f555fe9eb30ed 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py @@ -4,6 +4,7 @@ from pathlib import Path import pytest import responses +from responses import matchers from arkindex import ArkindexClient from arkindex.pagination import PaginationMode @@ -59,7 +60,7 @@ def test_page_pagination_with_missing_data(mock_schema, monkeypatch): responses.add( responses.GET, base_url, - match_querystring=True, + match=[matchers.query_param_matcher({})], json={ "count": 9, "number": 1, @@ -74,7 +75,8 @@ def test_page_pagination_with_missing_data(mock_schema, monkeypatch): for i in range(3): responses.add( responses.GET, - f"{base_url}?page=2", + base_url, + match=[matchers.query_param_matcher({"page": 2})], status=400, json={"error": "some error happened"}, ) @@ -82,12 +84,12 @@ def test_page_pagination_with_missing_data(mock_schema, monkeypatch): # Page 3 responses.add( responses.GET, - f"{base_url}?page=3", - match_querystring=True, + base_url, + match=[matchers.query_param_matcher({"page": 3})], json={ "count": 9, "number": 3, - "previous": f"{base_url}?page=2", + "previous": f"{base_url}?page=3", "next": None, "results": [7, 8, 9], }, @@ -123,7 +125,7 @@ def test_page_pagination_incomplete(mock_schema, monkeypatch): responses.add( responses.GET, base_url, - match_querystring=True, + match=[matchers.query_param_matcher({})], json={ "count": 9, "number": 1, @@ -137,7 +139,8 @@ def test_page_pagination_incomplete(mock_schema, monkeypatch): # Page 3 is not needed as it won't try to load it responses.add( responses.GET, - f"{base_url}?page=2", + base_url, + match=[matchers.query_param_matcher({"page": 2})], status=500, ) @@ -160,8 +163,8 @@ def test_cursor_pagination_length(mock_schema): responses.add( responses.GET, - f"{base_url}?with_count=true", - match_querystring=True, + base_url, + match=[matchers.query_param_matcher({"with_count": "true"})], json={ "count": 6, "previous": None, @@ -171,8 +174,8 @@ def test_cursor_pagination_length(mock_schema): ) responses.add( responses.GET, - f"{base_url}?cursor=DEF", - match_querystring=True, + base_url, + match=[matchers.query_param_matcher({"cursor": "DEF"})], json={ "count": None, "previous": f"{base_url}?cursor=ABC", @@ -198,8 +201,8 @@ def test_cursor_pagination_zero_results(mock_schema): base_url = "https://dummy.test/api/v1/process/process_id/elements/" responses.add( responses.GET, - f"{base_url}?with_count=true", - match_querystring=True, + base_url, + match=[matchers.query_param_matcher({"with_count": "true"})], json={ "count": 0, "previous": None, @@ -223,7 +226,8 @@ def test_cursor_pagination_len_errors(mock_schema, mocker): base_url = "https://dummy.test/api/v1/process/process_id/elements/" responses.add( responses.GET, - f"{base_url}?with_count=true", + base_url, + match=[matchers.query_param_matcher({"with_count": "true"})], status=500, ) @@ -244,7 +248,7 @@ def test_paginate_x_paginated(mock_schema): responses.add( responses.GET, "https://dummy.test/api/v1/element/element_id/metadata/", - match_querystring=True, + match=[matchers.query_param_matcher({})], json=["a", "b"], ) diff --git a/tox.ini b/tox.ini index f585be6eb01128af848e2c9ec2e990e40377b436..4707cae40069223e7d847888ab3c07b9c08424e3 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,4 @@ passenv = ARKINDEX_API_SCHEMA_URL commands = pytest {posargs} -deps = - pytest - pytest-responses - pytest-mock +deps = -rtests-requirements.txt