|
3 | 3 | from httpx import AsyncClient
|
4 | 4 |
|
5 | 5 | from domains.books.entities.cloudevent_base import BaseEvent
|
| 6 | +from domains.books.entities.events import BookCreatedV1 |
6 | 7 |
|
7 | 8 |
|
8 | 9 | class FakeEvent(BaseEvent):
|
@@ -32,3 +33,43 @@ async def test_event_schema_list_returns_data_from_registry(testapp):
|
32 | 33 | response = await ac.get("/events/dataschemas")
|
33 | 34 | assert response.status_code == 200
|
34 | 35 | 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