mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-05 02:53:11 +00:00
test(tokens-repo): use assert recent
This commit is contained in:
parent
851d90b30c
commit
6cb9cc6d03
|
@ -37,3 +37,11 @@ def generate_users_query(query_array):
|
||||||
|
|
||||||
def mnemonic_to_hex(mnemonic):
|
def mnemonic_to_hex(mnemonic):
|
||||||
return Mnemonic(language="english").to_entropy(mnemonic).hex()
|
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()
|
||||||
|
)
|
||||||
|
|
|
@ -3,7 +3,13 @@
|
||||||
# pylint: disable=missing-function-docstring
|
# pylint: disable=missing-function-docstring
|
||||||
import datetime
|
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
|
from tests.test_graphql.common import assert_empty, assert_data, assert_ok
|
||||||
|
|
||||||
API_RECOVERY_QUERY = """
|
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
|
assert read_json(tokens_file)["recovery_token"] is not None
|
||||||
time_generated = read_json(tokens_file)["recovery_token"]["date"]
|
time_generated = read_json(tokens_file)["recovery_token"]["date"]
|
||||||
assert time_generated is not None
|
assert time_generated is not None
|
||||||
assert (
|
assert_recovery_recent(time_generated)
|
||||||
datetime.datetime.strptime(time_generated, "%Y-%m-%dT%H:%M:%S.%f")
|
|
||||||
- datetime.timedelta(seconds=5)
|
|
||||||
< datetime.datetime.now()
|
|
||||||
)
|
|
||||||
|
|
||||||
# Try to get token status
|
# Try to get token status
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
|
|
@ -9,6 +9,7 @@ from tests.common import (
|
||||||
RECOVERY_KEY_VALIDATION_DATETIME,
|
RECOVERY_KEY_VALIDATION_DATETIME,
|
||||||
DEVICE_KEY_VALIDATION_DATETIME,
|
DEVICE_KEY_VALIDATION_DATETIME,
|
||||||
NearFuture,
|
NearFuture,
|
||||||
|
assert_recovery_recent,
|
||||||
)
|
)
|
||||||
|
|
||||||
DATE_FORMATS = [
|
DATE_FORMATS = [
|
||||||
|
@ -90,14 +91,6 @@ def rest_get_recovery_date(client):
|
||||||
return status["date"]
|
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):
|
def assert_no_recovery(client):
|
||||||
assert not rest_get_recovery_status(client)["exists"]
|
assert not rest_get_recovery_status(client)["exists"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue