Skip to content

test: fix unit tests #181

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

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_cloud_event_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
8 changes: 8 additions & 0 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pathlib

import flask
import pretend
import pytest

from cloudevents.http import from_json, to_binary
Expand Down Expand Up @@ -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",
[
Expand Down
16 changes: 16 additions & 0 deletions tests/test_view_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import json

import pretend
import pytest
import werkzeug

from cloudevents.http import from_http

Expand Down Expand Up @@ -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(
Expand Down