test(tokens-repo): move timewarping to test commons

This commit is contained in:
Houkime 2023-01-04 16:49:40 +00:00 committed by Inex Code
parent 0aaa90f54a
commit f5faf84a2b
2 changed files with 16 additions and 10 deletions

View file

@ -1,6 +1,17 @@
import json import json
import datetime
from mnemonic import Mnemonic from mnemonic import Mnemonic
# for expiration tests. If headache, consider freezegun
RECOVERY_KEY_VALIDATION_DATETIME = "selfprivacy_api.models.tokens.recovery_key.datetime"
DEVICE_KEY_VALIDATION_DATETIME = "selfprivacy_api.models.tokens.new_device_key.datetime"
class NearFuture(datetime.datetime):
@classmethod
def now(cls):
return datetime.datetime.now() + datetime.timedelta(minutes=13)
def read_json(file_path): def read_json(file_path):
with open(file_path, "r", encoding="utf-8") as file: with open(file_path, "r", encoding="utf-8") as file:

View file

@ -5,6 +5,11 @@ import datetime
import pytest import pytest
from tests.conftest import TOKENS_FILE_CONTENTS from tests.conftest import TOKENS_FILE_CONTENTS
from tests.common import (
RECOVERY_KEY_VALIDATION_DATETIME,
DEVICE_KEY_VALIDATION_DATETIME,
NearFuture,
)
DATE_FORMATS = [ DATE_FORMATS = [
"%Y-%m-%dT%H:%M:%S.%fZ", "%Y-%m-%dT%H:%M:%S.%fZ",
@ -13,16 +18,6 @@ DATE_FORMATS = [
"%Y-%m-%d %H:%M:%S.%f", "%Y-%m-%d %H:%M:%S.%f",
] ]
# for expiration tests. If headache, consider freezegun
RECOVERY_KEY_VALIDATION_DATETIME = "selfprivacy_api.models.tokens.recovery_key.datetime"
DEVICE_KEY_VALIDATION_DATETIME = "selfprivacy_api.models.tokens.new_device_key.datetime"
class NearFuture(datetime.datetime):
@classmethod
def now(cls):
return datetime.datetime.now() + datetime.timedelta(minutes=13)
def assert_original(client): def assert_original(client):
new_tokens = rest_get_tokens_info(client) new_tokens = rest_get_tokens_info(client)