Skip to content

Commit a04f031

Browse files
committed
Test the event input endpoint
1 parent 38d5635 commit a04f031

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/http_app/routes/test_events.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from httpx import AsyncClient
44

55
from domains.books.entities.cloudevent_base import BaseEvent
6+
from domains.books.entities.events import BookCreatedV1
67

78

89
class FakeEvent(BaseEvent):
@@ -32,3 +33,43 @@ async def test_event_schema_list_returns_data_from_registry(testapp):
3233
response = await ac.get("/events/dataschemas")
3334
assert response.status_code == 200
3435
assert response.json() == ["test_event"]
36+
37+
38+
async def test_event_returns_204(testapp):
39+
fake_event = BookCreatedV1(
40+
data={"book_id": 0, "title": "string", "author_name": "string"},
41+
)
42+
async with AsyncClient(app=testapp, base_url="http://test") as ac:
43+
response = await ac.post(
44+
"/events/",
45+
headers={"content-type": "application/cloudevents+json; charset=UTF-8"},
46+
content=fake_event.model_dump_json(),
47+
)
48+
assert response.status_code == 204
49+
50+
51+
async def test_malformed_event_returns_422(testapp):
52+
fake_event = BookCreatedV1(
53+
data={"book_id": 0, "title": "string", "author_name": "string"},
54+
)
55+
fake_event.dataschema = None
56+
async with AsyncClient(app=testapp, base_url="http://test") as ac:
57+
response = await ac.post(
58+
"/events/",
59+
headers={"content-type": "application/cloudevents+json; charset=UTF-8"},
60+
content=fake_event.model_dump_json(),
61+
)
62+
assert response.status_code == 422
63+
64+
65+
async def test_wrong_content_type_returns_422(testapp):
66+
fake_event = BookCreatedV1(
67+
data={"book_id": 0, "title": "string", "author_name": "string"},
68+
)
69+
async with AsyncClient(app=testapp, base_url="http://test") as ac:
70+
response = await ac.post(
71+
"/events/",
72+
headers={"content-type": "application/json"},
73+
content=fake_event.model_dump_json(),
74+
)
75+
assert response.status_code == 422

0 commit comments

Comments
 (0)