Skip to content

Commit c19a379

Browse files
committed
fix: Correct static directory path for StaticFiles mount
1 parent 26fc51e commit c19a379

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ async def rate_limit_exception_handler(request: Request, exc: Exception) -> Resp
156156
app.add_exception_handler(RateLimitExceeded, rate_limit_exception_handler)
157157

158158
# Mount static files to serve CSS, JS, and other static assets
159-
app.mount("/static", StaticFiles(directory="src/static"), name="static")
159+
# Mount static files dynamically
160+
static_dir = Path(__file__).parent / "static"
161+
if static_dir.exists():
162+
app.mount("/static", StaticFiles(directory=static_dir), name="static")
163+
else:
164+
print(f"Warning: Static directory '{static_dir}' does not exist. Skipping static file mount.")
160165

161166
# Set up API analytics middleware if an API key is provided
162167
if app_analytics_key := os.getenv("API_ANALYTICS_KEY"):
@@ -175,7 +180,7 @@ async def rate_limit_exception_handler(request: Request, exc: Exception) -> Resp
175180
app.add_middleware(TrustedHostMiddleware, allowed_hosts=allowed_hosts)
176181

177182
# Set up template rendering
178-
templates = Jinja2Templates(directory="src/templates")
183+
templates = Jinja2Templates(directory="templates")
179184

180185

181186
@app.get("/health")

tests/test_flow_integration.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212
from fastapi.testclient import TestClient
1313

14-
from main import app
14+
from src.main import app
1515

1616
BASE_DIR = Path(__file__).resolve().parent.parent
1717
TEMPLATE_DIR = BASE_DIR / "src" / "templates"
@@ -20,9 +20,16 @@
2020
@pytest.fixture(scope="module")
2121
def test_client():
2222
"""Create a test client fixture."""
23-
with TestClient(app) as client:
24-
client.headers.update({"Host": "localhost"})
25-
yield client
23+
with TestClient(app) as client_instance:
24+
client_instance.headers.update({"Host": "localhost"})
25+
yield client_instance
26+
27+
28+
@pytest.fixture(scope="module", autouse=True)
29+
def mock_static_files():
30+
"""Mock the static file mount to avoid directory errors."""
31+
with patch("src.main.StaticFiles") as mock_static:
32+
yield mock_static
2633

2734

2835
@pytest.fixture(scope="module", autouse=True)
@@ -50,53 +57,57 @@ def cleanup():
5057

5158

5259
@pytest.mark.asyncio
53-
async def test_remote_repository_analysis(test_client): # pylint: disable=redefined-outer-name
60+
async def test_remote_repository_analysis(request):
5461
"""Test the complete flow of analyzing a remote repository."""
62+
client = request.getfixturevalue("test_client")
5563
form_data = {
5664
"input_text": "https://github.com/octocat/Hello-World",
5765
"max_file_size": "243",
5866
"pattern_type": "exclude",
5967
"pattern": "",
6068
}
6169

62-
response = test_client.post("/", data=form_data)
70+
response = client.post("/", data=form_data)
6371
assert response.status_code == 200, f"Form submission failed: {response.text}"
6472
assert "Mocked Template Response" in response.text
6573

6674

6775
@pytest.mark.asyncio
68-
async def test_invalid_repository_url(test_client): # pylint: disable=redefined-outer-name
76+
async def test_invalid_repository_url(request):
6977
"""Test handling of an invalid repository URL."""
78+
client = request.getfixturevalue("test_client")
7079
form_data = {
7180
"input_text": "https://github.com/nonexistent/repo",
7281
"max_file_size": "243",
7382
"pattern_type": "exclude",
7483
"pattern": "",
7584
}
7685

77-
response = test_client.post("/", data=form_data)
86+
response = client.post("/", data=form_data)
7887
assert response.status_code == 200, f"Request failed: {response.text}"
7988
assert "Mocked Template Response" in response.text
8089

8190

8291
@pytest.mark.asyncio
83-
async def test_large_repository(test_client): # pylint: disable=redefined-outer-name
92+
async def test_large_repository(request):
8493
"""Simulate analysis of a large repository with nested folders."""
94+
client = request.getfixturevalue("test_client")
8595
form_data = {
8696
"input_text": "https://github.com/large/repo-with-many-files",
8797
"max_file_size": "243",
8898
"pattern_type": "exclude",
8999
"pattern": "",
90100
}
91101

92-
response = test_client.post("/", data=form_data)
102+
response = client.post("/", data=form_data)
93103
assert response.status_code == 200, f"Request failed: {response.text}"
94104
assert "Mocked Template Response" in response.text
95105

96106

97107
@pytest.mark.asyncio
98-
async def test_concurrent_requests(test_client): # pylint: disable=redefined-outer-name
108+
async def test_concurrent_requests(request):
99109
"""Test handling of multiple concurrent requests."""
110+
client = request.getfixturevalue("test_client")
100111

101112
def make_request():
102113
form_data = {
@@ -105,7 +116,7 @@ def make_request():
105116
"pattern_type": "exclude",
106117
"pattern": "",
107118
}
108-
response = test_client.post("/", data=form_data)
119+
response = client.post("/", data=form_data)
109120
assert response.status_code == 200, f"Request failed: {response.text}"
110121
assert "Mocked Template Response" in response.text
111122

@@ -116,30 +127,32 @@ def make_request():
116127

117128

118129
@pytest.mark.asyncio
119-
async def test_large_file_handling(test_client): # pylint: disable=redefined-outer-name
130+
async def test_large_file_handling(request):
120131
"""Test handling of repositories with large files."""
132+
client = request.getfixturevalue("test_client")
121133
form_data = {
122134
"input_text": "https://github.com/octocat/Hello-World",
123135
"max_file_size": "1",
124136
"pattern_type": "exclude",
125137
"pattern": "",
126138
}
127139

128-
response = test_client.post("/", data=form_data)
140+
response = client.post("/", data=form_data)
129141
assert response.status_code == 200, f"Request failed: {response.text}"
130142
assert "Mocked Template Response" in response.text
131143

132144

133145
@pytest.mark.asyncio
134-
async def test_repository_with_patterns(test_client): # pylint: disable=redefined-outer-name
146+
async def test_repository_with_patterns(request):
135147
"""Test repository analysis with include/exclude patterns."""
148+
client = request.getfixturevalue("test_client")
136149
form_data = {
137150
"input_text": "https://github.com/octocat/Hello-World",
138151
"max_file_size": "243",
139152
"pattern_type": "include",
140153
"pattern": "*.md",
141154
}
142155

143-
response = test_client.post("/", data=form_data)
156+
response = client.post("/", data=form_data)
144157
assert response.status_code == 200, f"Request failed: {response.text}"
145158
assert "Mocked Template Response" in response.text

0 commit comments

Comments
 (0)