Skip to content
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

fix incorrect error messages for from_http() #143

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions cloudevents/sdk/converters/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def has_binary_headers(headers: typing.Dict[str, str]) -> bool:
return (
"ce-specversion" in headers
and "ce-source" in headers
and "ce-type" in headers
and "ce-id" in headers
or "ce-source" in headers
Copy link
Member

@grant grant Sep 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these headers are required for binary CEs.

or "ce-type" in headers
or "ce-id" in headers
)
12 changes: 11 additions & 1 deletion cloudevents/tests/test_http_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
)
from cloudevents.sdk import converters

required_headers = {"ce-id", "ce-source", "ce-type", "ce-specversion"}

invalid_test_headers = [
{
"ce-source": "<event-source>",
Expand Down Expand Up @@ -96,9 +98,17 @@ def test_missing_required_fields_structured(body):

@pytest.mark.parametrize("headers", invalid_test_headers)
def test_missing_required_fields_binary(headers):
with pytest.raises(cloud_exceptions.MissingRequiredFields):
with pytest.raises(cloud_exceptions.MissingRequiredFields) as e:
_ = from_http(headers, json.dumps(test_data))

if "ce-specversion" not in headers:
assert "Failed to find specversion in HTTP request" == str(e.value)
else:
assert (
f"Missing required attributes: {set(required_headers) - set(headers)}"
== str(e.value)
)


@pytest.mark.parametrize("headers", invalid_test_headers)
def test_missing_required_fields_empty_data_binary(headers):
Expand Down