|
1 | 1 | from re import compile as regex |
2 | | -from datetime import datetime |
| 2 | +from datetime import timedelta |
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 | from freezegun import freeze_time |
@@ -51,34 +51,20 @@ def test_renew_when_token_empty(auth, responses): |
51 | 51 | assert req.headers["X-Application-Key"] == auth.client_id |
52 | 52 |
|
53 | 53 |
|
54 | | -@freeze_time("2025-02-13 10:05") |
55 | 54 | def test_renew_token_when_expired(auth, responses): |
56 | 55 | responses.add( |
57 | 56 | responses.POST, |
58 | 57 | regex(".+/auth/oauth/v2/token"), |
59 | | - json={"access_token": "NEW_VALID_TOKEN", "expires_in": 120}, |
| 58 | + json={"access_token": "FRESH_TOKEN", "expires_in": 120}, |
60 | 59 | ) |
61 | | - auth.token = "VALID_TOKEN", datetime(2025, 2, 13, 10) |
| 60 | + with freeze_time("2025-02-13 10:00"): |
| 61 | + auth.token_store.set("EXPIRED_TOKEN", timedelta(0)) |
62 | 62 |
|
63 | | - req = PreparedRequest() |
64 | | - req.prepare("GET", "https://api.santander.com.br/orders", auth=auth) |
| 63 | + with freeze_time("2025-02-13 10:01"): |
| 64 | + req = PreparedRequest() |
| 65 | + req.prepare("GET", "https://api.santander.com.br/orders", auth=auth) |
65 | 66 |
|
66 | | - assert req.headers["Authorization"] == "Bearer NEW_VALID_TOKEN" |
67 | | - assert auth.expires_at == datetime(2025, 2, 13, 10, 7) |
68 | | - |
69 | | - |
70 | | -@freeze_time("2025-02-13 10:00") |
71 | | -@pytest.mark.parametrize( |
72 | | - "expires_at,expected", |
73 | | - [ |
74 | | - (None, True), |
75 | | - (datetime(2025, 2, 13, 10, 1), False), |
76 | | - (datetime(2025, 2, 13, 10, 0, 59), True), |
77 | | - ], |
78 | | -) |
79 | | -def test_is_expired(auth, expires_at, expected): |
80 | | - auth.expires_at = expires_at |
81 | | - assert auth.is_expired is expected |
| 67 | + assert req.headers["Authorization"] == "Bearer FRESH_TOKEN" |
82 | 68 |
|
83 | 69 |
|
84 | 70 | def test_invalid_credentials(auth, responses): |
|
0 commit comments