Skip to content

Commit

Permalink
Fix test not passing in 32-bit architectures (#2033)
Browse files Browse the repository at this point in the history
Some architectures cannot hold values after
2038 year.

This commit fixes the following tests, adjusting
the expiring date for the cookies to a maximum
year value of 2037:

* test_set_cookie
* test_expires_on_set_cookie
  • Loading branch information
kraptor authored Feb 11, 2023
1 parent 337ae24 commit 5771a78
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_file_response_with_inline_disposition(tmpdir, test_client_factory):

def test_set_cookie(test_client_factory, monkeypatch):
# Mock time used as a reference for `Expires` by stdlib `SimpleCookie`.
mocked_now = dt.datetime(2100, 1, 22, 12, 0, 0, tzinfo=dt.timezone.utc)
mocked_now = dt.datetime(2037, 1, 22, 12, 0, 0, tzinfo=dt.timezone.utc)
monkeypatch.setattr(time, "time", lambda: mocked_now.timestamp())

async def app(scope, receive, send):
Expand All @@ -316,7 +316,7 @@ async def app(scope, receive, send):
assert response.text == "Hello, world!"
assert (
response.headers["set-cookie"]
== "mycookie=myvalue; Domain=localhost; expires=Fri, 22 Jan 2100 12:00:10 GMT; "
== "mycookie=myvalue; Domain=localhost; expires=Thu, 22 Jan 2037 12:00:10 GMT; "
"HttpOnly; Max-Age=10; Path=/; SameSite=none; Secure"
)

Expand All @@ -325,15 +325,15 @@ async def app(scope, receive, send):
"expires",
[
pytest.param(
dt.datetime(2100, 1, 22, 12, 0, 10, tzinfo=dt.timezone.utc), id="datetime"
dt.datetime(2037, 1, 22, 12, 0, 10, tzinfo=dt.timezone.utc), id="datetime"
),
pytest.param("Fri, 22 Jan 2100 12:00:10 GMT", id="str"),
pytest.param("Thu, 22 Jan 2037 12:00:10 GMT", id="str"),
pytest.param(10, id="int"),
],
)
def test_expires_on_set_cookie(test_client_factory, monkeypatch, expires):
# Mock time used as a reference for `Expires` by stdlib `SimpleCookie`.
mocked_now = dt.datetime(2100, 1, 22, 12, 0, 0, tzinfo=dt.timezone.utc)
mocked_now = dt.datetime(2037, 1, 22, 12, 0, 0, tzinfo=dt.timezone.utc)
monkeypatch.setattr(time, "time", lambda: mocked_now.timestamp())

async def app(scope, receive, send):
Expand All @@ -344,7 +344,7 @@ async def app(scope, receive, send):
client = test_client_factory(app)
response = client.get("/")
cookie: SimpleCookie = SimpleCookie(response.headers.get("set-cookie"))
assert cookie["mycookie"]["expires"] == "Fri, 22 Jan 2100 12:00:10 GMT"
assert cookie["mycookie"]["expires"] == "Thu, 22 Jan 2037 12:00:10 GMT"


def test_delete_cookie(test_client_factory):
Expand Down

0 comments on commit 5771a78

Please sign in to comment.