diff --git a/tests/test_duplicate_operation_id.py b/tests/test_duplicate_operation_id.py index 437311ec57..f7d02249d4 100644 --- a/tests/test_duplicate_operation_id.py +++ b/tests/test_duplicate_operation_id.py @@ -1,4 +1,5 @@ """Test for fix of issue #13175: duplicate operation IDs with multi-method routes""" + from fastapi import FastAPI from fastapi.testclient import TestClient @@ -14,37 +15,37 @@ def test_no_duplicate_operation_ids_with_multiple_methods(): client = TestClient(app) response = client.get("/openapi.json") assert response.status_code == 200 - + data = response.json() - + # Check that all three methods exist in the OpenAPI schema paths = data.get("paths", {}) items_path = paths.get("/items/", {}) - + assert "get" in items_path assert "post" in items_path assert "delete" in items_path - + # Verify each method has a unique operation ID get_op_id = items_path["get"].get("operationId") post_op_id = items_path["post"].get("operationId") delete_op_id = items_path["delete"].get("operationId") - + # All should exist assert get_op_id is not None assert post_op_id is not None assert delete_op_id is not None - + # All should be different assert get_op_id != post_op_id assert get_op_id != delete_op_id assert post_op_id != delete_op_id - + # Verify they follow the pattern: __ assert "handle_items_items_" in get_op_id assert "handle_items_items_" in post_op_id assert "handle_items_items_" in delete_op_id - + assert "_get" in get_op_id assert "_post" in post_op_id assert "_delete" in delete_op_id @@ -53,4 +54,3 @@ def test_no_duplicate_operation_ids_with_multiple_methods(): if __name__ == "__main__": test_no_duplicate_operation_ids_with_multiple_methods() print("✓ Test passed!") -