8000 test: fix unit tests (#181) · jrmfg/functions-framework-python@abef664 · GitHub
[go: up one dir, main page]

Skip to content

Commit abef664

Browse files
authored
test: fix unit tests (GoogleCloudPlatform#181)
Fix failing assert to look for a different error message, likely due to a change in CloudEvents error message. Also add tests so that code coverage is back at 100%.
1 parent 9046388 commit abef664

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

tests/test_cloud_event_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_unparsable_cloud_event(client):
190190
resp = client.post("/", headers={}, data="")
191191

192192
assert resp.status_code == 400
193-
assert "MissingRequiredFields" in resp.data.decode()
193+
assert "Bad Request" in resp.data.decode()
194194

195195

196196
@pytest.mark.parametrize("specversion", ["0.3", "1.0"])

tests/test_convert.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pathlib
1616

1717
import flask
18+
import pretend
1819
import pytest
1920

2021
from cloudevents.http import from_json, to_binary
@@ -259,6 +260,13 @@ def test_firebase_db_event_to_cloud_event_missing_domain(
259260
)
260261

261262

263+
def test_marshal_background_event_data_bad_request():
264+
req = pretend.stub(headers={}, get_json=lambda: None)
265+
266+
with pytest.raises(EventConversionException):
267+
event_conversion.background_event_to_cloud_event(req)
268+
269+
262270
@pytest.mark.parametrize(
263271
"background_resource",
264272
[

tests/test_view_functions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import json
1515

1616
import pretend
17+
import pytest
18+
import werkzeug
1719

1820
from cloudevents.http import from_http
1921

@@ -63,6 +65,20 @@ def test_event_view_func_wrapper(monkeypatch):
6365
]
6466

6567

68+
def test_event_view_func_wrapper_bad_request(monkeypatch):
69+
request = pretend.stub(headers={}, get_json=lambda: None)
70+
71+
context_stub = pretend.stub()
72+
context_class = pretend.call_recorder(lambda *a, **kw: context_stub)
73+
monkeypatch.setattr(functions_framework, "Context", context_class)
74+
function = pretend.call_recorder(lambda data, context: "Hello")
75+
76+
view_func = functions_framework._event_view_func_wrapper(function, request)
77+
78+
with pytest.raises(werkzeug.exceptions.BadRequest):
79+
view_func("/some/path")
80+
81+
6682
def test_run_cloud_event():
6783
headers = {"Content-Type": "application/cloudevents+json"}
6884
data = json.dumps(

0 commit comments

Comments
 (0)
0