mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-10 13:03:11 +00:00
Formatting and fix swagger test
This commit is contained in:
parent
ade7c77754
commit
759e90f734
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue