2022-06-24 18:14:20 +00:00
|
|
|
import json
|
2023-01-04 16:49:40 +00:00
|
|
|
import datetime
|
2022-06-29 17:39:46 +00:00
|
|
|
from mnemonic import Mnemonic
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2023-01-04 16:49:40 +00:00
|
|
|
# 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)
|
|
|
|
|
2022-07-07 13:53:19 +00:00
|
|
|
|
2022-06-24 18:14:20 +00:00
|
|
|
def read_json(file_path):
|
|
|
|
with open(file_path, "r", encoding="utf-8") as file:
|
|
|
|
return json.load(file)
|
|
|
|
|
|
|
|
|
|
|
|
def write_json(file_path, data):
|
|
|
|
with open(file_path, "w", encoding="utf-8") as file:
|
|
|
|
json.dump(data, file, indent=4)
|
2022-06-29 17:39:46 +00:00
|
|
|
|
2022-07-07 13:53:19 +00:00
|
|
|
|
2022-06-29 17:39:46 +00:00
|
|
|
def generate_api_query(query_array):
|
|
|
|
return "query TestApi {\n api {" + "\n".join(query_array) + "}\n}"
|
|
|
|
|
2022-07-07 13:53:19 +00:00
|
|
|
|
2022-07-05 05:14:37 +00:00
|
|
|
def generate_system_query(query_array):
|
|
|
|
return "query TestSystem {\n system {" + "\n".join(query_array) + "}\n}"
|
|
|
|
|
2022-07-07 13:53:19 +00:00
|
|
|
|
2022-08-01 10:40:40 +00:00
|
|
|
def generate_users_query(query_array):
|
|
|
|
return "query TestUsers {\n users {" + "\n".join(query_array) + "}\n}"
|
|
|
|
|
|
|
|
|
2022-06-29 17:39:46 +00:00
|
|
|
def mnemonic_to_hex(mnemonic):
|
|
|
|
return Mnemonic(language="english").to_entropy(mnemonic).hex()
|
2023-01-06 10:59:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
)
|