From 759e90f7342e049dea9df754d2810d965e96c034 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Mon, 17 Jan 2022 13:29:54 +0200 Subject: [PATCH] Formatting and fix swagger test --- selfprivacy_api/resources/api_auth/app_tokens.py | 8 ++++++-- selfprivacy_api/resources/api_auth/recovery_token.py | 4 +++- selfprivacy_api/utils/auth.py | 3 +++ tests/conftest.py | 2 +- tests/test_common.py | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/selfprivacy_api/resources/api_auth/app_tokens.py b/selfprivacy_api/resources/api_auth/app_tokens.py index 36db1ab..f8604d0 100644 --- a/selfprivacy_api/resources/api_auth/app_tokens.py +++ b/selfprivacy_api/resources/api_auth/app_tokens.py @@ -66,10 +66,14 @@ class Tokens(Resource): description: Token not found """ parser = reqparse.RequestParser() - parser.add_argument("token_name", type=str, required=True, help="Token to delete") + parser.add_argument( + "token_name", type=str, required=True, help="Token to delete" + ) args = parser.parse_args() token_name = args["token"] - if is_token_name_pair_valid(token_name, request.headers.get("Authorization").split(" ")[1]): + if is_token_name_pair_valid( + token_name, request.headers.get("Authorization").split(" ")[1] + ): return {"message": "Cannot delete caller's token"}, 400 if not is_token_name_exists(token_name): return {"message": "Token not found"}, 404 diff --git a/selfprivacy_api/resources/api_auth/recovery_token.py b/selfprivacy_api/resources/api_auth/recovery_token.py index a9e6e96..6c81187 100644 --- a/selfprivacy_api/resources/api_auth/recovery_token.py +++ b/selfprivacy_api/resources/api_auth/recovery_token.py @@ -120,7 +120,9 @@ class RecoveryToken(Resource): # Convert expiration date to datetime and return 400 if it is not valid if args["expiration"]: try: - expiration = datetime.strptime(args["expiration"], "%Y-%m-%dT%H:%M:%S.%fZ") + expiration = datetime.strptime( + args["expiration"], "%Y-%m-%dT%H:%M:%S.%fZ" + ) except ValueError: return { "error": "Invalid expiration date. Use YYYY-MM-DDTHH:MM:SS.SSSZ" diff --git a/selfprivacy_api/utils/auth.py b/selfprivacy_api/utils/auth.py index 65d2125..925dfb5 100644 --- a/selfprivacy_api/utils/auth.py +++ b/selfprivacy_api/utils/auth.py @@ -70,11 +70,13 @@ def is_token_valid(token): return True return False + def is_token_name_exists(token_name): """Check if token name exists""" with ReadUserData(UserDataFiles.TOKENS) as tokens: return token_name in [t["name"] for t in tokens["tokens"]] + def is_token_name_pair_valid(token_name, token): """Check if token name and token pair exists""" with ReadUserData(UserDataFiles.TOKENS) as tokens: @@ -83,6 +85,7 @@ def is_token_name_pair_valid(token_name, token): return True return False + def get_tokens_info(): """Get all tokens info without tokens themselves""" with ReadUserData(UserDataFiles.TOKENS) as tokens: diff --git a/tests/conftest.py b/tests/conftest.py index 2dca331..302fdb7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ def app(mocker, shared_datadir): mocker.patch("selfprivacy_api.utils.TOKENS_FILE", shared_datadir / "tokens.json") app = create_app( { - "ENABLE_SWAGGER": "0", + "ENABLE_SWAGGER": "1", } ) diff --git a/tests/test_common.py b/tests/test_common.py index c473956..ecd729c 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -15,6 +15,7 @@ def test_get_api_version_unauthorized(client): assert response.status_code == 200 assert "version" in response.get_json() + def test_get_swagger_json(authorized_client): response = authorized_client.get("/api/swagger.json") assert response.status_code == 200