@@ -82,52 +82,51 @@ async def test_static_manager(
8282@mark_async_test
8383@pytest .mark .parametrize (("auth1" , "auth2" ),
8484 itertools .product (SAMPLE_AUTHS , repeat = 2 ))
85- @pytest .mark .parametrize ("expires_in " , (None , - 1 , 1. , 1 , 1000. ))
85+ @pytest .mark .parametrize ("expires_at " , (None , .001 , 1 , 1000. ))
8686async def test_expiration_based_manager_manual_expiry (
8787 auth1 : t .Union [t .Tuple [str , str ], Auth , None ],
8888 auth2 : t .Union [t .Tuple [str , str ], Auth , None ],
89- expires_in : t .Union [float , int ],
89+ expires_at : t .Optional [float ],
9090 mocker
9191) -> None :
92- if expires_in is None or expires_in >= 0 :
93- temporal_auth = expiring_auth (auth1 , expires_in )
94- else :
95- temporal_auth = expiring_auth (auth1 )
96- provider = mocker .AsyncMock (return_value = temporal_auth )
97- manager : AsyncAuthManager = expiration_based_auth_manager (provider )
92+ with freeze_time ("1970-01-01 00:00:00" ) as frozen_time :
93+ assert isinstance (frozen_time , FrozenDateTimeFactory )
94+ temporal_auth = expiring_auth (auth1 , expires_at )
95+ provider = mocker .AsyncMock (return_value = temporal_auth )
96+ manager : AsyncAuthManager = expiration_based_auth_manager (provider )
9897
99- provider .assert_not_called ()
100- assert await manager .get_auth () is auth1
101- provider .assert_awaited_once ()
102- provider .reset_mock ()
98+ provider .assert_not_called ()
99+ assert await manager .get_auth () is auth1
100+ provider .assert_awaited_once ()
101+ provider .reset_mock ()
103102
104- provider .return_value = expiring_auth (auth2 )
103+ provider .return_value = expiring_auth (auth2 )
105104
106- await manager .on_auth_expired (("something" , "else" ))
107- assert await manager .get_auth () is auth1
108- provider .assert_not_called ()
105+ await manager .on_auth_expired (("something" , "else" ))
106+ assert await manager .get_auth () is auth1
107+ provider .assert_not_called ()
109108
110- await manager .on_auth_expired (auth1 )
111- provider .assert_awaited_once ()
112- provider .reset_mock ()
113- assert await manager .get_auth () is auth2
114- provider .assert_not_called ()
109+ await manager .on_auth_expired (auth1 )
110+ provider .assert_awaited_once ()
111+ provider .reset_mock ()
112+ assert await manager .get_auth () is auth2
113+ provider .assert_not_called ()
115114
116115
117116@mark_async_test
118117@pytest .mark .parametrize (("auth1" , "auth2" ),
119118 itertools .product (SAMPLE_AUTHS , repeat = 2 ))
120- @pytest .mark .parametrize ("expires_in " , (None , - 1 , 1. , 1 , 1000. ))
119+ @pytest .mark .parametrize ("expires_at " , (None , - 1 , 1. , 1 , 1000. ))
121120async def test_expiration_based_manager_time_expiry (
122121 auth1 : t .Union [t .Tuple [str , str ], Auth , None ],
123122 auth2 : t .Union [t .Tuple [str , str ], Auth , None ],
124- expires_in : t .Union [float , int , None ],
123+ expires_at : t .Optional [float ],
125124 mocker
126125) -> None :
127- with freeze_time () as frozen_time :
126+ with freeze_time ("1970-01-01 00:00:00" ) as frozen_time :
128127 assert isinstance (frozen_time , FrozenDateTimeFactory )
129- if expires_in is None or expires_in >= 0 :
130- temporal_auth = expiring_auth (auth1 , expires_in )
128+ if expires_at is None or expires_at >= 0 :
129+ temporal_auth = expiring_auth (auth1 , expires_at )
131130 else :
132131 temporal_auth = expiring_auth (auth1 )
133132 provider = mocker .AsyncMock (return_value = temporal_auth )
@@ -140,12 +139,12 @@ async def test_expiration_based_manager_time_expiry(
140139
141140 provider .return_value = expiring_auth (auth2 )
142141
143- if expires_in is None or expires_in < 0 :
142+ if expires_at is None or expires_at < 0 :
144143 frozen_time .tick (1_000_000 )
145144 assert await manager .get_auth () is auth1
146145 provider .assert_not_called ()
147146 else :
148- frozen_time .tick (expires_in - 0.000001 )
147+ frozen_time .tick (expires_at - 0.000001 )
149148 assert await manager .get_auth () is auth1
150149 provider .assert_not_called ()
151150 frozen_time .tick (0.000002 )
0 commit comments