From 07fa3c5f62f273ef498151ee4c296d4bcbb553e2 Mon Sep 17 00:00:00 2001 From: Arul Date: Tue, 12 May 2026 20:54:19 +0530 Subject: [PATCH] Add tests for OpenAPI callback tutorial --- .../test_tutorial002.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test_tutorial/test_openapi_callbacks/test_tutorial002.py diff --git a/tests/test_tutorial/test_openapi_callbacks/test_tutorial002.py b/tests/test_tutorial/test_openapi_callbacks/test_tutorial002.py new file mode 100644 index 0000000000..51f085fc76 --- /dev/null +++ b/tests/test_tutorial/test_openapi_callbacks/test_tutorial002.py @@ -0,0 +1,40 @@ +from unittest.mock import AsyncMock, patch + +from fastapi.testclient import TestClient + +from docs_src.openapi_callbacks.tutorial002_py310 import app + +client = TestClient(app) + + +@patch("docs_src.openapi_callbacks.tutorial002_py310.httpx.AsyncClient.post") +def test_process_passage(mock_post): + mock_post.return_value = AsyncMock() + + response = client.post( + "/process-passage", + json={ + "passage_topic": "FastAPI tutorial", + "callback_url": "http://testserver/callback", + }, + ) + + assert response.status_code == 200 + assert response.json() == { + "message": "Passage processing started" + } + + +def test_callback(): + response = client.post( + "/callback", + json={ + "processed_passage": "FastAPI tutorial", + "status": "completed", + }, + ) + + assert response.status_code == 200 + assert response.json() == { + "received": True + }