|
| 1 | +from urllib.parse import parse_qs, urlsplit |
| 2 | + |
1 | 3 | import pytest |
2 | 4 | from pystac_client.conformance import ConformanceClasses |
3 | 5 |
|
@@ -75,3 +77,32 @@ def test_custom_headers(self, requests_mock): |
75 | 77 | assert len(history) == 1 |
76 | 78 | assert header_name in history[0].headers |
77 | 79 | assert history[0].headers[header_name] == header_value |
| 80 | + |
| 81 | + def test_custom_query_params(self, requests_mock): |
| 82 | + """Checks that query params passed to the init method are added to requests.""" |
| 83 | + init_qp_name = "my-param" |
| 84 | + init_qp_value = "something" |
| 85 | + url = "https://some-url.com/some-file.json" |
| 86 | + stac_api_io = StacApiIO(parameters={init_qp_name: init_qp_value}) |
| 87 | + |
| 88 | + request_qp_name = "another-param" |
| 89 | + request_qp_value = "another_value" |
| 90 | + requests_mock.get(url, status_code=200, json={}) |
| 91 | + |
| 92 | + stac_api_io.read_json(url, parameters={request_qp_name: request_qp_value}) |
| 93 | + |
| 94 | + history = requests_mock.request_history |
| 95 | + assert len(history) == 1 |
| 96 | + |
| 97 | + actual_qs = urlsplit(history[0].url).query |
| 98 | + actual_qp = parse_qs(actual_qs) |
| 99 | + |
| 100 | + # Check that the param from the init method is present |
| 101 | + assert init_qp_name in actual_qp |
| 102 | + assert len(actual_qp[init_qp_name]) == 1 |
| 103 | + assert actual_qp[init_qp_name][0] == init_qp_value |
| 104 | + |
| 105 | + # Check that the param from the request is present |
| 106 | + assert request_qp_name in actual_qp |
| 107 | + assert len(actual_qp[request_qp_name]) == 1 |
| 108 | + assert actual_qp[request_qp_name][0] == request_qp_value |
0 commit comments