@@ -301,6 +301,7 @@ def test_initialize_declarative_oauth_with_token_expiry_date_as_timestamp(
301
301
client_id = "{{ config['client_id'] }}" ,
302
302
client_secret = "{{ config['client_secret'] }}" ,
303
303
token_expiry_date = timestamp ,
304
+ access_token_value = "some_access_token" ,
304
305
refresh_token = "some_refresh_token" ,
305
306
config = {
306
307
"refresh_endpoint" : "refresh_end" ,
@@ -313,6 +314,34 @@ def test_initialize_declarative_oauth_with_token_expiry_date_as_timestamp(
313
314
assert isinstance (oauth ._token_expiry_date , AirbyteDateTime )
314
315
assert oauth .get_token_expiry_date () == ab_datetime_parse (expected_date )
315
316
317
+ def test_given_no_access_token_but_expiry_in_the_future_when_refresh_token_then_fetch_access_token (
318
+ self ,
319
+ ) -> None :
320
+ expiry_date = ab_datetime_now ().add (timedelta (days = 1 ))
321
+ oauth = DeclarativeOauth2Authenticator (
322
+ token_refresh_endpoint = "https://refresh_endpoint.com/" ,
323
+ client_id = "some_client_id" ,
324
+ client_secret = "some_client_secret" ,
325
+ token_expiry_date = expiry_date .isoformat (),
326
+ refresh_token = "some_refresh_token" ,
327
+ config = {},
328
+ parameters = {},
329
+ grant_type = "client" ,
330
+ )
331
+
332
+ with HttpMocker () as http_mocker :
333
+ http_mocker .post (
334
+ HttpRequest (
335
+ url = "https://refresh_endpoint.com/" ,
336
+ body = "grant_type=client&client_id=some_client_id&client_secret=some_client_secret&refresh_token=some_refresh_token" ,
337
+ ),
338
+ HttpResponse (body = json .dumps ({"access_token" : "new_access_token" })),
339
+ )
340
+ oauth .get_access_token ()
341
+
342
+ assert oauth .access_token == "new_access_token"
343
+ assert oauth ._token_expiry_date == expiry_date
344
+
316
345
@pytest .mark .parametrize (
317
346
"expires_in_response, token_expiry_date_format" ,
318
347
[
0 commit comments