diff --git a/tests/test_cloud_event_functions.py b/tests/test_cloud_event_functions.py index 4ad8a527..a673c6e4 100644 --- a/tests/test_cloud_event_functions.py +++ b/tests/test_cloud_event_functions.py @@ -190,7 +190,7 @@ def test_unparsable_cloud_event(client): resp = client.post("/", headers={}, data="") assert resp.status_code == 400 - assert "MissingRequiredFields" in resp.data.decode() + assert "Bad Request" in resp.data.decode() @pytest.mark.parametrize("specversion", ["0.3", "1.0"]) diff --git a/tests/test_convert.py b/tests/test_convert.py index 9202f567..0d41d5ed 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -15,6 +15,7 @@ import pathlib import flask +import pretend import pytest from cloudevents.http import from_json, to_binary @@ -259,6 +260,13 @@ def test_firebase_db_event_to_cloud_event_missing_domain( ) +def test_marshal_background_event_data_bad_request(): + req = pretend.stub(headers={}, get_json=lambda: None) + + with pytest.raises(EventConversionException): + event_conversion.background_event_to_cloud_event(req) + + @pytest.mark.parametrize( "background_resource", [ diff --git a/tests/test_view_functions.py b/tests/test_view_functions.py index 219313f9..8de543d1 100644 --- a/tests/test_view_functions.py +++ b/tests/test_view_functions.py @@ -14,6 +14,8 @@ import json import pretend +import pytest +import werkzeug from cloudevents.http import from_http @@ -63,6 +65,20 @@ def test_event_view_func_wrapper(monkeypatch): ] +def test_event_view_func_wrapper_bad_request(monkeypatch): + request = pretend.stub(headers={}, get_json=lambda: None) + + context_stub = pretend.stub() + context_class = pretend.call_recorder(lambda *a, **kw: context_stub) + monkeypatch.setattr(functions_framework, "Context", context_class) + function = pretend.call_recorder(lambda data, context: "Hello") + + view_func = functions_framework._event_view_func_wrapper(function, request) + + with pytest.raises(werkzeug.exceptions.BadRequest): + view_func("/some/path") + + def test_run_cloud_event(): headers = {"Content-Type": "application/cloudevents+json"} data = json.dumps(