Skip to content

Commit

Permalink
fix incorrect error messages for from_http()
Browse files Browse the repository at this point in the history
add tests

Signed-off-by: XinYang <[email protected]>
  • Loading branch information
xinydev committed Sep 3, 2021
1 parent a5fc827 commit ff51adc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cloudevents/sdk/converters/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

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
"ce-specversion" in headers
or "ce-source" in headers
or "ce-type" in headers
or "ce-id" in headers
)
9 changes: 8 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,14 @@ 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

0 comments on commit ff51adc

Please sign in to comment.