From 6cb9cc6d03d8d71d83c6f4bfdb138a406904b364 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 6 Jan 2023 10:59:59 +0000 Subject: [PATCH] test(tokens-repo): use assert recent --- tests/common.py | 8 ++++++++ tests/test_graphql/test_api_recovery.py | 15 ++++++++------- tests/test_rest_endpoints/test_auth.py | 9 +-------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/common.py b/tests/common.py index 95488cc..a49885a 100644 --- a/tests/common.py +++ b/tests/common.py @@ -37,3 +37,11 @@ def generate_users_query(query_array): def mnemonic_to_hex(mnemonic): return Mnemonic(language="english").to_entropy(mnemonic).hex() + + +def assert_recovery_recent(time_generated): + assert ( + datetime.datetime.strptime(time_generated, "%Y-%m-%dT%H:%M:%S.%f") + - datetime.timedelta(seconds=5) + < datetime.datetime.now() + ) diff --git a/tests/test_graphql/test_api_recovery.py b/tests/test_graphql/test_api_recovery.py index dd7d3e4..2f97513 100644 --- a/tests/test_graphql/test_api_recovery.py +++ b/tests/test_graphql/test_api_recovery.py @@ -3,7 +3,13 @@ # pylint: disable=missing-function-docstring import datetime -from tests.common import generate_api_query, mnemonic_to_hex, read_json, write_json +from tests.common import ( + generate_api_query, + mnemonic_to_hex, + read_json, + write_json, + assert_recovery_recent, +) from tests.test_graphql.common import assert_empty, assert_data, assert_ok API_RECOVERY_QUERY = """ @@ -90,12 +96,7 @@ def test_graphql_generate_recovery_key(client, authorized_client, tokens_file): assert read_json(tokens_file)["recovery_token"] is not None time_generated = read_json(tokens_file)["recovery_token"]["date"] assert time_generated is not None - assert ( - datetime.datetime.strptime(time_generated, "%Y-%m-%dT%H:%M:%S.%f") - - datetime.timedelta(seconds=5) - < datetime.datetime.now() - ) - + assert_recovery_recent(time_generated) # Try to get token status response = authorized_client.post( "/graphql", diff --git a/tests/test_rest_endpoints/test_auth.py b/tests/test_rest_endpoints/test_auth.py index 1632e22..ff161fb 100644 --- a/tests/test_rest_endpoints/test_auth.py +++ b/tests/test_rest_endpoints/test_auth.py @@ -9,6 +9,7 @@ from tests.common import ( RECOVERY_KEY_VALIDATION_DATETIME, DEVICE_KEY_VALIDATION_DATETIME, NearFuture, + assert_recovery_recent, ) DATE_FORMATS = [ @@ -90,14 +91,6 @@ def rest_get_recovery_date(client): return status["date"] -def assert_recovery_recent(time_generated): - assert ( - datetime.datetime.strptime(time_generated, "%Y-%m-%dT%H:%M:%S.%f") - - datetime.timedelta(seconds=5) - < datetime.datetime.now() - ) - - def assert_no_recovery(client): assert not rest_get_recovery_status(client)["exists"]