Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors test_routes as a separate module #266

Merged
merged 12 commits into from
Jan 10, 2020
2 changes: 1 addition & 1 deletion app/api/routes/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def unauthorized_response():
message = "The email or password you submitted is incorrect " \
"or your account is not allowed api access"
payload = {'errors': {"invalid-credentials": {"message": message}}}
payload = {'errors': {"unauthorized": {"message": message}}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only status code that returns an "invalid-*" response is a 422. For all the rest of the routes, the error is the same as the status, which in the case of 401 is "Unauthorized". I feel this API change is necessary for consistency

return utils.standardize_response(payload=payload, status_code=401)


Expand Down
3 changes: 2 additions & 1 deletion app/api/validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MISSING_BODY = "missing-body"
MISSING_PARAMS = "missing-params"
INVALID_PARAMS = "invalid-params"
INVALID_TYPE = "invalid-type"


def requires_body(func):
Expand Down Expand Up @@ -143,6 +144,6 @@ def wrong_type(type_accepted, type_provided):
}
json_type = types[type_provided]
msg = f"Expected {type_accepted}, but found {json_type}"
validation_errors = {"errors": {"invalid-type": {"message": msg}}}
validation_errors = {"errors": {INVALID_TYPE: {"message": msg}}}

return standardize_response(payload=validation_errors, status_code=422)
8 changes: 4 additions & 4 deletions app/static/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ paths:
apiVersion: '1.0'
data: null
errors:
invalid-credentials:
unauthorized:
message: 'The email or password you submitted is incorrect'
status: 'Unauthorized'
status_code: 401
Expand Down Expand Up @@ -719,7 +719,7 @@ components:
resource:
description: An href link to the resource with a duplicate url
type: string
invalid-credentials:
unauthorized:
type: object
properties:
message:
Expand Down Expand Up @@ -806,7 +806,7 @@ components:
resource:
description: An href link to the resource with a duplicate url
type: string
invalid-credentials:
unauthorized:
type: object
properties:
message:
Expand Down Expand Up @@ -1184,7 +1184,7 @@ components:
'data': null,
'error': 1,
'errors': {
'invalid-credentials': {
'unauthorized': {
'message': 'The email or password you submitted is incorrect'
}
},
Expand Down
2 changes: 1 addition & 1 deletion app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def standardize_response(payload={}, status_code=200, version=LATEST_API_VERSION
elif not data:
# 500 Error case -- Something went wrong.
message = msg_map.get(500)
resp["errors"] = {'errors': {"server-error": {"message": message}}}
resp["errors"] = {"server-error": {"message": message}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing these tests to use a standardized utility function to check the responses was really good, because it caught this issue. A frontend would not have been able to parse correctly

resp["status_code"] = 500
resp["status"] = err_map.get(500)
else:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ prometheus_client==0.7.1
uWSGI==2.0.18
py-healthcheck==1.9.0
bandit==1.5.1

Loading