|
2 | 2 | from dataclasses import dataclass |
3 | 3 | from datetime import datetime |
4 | 4 | from typing import Optional |
| 5 | +from urllib.parse import parse_qs, unquote, urlsplit |
5 | 6 | from unittest.mock import Mock |
| 7 | +from zoneinfo import ZoneInfo |
6 | 8 |
|
7 | 9 | import pytest |
8 | 10 |
|
@@ -262,6 +264,21 @@ def test_sets_datetime_values_in_path_parameters(): |
262 | 264 | assert request_info.url == "https://example.com/daysFrom/2020-08-01T00%3A20%3A00%2B00%3A00" |
263 | 265 |
|
264 | 266 |
|
| 267 | +@pytest.mark.parametrize("fold", [0, 1]) |
| 268 | +@pytest.mark.parametrize("location", ["path", "query", "query_collection"]) |
| 269 | +def test_datetime_parameters_preserve_fold(fold, location): |
| 270 | + value = datetime(2020, 11, 1, 1, 30, tzinfo=ZoneInfo("America/New_York"), fold=fold) |
| 271 | + if location == "path": |
| 272 | + request_info = RequestInformation(Method.GET, "https://example.com/events/{at}") |
| 273 | + request_info.path_parameters["at"] = value |
| 274 | + actual = unquote(urlsplit(request_info.url).path).rsplit("/", 1)[-1] |
| 275 | + else: |
| 276 | + request_info = RequestInformation(Method.GET, "https://example.com/events{?at}") |
| 277 | + request_info.query_parameters["at"] = [value] if location == "query_collection" else value |
| 278 | + actual = parse_qs(urlsplit(request_info.url).query)["at"][0] |
| 279 | + assert actual == value.isoformat() |
| 280 | + |
| 281 | + |
265 | 282 | def test_sets_int_values_in_path_parameters(): |
266 | 283 | """Tests setting int values values in path parameters |
267 | 284 | """ |
|
0 commit comments