test(tokens-repo): travel in time to check expiration

redis/connection-pool
Houkime 2022-12-28 17:09:19 +00:00 committed by Inex Code
parent 458c4fd28a
commit 0bf18603d4
1 changed files with 13 additions and 6 deletions

View File

@ -31,6 +31,9 @@ DATE_FORMATS = [
"%Y-%m-%d %H:%M:%S.%f", "%Y-%m-%d %H:%M:%S.%f",
] ]
# for expiration tests. If headache, consider freezegun
DEVICE_KEY_VALIDATION_DATETIME = "selfprivacy_api.models.tokens.new_device_key.datetime"
def assert_original(filename): def assert_original(filename):
assert read_json(filename) == TOKENS_FILE_CONTETS assert read_json(filename) == TOKENS_FILE_CONTETS
@ -176,15 +179,19 @@ def test_get_and_authorize_used_token(client, authorized_client, tokens_file):
def test_get_and_authorize_token_after_12_minutes( def test_get_and_authorize_token_after_12_minutes(
client, authorized_client, tokens_file client, authorized_client, tokens_file, mocker
): ):
token = rest_get_new_device_token(authorized_client) token = rest_get_new_device_token(authorized_client)
file_data = read_json(tokens_file) # TARDIS sounds
file_data["new_device"]["expiration"] = str( new_time = datetime.datetime.now() + datetime.timedelta(minutes=13)
datetime.datetime.now() - datetime.timedelta(minutes=13)
) class warped_spacetime(datetime.datetime):
write_json(tokens_file, file_data) @classmethod
def now(cls):
return new_time
mock = mocker.patch(DEVICE_KEY_VALIDATION_DATETIME, warped_spacetime)
response = client.post( response = client.post(
"/auth/new_device/authorize", "/auth/new_device/authorize",