1111import pytest
1212from fastapi .testclient import TestClient
1313
14- from main import app
14+ from src . main import app
1515
1616BASE_DIR = Path (__file__ ).resolve ().parent .parent
1717TEMPLATE_DIR = BASE_DIR / "src" / "templates"
2020@pytest .fixture (scope = "module" )
2121def 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