Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fastapi/fastapi_installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 3 additions & 31 deletions src/fastapi/test_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}}")
Expand All @@ -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"
"#
)
}
Expand Down
Loading