1
1
import requests
2
2
import os
3
3
4
- from time import sleep
4
+ from time import mktime
5
+ from datetime import datetime
5
6
6
7
from astropy .config import paths
7
8
@@ -146,7 +147,7 @@ def test_login():
146
147
assert not mytest .authenticated () # Should not be accessing cache
147
148
148
149
149
- def test_timeout ():
150
+ def test_timeout (monkeypatch ):
150
151
cache_conf .reset ()
151
152
152
153
mytest = CacheTestClass ()
@@ -155,21 +156,23 @@ def test_timeout():
155
156
mytest .clear_cache ()
156
157
assert len (os .listdir (mytest .cache_location )) == 0
157
158
158
- cache_conf .cache_timeout = 2 # Set to 2 sec so we can reach timeout easily
159
-
160
159
set_response (TEXT1 ) # setting the response
161
160
162
161
resp = mytest .test_func (URL1 ) # should be cached
163
162
assert resp .content == TEXT1
164
163
165
- set_response (TEXT2 ) # changing the respont
164
+ set_response (TEXT2 ) # changing the response
166
165
167
166
resp = mytest .test_func (URL1 ) # should access cached value
168
167
assert resp .content == TEXT1
169
168
170
- sleep (2 ) # run out cache time
169
+ # Changing the file date so the cache will consider it expired
170
+ cache_file = list (mytest .cache_location .iterdir ())[0 ]
171
+ modTime = mktime (datetime (1970 , 1 , 1 ).timetuple ())
172
+ os .utime (cache_file , (modTime , modTime ))
173
+
171
174
resp = mytest .test_func (URL1 )
172
- assert resp .content == TEXT2 # no see the new response
175
+ assert resp .content == TEXT2 # now see the new response
173
176
174
177
175
178
def test_deactivate ():
0 commit comments