From 851d90b30c6d0de73c37e44972b698f42d494f7d Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 6 Jan 2023 10:48:59 +0000 Subject: [PATCH] test(tokens-repo): break out getting recovery key --- tests/test_graphql/test_api_recovery.py | 35 ++++++++++++------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/test_graphql/test_api_recovery.py b/tests/test_graphql/test_api_recovery.py index 9e12c0e..dd7d3e4 100644 --- a/tests/test_graphql/test_api_recovery.py +++ b/tests/test_graphql/test_api_recovery.py @@ -4,7 +4,7 @@ import datetime from tests.common import generate_api_query, mnemonic_to_hex, read_json, write_json -from tests.test_graphql.common import assert_empty, assert_data +from tests.test_graphql.common import assert_empty, assert_data, assert_ok API_RECOVERY_QUERY = """ recoveryKey { @@ -33,6 +33,20 @@ def graphql_recovery_status(client): return status +def graphql_get_new_recovery_key(client): + response = client.post( + "/graphql", + json={ + "query": API_RECOVERY_KEY_GENERATE_MUTATION, + }, + ) + assert_ok(response, "getNewRecoveryApiKey") + key = response.json()["data"]["getNewRecoveryApiKey"]["key"] + assert key is not None + assert key.split(" ").__len__() == 18 + return key + + def test_graphql_recovery_key_status_unauthorized(client, tokens_file): response = request_recovery_status(client) assert_empty(response) @@ -71,26 +85,11 @@ mutation TestUseRecoveryKey($input: UseRecoveryKeyInput!) { def test_graphql_generate_recovery_key(client, authorized_client, tokens_file): - response = authorized_client.post( - "/graphql", - json={ - "query": API_RECOVERY_KEY_GENERATE_MUTATION, - }, - ) - assert response.status_code == 200 - assert response.json().get("data") is not None - assert response.json()["data"]["getNewRecoveryApiKey"]["success"] is True - assert response.json()["data"]["getNewRecoveryApiKey"]["message"] is not None - assert response.json()["data"]["getNewRecoveryApiKey"]["code"] == 200 - assert response.json()["data"]["getNewRecoveryApiKey"]["key"] is not None - assert ( - response.json()["data"]["getNewRecoveryApiKey"]["key"].split(" ").__len__() - == 18 - ) + key = graphql_get_new_recovery_key(authorized_client) + 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 - key = response.json()["data"]["getNewRecoveryApiKey"]["key"] assert ( datetime.datetime.strptime(time_generated, "%Y-%m-%dT%H:%M:%S.%f") - datetime.timedelta(seconds=5)