@@ -82,52 +82,51 @@ async def test_static_manager(
82
82
@mark_async_test
83
83
@pytest .mark .parametrize (("auth1" , "auth2" ),
84
84
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. ))
86
86
async def test_expiration_based_manager_manual_expiry (
87
87
auth1 : t .Union [t .Tuple [str , str ], Auth , None ],
88
88
auth2 : t .Union [t .Tuple [str , str ], Auth , None ],
89
- expires_in : t .Union [float , int ],
89
+ expires_at : t .Optional [float ],
90
90
mocker
91
91
) -> 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 )
98
97
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 ()
103
102
104
- provider .return_value = expiring_auth (auth2 )
103
+ provider .return_value = expiring_auth (auth2 )
105
104
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 ()
109
108
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 ()
115
114
116
115
117
116
@mark_async_test
118
117
@pytest .mark .parametrize (("auth1" , "auth2" ),
119
118
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. ))
121
120
async def test_expiration_based_manager_time_expiry (
122
121
auth1 : t .Union [t .Tuple [str , str ], Auth , None ],
123
122
auth2 : t .Union [t .Tuple [str , str ], Auth , None ],
124
- expires_in : t .Union [float , int , None ],
123
+ expires_at : t .Optional [float ],
125
124
mocker
126
125
) -> None :
127
- with freeze_time () as frozen_time :
126
+ with freeze_time ("1970-01-01 00:00:00" ) as frozen_time :
128
127
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 )
131
130
else :
132
131
temporal_auth = expiring_auth (auth1 )
133
132
provider = mocker .AsyncMock (return_value = temporal_auth )
@@ -140,12 +139,12 @@ async def test_expiration_based_manager_time_expiry(
140
139
141
140
provider .return_value = expiring_auth (auth2 )
142
141
143
- if expires_in is None or expires_in < 0 :
142
+ if expires_at is None or expires_at < 0 :
144
143
frozen_time .tick (1_000_000 )
145
144
assert await manager .get_auth () is auth1
146
145
provider .assert_not_called ()
147
146
else :
148
- frozen_time .tick (expires_in - 0.000001 )
147
+ frozen_time .tick (expires_at - 0.000001 )
149
148
assert await manager .get_auth () is auth1
150
149
provider .assert_not_called ()
151
150
frozen_time .tick (0.000002 )
0 commit comments