|
4 | 4 |
|
5 | 5 | import json |
6 | 6 | import logging |
7 | | -from datetime import timedelta, timezone |
| 7 | +from datetime import timedelta |
8 | 8 | from typing import Optional, Union |
9 | | -from unittest.mock import Mock |
| 9 | +from unittest.mock import Mock, PropertyMock |
10 | 10 |
|
11 | 11 | import freezegun |
12 | 12 | import pytest |
@@ -236,6 +236,7 @@ def test_refresh_request_body_with_keys_override(self): |
236 | 236 | } |
237 | 237 | assert body == expected |
238 | 238 |
|
| 239 | + @freezegun.freeze_time("2022-01-01") |
239 | 240 | def test_refresh_access_token(self, mocker): |
240 | 241 | oauth = Oauth2Authenticator( |
241 | 242 | token_refresh_endpoint="https://refresh_endpoint.com", |
@@ -281,6 +282,15 @@ def test_refresh_access_token(self, mocker): |
281 | 282 | assert isinstance(expires_in, str) |
282 | 283 | assert ("access_token", "2022-04-24T00:00:00Z") == (token, expires_in) |
283 | 284 |
|
| 285 | + # Test with no expires_in |
| 286 | + mocker.patch.object( |
| 287 | + resp, |
| 288 | + "json", |
| 289 | + return_value={"access_token": "access_token"}, |
| 290 | + ) |
| 291 | + token, expires_in = oauth.refresh_access_token() |
| 292 | + assert expires_in == "3600" |
| 293 | + |
284 | 294 | # Test with nested access_token and expires_in as str(int) |
285 | 295 | mocker.patch.object( |
286 | 296 | resp, |
@@ -393,8 +403,10 @@ def test_refresh_access_token_when_headers_provided(self, mocker): |
393 | 403 | "YYYY-MM-DDTHH:mm:ss.SSSSSSZ", |
394 | 404 | AirbyteDateTime(year=2022, month=2, day=12), |
395 | 405 | ), |
| 406 | + (None, None, AirbyteDateTime(year=2022, month=1, day=1, hour=1)), |
| 407 | + (None, "YYYY-MM-DD", AirbyteDateTime(year=2022, month=1, day=1, hour=1)), |
396 | 408 | ], |
397 | | - ids=["seconds", "string_of_seconds", "simple_date", "simple_datetime"], |
| 409 | + ids=["seconds", "string_of_seconds", "simple_date", "simple_datetime", "default_behavior", "default_behavior_with_format"], |
398 | 410 | ) |
399 | 411 | @freezegun.freeze_time("2022-01-01") |
400 | 412 | def test_parse_refresh_token_lifespan( |
|
0 commit comments