diff options
| author | Tom Harley | 2021-07-09 15:16:54 +0000 |
|---|---|---|
| committer | Tom Harley | 2021-07-09 15:16:54 +0000 |
| commit | 57e7488149ee093e34774d83ffe161fb305a7dde (patch) | |
| tree | ed922a052cd8eb6fc5b77c21970cb0d0b02b9cb3 /tests/test_auth.py | |
| parent | Add testing for authorisation decorators (diff) | |
| download | swap-57e7488149ee093e34774d83ffe161fb305a7dde.tar.gz swap-57e7488149ee093e34774d83ffe161fb305a7dde.zip | |
Add basic inbox/outbox functionality
Lots of added TODOs, and very little test coverage for the new functions.
Next step is to get 100% coverage of what we have so far.
Diffstat (limited to 'tests/test_auth.py')
| -rw-r--r-- | tests/test_auth.py | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py index 4e28e93..c96d14f 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,9 +1,9 @@ import pytest -from flask import g, session, json, url_for +from flask import g, session, json, url_for, request from sw.db import get_db -from sw.auth import login_required, specific_user_required +from sw.auth import login_required, specific_user_required, json_input from werkzeug.datastructures import Headers @@ -126,3 +126,43 @@ def test_specific_user_required_right_user(client, app, auth): assert response.status_code == 200 assert b"Should succeed" in response.data + + +@pytest.mark.parametrize( + ("input_data", "content_type", "expected_response"), + ( + (None, None, 422), + ("", None, 422), + ("invalid JSON string", None, 422), + ('{ "valid": "JSON"}', None, 422), + (None, "", 422), + ("", "", 422), + ("invalid JSON string", "", 422), + ('{ "valid": "JSON"}', "", 422), + (None, "application/json", 400), + ("", "application/json", 400), + ("invalid JSON string", "application/json", 400), + ('{ "valid": "JSON"}', "application/json", 201), + (None, "application/ld+json", 400), + ("", "application/ld+json", 400), + ("invalid JSON string", "application/ld+json", 400), + ('{ "valid": "JSON"}', "application/ld+json", 201), + ), +) +def test_json_input_empty_input( + client, app, input_data, content_type, expected_response +): + test_endpoint = "/test/dummy_endpoint" + + @app.route(test_endpoint, methods=["POST"]) + @json_input + def dummy_endpoint(): + data = request.json + return data, 201 + + with client: + response = client.post( + test_endpoint, data=input_data, headers={"Content-Type": content_type} + ) + + assert response.status_code == expected_response |
