1
1
# This Source Code Form is subject to the terms of the Mozilla Public
2
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
+ from freezegun import freeze_time
4
5
from time import sleep
5
6
6
7
from functools import partial
28
29
"TestTwoFactorUser" , TestUser ._fields + ("otp_generator" , "backup_codes" )
29
30
)
30
31
31
-
32
- @pytest .fixture
33
- def test_date (monkeypatch ):
34
-
35
- # Adapted from https://stackoverflow.com/questions/20503373/how-to-monkeypatch-pythons-datetime-datetime-now-with-py-test /
36
- TEST_DATE = datetime .datetime (year = 2020 , month = 12 , day = 31 )
37
-
38
- class test_datetime (datetime .datetime ):
39
- @classmethod
40
- def now (cls , * args , ** kwargs ):
41
- return TEST_DATE
42
-
43
- @classmethod
44
- def utcnow (cls , * args , ** kwargs ):
45
- return cls .now ()
46
-
47
- monkeypatch .setattr (datetime , "datetime" , test_datetime )
48
- return TEST_DATE
49
-
50
-
51
- def test_test_date_fixture (test_date ):
52
- assert datetime .datetime .now () == test_date
32
+ #
33
+ # @pytest.fixture
34
+ # def test_date(monkeypatch):
35
+ #
36
+ # # Adapted from https://stackoverflow.com/questions/20503373/how-to-monkeypatch-pythons-datetime-datetime-now-with-py-test /
37
+ # TEST_DATE = datetime.datetime(year=2020, month=12, day=31)
38
+ #
39
+ # class test_datetime(datetime.datetime):
40
+ # @classmethod
41
+ # def now(cls, *args, **kwargs):
42
+ # return TEST_DATE
43
+ #
44
+ # @classmethod
45
+ # def utcnow(cls, *args, **kwargs):
46
+ # return cls.now()
47
+ #
48
+ # monkeypatch.setattr(datetime, "datetime", test_datetime)
49
+ # return TEST_DATE
50
+ #
51
+ #
52
+ # def test_test_date_fixture(test_date):
53
+ # assert datetime.datetime.now() == test_date
54
+ #
53
55
54
56
55
57
@pytest .fixture
56
- def app (tmpdir , test_date ):
58
+ def app (tmpdir ):
57
59
"""Per test app"""
58
60
db_path = tmpdir / "db.db"
59
61
print (f"DB path: { db_path } " )
@@ -156,10 +158,11 @@ def test_two_factor_auth_user(app, get_two_factor_code):
156
158
def test_admin (app ):
157
159
with app .app_context ():
158
160
user = User .query .filter (User .username == app .config ["ADMIN_USER" ]).first ()
159
- return TestUser (user .id , user .username , app .config ["ADMIN_PASSWORD" ])
161
+ return TestUser (user .id , user .username , app .config ["ADMIN_PASSWORD" ])
160
162
161
163
162
164
@pytest .fixture # (scope="session")
165
+ @freeze_time ("2020-12-31" )
163
166
def test_servers (app ):
164
167
with app .app_context ():
165
168
# Add some servers
@@ -173,7 +176,7 @@ def test_servers(app):
173
176
name = "DUMMY_SERVER_B" ,
174
177
longest_token_life_minutes = 2880 ,
175
178
latest_token_expiry = datetime .datetime .now ().date ()
176
- + datetime .timedelta (days = 700 ),
179
+ + datetime .timedelta (days = 365 ),
177
180
)
178
181
db .session .add (dummy_server_a )
179
182
db .session .add (dummy_server_b )
@@ -202,6 +205,7 @@ def test_scopes(app, test_servers):
202
205
203
206
204
207
@pytest .fixture # (scope="session")
208
+ @freeze_time ("2020-12-31" )
205
209
def test_roles (app , test_scopes , test_servers ):
206
210
read_a , read_b , run , dummy_query = test_scopes
207
211
server_a , server_b = test_servers
@@ -237,7 +241,7 @@ def test_user_with_roles(app, test_user, test_roles):
237
241
test_user_orm .roles += [role_a , role_b ]
238
242
db .session .add (test_user_orm )
239
243
db .session .commit ()
240
- return uid , uname , upass
244
+ return uid , uname , upass
241
245
242
246
243
247
@pytest .fixture
0 commit comments