diff --git a/src/fastapi/fastapi_installer.rs b/src/fastapi/fastapi_installer.rs index 8b50a444..f90ac60b 100644 --- a/src/fastapi/fastapi_installer.rs +++ b/src/fastapi/fastapi_installer.rs @@ -19,7 +19,7 @@ const FASTAPI_BASE_DEPENDENCIES: &[&str] = &[ "valkey", ]; -const FASTAPI_BASE_DEV_DEPENDENCIES: &[&str] = &["httpx", "pytest-xdist"]; +const FASTAPI_BASE_DEV_DEPENDENCIES: &[&str] = &["httpx2", "pytest-xdist"]; pub fn install_fastapi_dependencies(project_info: &ProjectInfo) -> Result<()> { match project_info.project_manager { diff --git a/src/fastapi/test_files.rs b/src/fastapi/test_files.rs index 849cf72b..3aa7e0cc 100644 --- a/src/fastapi/test_files.rs +++ b/src/fastapi/test_files.rs @@ -182,7 +182,7 @@ from uuid import uuid4 import asyncpg import pytest -from httpx import ASGITransport, AsyncClient +from httpx2 import ASGITransport, AsyncClient from {module}.api.deps import get_cache_client, get_db_pool from {module}.core.cache import cache @@ -395,7 +395,7 @@ fn create_health_route_test_file(project_info: &ProjectInfo) -> String { r#"from unittest.mock import AsyncMock, MagicMock import pytest -from httpx import ASGITransport, AsyncClient +from httpx2 import ASGITransport, AsyncClient from {module}.api.deps import get_cache_client, get_db_pool from {module}.core.config import settings @@ -1383,15 +1383,10 @@ fn create_main_test_file(project_info: &ProjectInfo) -> String { let module = &project_info.module_name(); format!( - r#"import importlib -from unittest.mock import patch + r#"from unittest.mock import patch -from fastapi.testclient import TestClient from loguru import logger -from {module} import main -from {module}.core.config import settings - async def test_http_exception_handler(test_client, normal_user_token_headers, caplog): logger.add(caplog.handler, level="ERROR", format="{{message}}") @@ -1404,29 +1399,6 @@ async def test_http_exception_handler(test_client, normal_user_token_headers, ca assert response.status_code == 500 assert "Server crashed" in caplog.text - - -def test_cors_middleware_added(test_client): - with patch.object( - type(settings), - "all_cors_origins", - new=property(lambda _: ["https://example.com"]), - ): - importlib.reload(main) - app = main.app - client = TestClient(app) - - resp = client.options( - "/", - headers={{ - "Origin": "https://example.com", - "Access-Control-Request-Method": "GET", - "Access-Control-Request-Headers": "Authorization, Content-Type", - }}, - ) - - assert resp.status_code == 200 - assert resp.headers.get("access-control-allow-origin") == "https://example.com" "# ) }