|
15 | 15 | import bz2 |
16 | 16 | import io |
17 | 17 | import json |
| 18 | +import typing |
18 | 19 |
|
19 | 20 | import pytest |
20 | 21 | from sanic import Sanic, response |
@@ -83,7 +84,6 @@ async def echo(request): |
83 | 84 | @pytest.mark.parametrize("body", invalid_cloudevent_request_body) |
84 | 85 | def test_missing_required_fields_structured(body): |
85 | 86 | with pytest.raises(cloud_exceptions.MissingRequiredFields): |
86 | | - |
87 | 87 | _ = from_http( |
88 | 88 | {"Content-Type": "application/cloudevents+json"}, json.dumps(body) |
89 | 89 | ) |
@@ -188,7 +188,6 @@ def test_missing_ce_prefix_binary_event(specversion): |
188 | 188 | "ce-specversion": specversion, |
189 | 189 | } |
190 | 190 | for key in headers: |
191 | | - |
192 | 191 | # breaking prefix e.g. e-id instead of ce-id |
193 | 192 | prefixed_headers[key[1:]] = headers[key] |
194 | 193 |
|
@@ -245,6 +244,25 @@ def test_structured_to_request(specversion): |
245 | 244 | assert body["data"] == data, f"|{body_bytes}|| {body}" |
246 | 245 |
|
247 | 246 |
|
| 247 | +@pytest.mark.parametrize("specversion", ["1.0", "0.3"]) |
| 248 | +def test_attributes_view_accessor(specversion: str): |
| 249 | + attributes: dict[str, typing.Any] = { |
| 250 | + "specversion": specversion, |
| 251 | + "type": "word.found.name", |
| 252 | + "id": "96fb5f0b-001e-0108-6dfe-da6e2806f124", |
| 253 | + "source": "pytest", |
| 254 | + } |
| 255 | + data = {"message": "Hello World!"} |
| 256 | + |
| 257 | + event: CloudEvent = CloudEvent(attributes, data) |
| 258 | + event_attributes: typing.Mapping[str, typing.Any] = event.get_attributes() |
| 259 | + assert event_attributes["specversion"] == attributes["specversion"] |
| 260 | + assert event_attributes["type"] == attributes["type"] |
| 261 | + assert event_attributes["id"] == attributes["id"] |
| 262 | + assert event_attributes["source"] == attributes["source"] |
| 263 | + assert event_attributes["time"] |
| 264 | + |
| 265 | + |
248 | 266 | @pytest.mark.parametrize("specversion", ["1.0", "0.3"]) |
249 | 267 | def test_binary_to_request(specversion): |
250 | 268 | attributes = { |
|
0 commit comments