diff --git a/swh/core/pytest_plugin.py b/swh/core/pytest_plugin.py --- a/swh/core/pytest_plugin.py +++ b/swh/core/pytest_plugin.py @@ -45,11 +45,11 @@ then a call requests.get like: - requests.get('https://nowhere.com/path/to/resource') + requests.get('https://nowhere.com/path/to/resource?a=b&c=d') will look the content of the response in: - datadir/nowhere.com/path_to_resource + datadir/nowhere.com/path_to_resource,a=b,c=d Args: request (requests.Request): Object requests @@ -77,6 +77,9 @@ if filename.endswith('/'): filename = filename[:-1] filename = filename.replace('/', '_') + if url.query: + filename += ',' + url.query.replace('&', ',') + filepath = path.join(datadir, dirname, filename) if visits is not None: visit = visits.get(url, 0) diff --git a/swh/core/tests/data/example.com/file.json,name=doe,firstname=jane b/swh/core/tests/data/example.com/file.json,name=doe,firstname=jane new file mode 100644 --- /dev/null +++ b/swh/core/tests/data/example.com/file.json,name=doe,firstname=jane @@ -0,0 +1,3 @@ +{ + "hello": "jane doe" +} diff --git a/swh/core/tests/test_pytest_plugin.py b/swh/core/tests/test_pytest_plugin.py --- a/swh/core/tests/test_pytest_plugin.py +++ b/swh/core/tests/test_pytest_plugin.py @@ -56,6 +56,17 @@ assert response.json() == {'hello': 'you'} +def test_get_response_cb_query_params(requests_mock_datadir): + response = requests.get('https://example.com/file.json?toto=42') + assert not response.ok + assert response.status_code == 404 + + response = requests.get( + 'https://example.com/file.json?name=doe&firstname=jane') + assert response.ok + assert response.json() == {'hello': 'jane doe'} + + requests_mock_datadir_ignore = requests_mock_datadir_factory( ignore_urls=['https://example.com/file.json'], has_multi_visit=False,