diff options
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 |
