@@ -252,8 +252,8 @@ def test_refresh_access_token(self, mocker):
252252 "scopes" : ["no_override" ],
253253 },
254254 )
255-
256- oauth_with_expired_token = Oauth2Authenticator (
255+
256+ oauth_with_expired_token = Oauth2Authenticator (
257257 token_refresh_endpoint = "https://refresh_endpoint.com" ,
258258 client_id = "some_client_id" ,
259259 client_secret = "some_client_secret" ,
@@ -266,7 +266,6 @@ def test_refresh_access_token(self, mocker):
266266 "scopes" : ["no_override" ],
267267 },
268268 )
269-
270269
271270 resp .status_code = 200
272271 mocker .patch .object (
@@ -288,7 +287,7 @@ def test_refresh_access_token(self, mocker):
288287 assert isinstance (expires_in , AirbyteDateTime )
289288 assert expires_in == ab_datetime_now ().add (timedelta (seconds = 2000 ))
290289 assert token == "access_token"
291-
290+
292291 # Test with expires_in as datetime(str)
293292 mocker .patch .object (
294293 resp ,
@@ -298,24 +297,24 @@ def test_refresh_access_token(self, mocker):
298297 # This should raise a ValueError because the token_expiry_is_time_of_expiration is False by default
299298 with pytest .raises (ValueError ):
300299 token , expires_in = oauth .refresh_access_token ()
301-
302- # Test with no expires_in
300+
301+ # Test with no expires_in
303302 mocker .patch .object (
304303 resp ,
305304 "json" ,
306305 return_value = {"access_token" : "access_token" },
307306 )
308-
307+
309308 # Since the initialized token is not expired (now + 3 days), we don't expect the expiration date to be updated
310309 token , expires_in = oauth .refresh_access_token ()
311-
310+
312311 assert isinstance (expires_in , AirbyteDateTime )
313312 assert expires_in == ab_datetime_now ().add (timedelta (days = 3 ))
314313 assert token == "access_token"
315-
314+
316315 # Since the initialized token is expired (now - 3 days), we expect the expiration date to be updated to the default value (now + 1 hour)
317316 token , expires_in = oauth_with_expired_token .refresh_access_token ()
318-
317+
319318 assert isinstance (expires_in , AirbyteDateTime )
320319 assert expires_in == ab_datetime_now ().add (timedelta (hours = 1 ))
321320 assert token == "access_token"
@@ -356,7 +355,7 @@ def test_refresh_access_token(self, mocker):
356355 },
357356 )
358357 token , expires_in = oauth .refresh_access_token ()
359-
358+
360359 assert isinstance (expires_in , AirbyteDateTime )
361360 assert expires_in == ab_datetime_now ().add (timedelta (seconds = 2002 ))
362361 assert token == "access_token_deeply_nested"
@@ -579,6 +578,7 @@ def test_refresh_access_token_wrapped(
579578 assert exc_info .value .message == error_message
580579 assert exc_info .value .failure_type == FailureType .config_error
581580
581+
582582@freezegun .freeze_time ("2022-12-31" )
583583class TestSingleUseRefreshTokenOauth2Authenticator :
584584 @pytest .fixture
@@ -636,14 +636,20 @@ def test_given_no_message_repository_get_access_token(
636636 token_expiry_date_format = expiry_date_format ,
637637 token_expiry_is_time_of_expiration = bool (expiry_date_format ),
638638 )
639-
639+
640640 # Mock the response from the refresh token endpoint
641641 resp .status_code = 200
642642 mocker .patch .object (
643- resp , "json" , return_value = {"access_token" : "new_access_token" , "expires_in" : expires_in_value , "refresh_token" : "new_refresh_token" }
643+ resp ,
644+ "json" ,
645+ return_value = {
646+ authenticator .get_access_token_name (): "new_access_token" ,
647+ authenticator .get_expires_in_name (): expires_in_value ,
648+ authenticator .get_refresh_token_name (): "new_refresh_token" ,
649+ },
644650 )
645651 mocker .patch .object (requests , "request" , side_effect = mock_request , autospec = True )
646-
652+
647653 authenticator .token_has_expired = mocker .Mock (return_value = True )
648654 access_token = authenticator .get_access_token ()
649655 captured = capsys .readouterr ()
@@ -678,10 +684,16 @@ def test_given_message_repository_when_get_access_token_then_emit_message(
678684 # Mock the response from the refresh token endpoint
679685 resp .status_code = 200
680686 mocker .patch .object (
681- resp , "json" , return_value = {"access_token" : "new_access_token" , "expires_in" : "2023-04-04" , "refresh_token" : "new_refresh_token" }
687+ resp ,
688+ "json" ,
689+ return_value = {
690+ authenticator .get_access_token_name (): "new_access_token" ,
691+ authenticator .get_expires_in_name (): "2023-04-04" ,
692+ authenticator .get_refresh_token_name (): "new_refresh_token" ,
693+ },
682694 )
683695 mocker .patch .object (requests , "request" , side_effect = mock_request , autospec = True )
684-
696+
685697 authenticator .token_has_expired = mocker .Mock (return_value = True )
686698
687699 authenticator .get_access_token ()
@@ -746,16 +758,17 @@ def test_refresh_access_token(self, mocker, connector_config):
746758 client_id = connector_config ["credentials" ]["client_id" ],
747759 client_secret = connector_config ["credentials" ]["client_secret" ],
748760 )
749-
761+
750762 # Mock the response from the refresh token endpoint
751763 resp .status_code = 200
752764 mocker .patch .object (
753- resp , "json" ,
765+ resp ,
766+ "json" ,
754767 return_value = {
755768 authenticator .get_access_token_name (): "new_access_token" ,
756769 authenticator .get_expires_in_name (): "42" ,
757770 authenticator .get_refresh_token_name (): "new_refresh_token" ,
758- }
771+ },
759772 )
760773 mocker .patch .object (requests , "request" , side_effect = mock_request , autospec = True )
761774
0 commit comments