1212from starlette .routing import Mount
1313
1414from ellar .core import AppFactory , TestClient
15- from ellar .core .staticfiles import StarletteStaticFiles
15+ from ellar .core .staticfiles import StaticFiles
1616
1717
1818def test_staticfiles (tmpdir ):
1919 path = os .path .join (tmpdir , "example.txt" )
2020 with open (path , "w" ) as file :
2121 file .write ("<file content>" )
2222
23- app = StarletteStaticFiles (directories = [tmpdir ])
23+ app = StaticFiles (directories = [tmpdir ])
2424 client = TestClient (app )
2525 response = client .get ("/example.txt" )
2626 assert response .status_code == 200
@@ -33,7 +33,7 @@ def test_staticfiles_with_pathlib(tmpdir):
3333 with open (path , "w" ) as file :
3434 file .write ("<file content>" )
3535
36- app = StarletteStaticFiles (directories = [base_dir ])
36+ app = StaticFiles (directories = [base_dir ])
3737 client = TestClient (app )
3838 response = client .get ("/example.txt" )
3939 assert response .status_code == 200
@@ -45,9 +45,7 @@ def test_staticfiles_head_with_middleware(tmpdir):
4545 with open (path , "w" ) as file :
4646 file .write ("x" * 100 )
4747
48- routers = [
49- Mount ("/static" , app = StarletteStaticFiles (directories = [tmpdir ]), name = "static" )
50- ]
48+ routers = [Mount ("/static" , app = StaticFiles (directories = [tmpdir ]), name = "static" )]
5149 app = AppFactory .create_app (routers = routers )
5250
5351 client = TestClient (app )
@@ -57,13 +55,13 @@ def test_staticfiles_head_with_middleware(tmpdir):
5755
5856
5957def test_staticfiles_with_package ():
60- app = StarletteStaticFiles (packages = ["tests" ])
58+ app = StaticFiles (packages = ["tests" ])
6159 client = TestClient (app )
6260 response = client .get ("/example.txt" )
6361 assert response .status_code == 200
6462 assert response .text == "123\n "
6563
66- app = StarletteStaticFiles (packages = [("tests" , "statics" )])
64+ app = StaticFiles (packages = [("tests" , "statics" )])
6765 client = TestClient (app )
6866 response = client .get ("/example.txt" )
6967 assert response .status_code == 200
@@ -75,9 +73,7 @@ def test_staticfiles_post(tmpdir):
7573 with open (path , "w" ) as file :
7674 file .write ("<file content>" )
7775
78- routers = [
79- Mount ("/" , app = StarletteStaticFiles (directories = [tmpdir ]), name = "static" )
80- ]
76+ routers = [Mount ("/" , app = StaticFiles (directories = [tmpdir ]), name = "static" )]
8177 app = AppFactory .create_app (routers = routers )
8278 client = TestClient (app )
8379
@@ -91,9 +87,7 @@ def test_staticfiles_with_directory_returns_404(tmpdir):
9187 with open (path , "w" ) as file :
9288 file .write ("<file content>" )
9389
94- routers = [
95- Mount ("/" , app = StarletteStaticFiles (directories = [tmpdir ]), name = "static" )
96- ]
90+ routers = [Mount ("/" , app = StaticFiles (directories = [tmpdir ]), name = "static" )]
9791 app = AppFactory .create_app (routers = routers )
9892 client = TestClient (app )
9993
@@ -107,9 +101,7 @@ def test_staticfiles_with_missing_file_returns_404(tmpdir):
107101 with open (path , "w" ) as file :
108102 file .write ("<file content>" )
109103
110- routers = [
111- Mount ("/" , app = StarletteStaticFiles (directories = [tmpdir ]), name = "static" )
112- ]
104+ routers = [Mount ("/" , app = StaticFiles (directories = [tmpdir ]), name = "static" )]
113105 app = AppFactory .create_app (routers = routers )
114106 client = TestClient (app )
115107
@@ -121,13 +113,13 @@ def test_staticfiles_with_missing_file_returns_404(tmpdir):
121113def test_staticfiles_instantiated_with_missing_directory (tmpdir ):
122114 with pytest .raises (RuntimeError ) as exc_info :
123115 path = os .path .join (tmpdir , "no_such_directory" )
124- StarletteStaticFiles (directories = [path ])
116+ StaticFiles (directories = [path ])
125117 assert "does not exist" in str (exc_info .value )
126118
127119
128120def test_staticfiles_configured_with_missing_directory (tmpdir ):
129121 path = os .path .join (tmpdir , "no_such_directory" )
130- app = StarletteStaticFiles (directories = [path ], check_dir = False )
122+ app = StaticFiles (directories = [path ], check_dir = False )
131123 client = TestClient (app )
132124 with pytest .raises (RuntimeError ) as exc_info :
133125 client .get ("/example.txt" )
@@ -139,15 +131,15 @@ def test_staticfiles_configured_with_file_instead_of_directory(tmpdir):
139131 with open (path , "w" ) as file :
140132 file .write ("<file content>" )
141133
142- app = StarletteStaticFiles (directories = [path ], check_dir = False )
134+ app = StaticFiles (directories = [path ], check_dir = False )
143135 client = TestClient (app )
144136 with pytest .raises (RuntimeError ) as exc_info :
145137 client .get ("/example.txt" )
146138 assert "is not a directory" in str (exc_info .value )
147139
148140
149141def test_staticfiles_config_check_occurs_only_once (tmpdir ):
150- app = StarletteStaticFiles (directories = [tmpdir ])
142+ app = StaticFiles (directories = [tmpdir ])
151143 client = TestClient (app )
152144 assert not app .config_checked
153145
@@ -168,7 +160,7 @@ def test_staticfiles_prevents_breaking_out_of_directory(tmpdir):
168160 with open (path , "w" ) as file :
169161 file .write ("outside root dir" )
170162
171- app = StarletteStaticFiles (directories = [directory ])
163+ app = StaticFiles (directories = [directory ])
172164 # We can't test this with 'requests', so we test the app directly here.
173165 path = app .get_path ({"path" : "/../example.txt" })
174166 scope = {"method" : "GET" }
@@ -185,7 +177,7 @@ def test_staticfiles_never_read_file_for_head_method(tmpdir):
185177 with open (path , "w" ) as file :
186178 file .write ("<file content>" )
187179
188- app = StarletteStaticFiles (directories = [tmpdir ])
180+ app = StaticFiles (directories = [tmpdir ])
189181 client = TestClient (app )
190182 response = client .head ("/example.txt" )
191183 assert response .status_code == 200
@@ -198,7 +190,7 @@ def test_staticfiles_304_with_etag_match(tmpdir):
198190 with open (path , "w" ) as file :
199191 file .write ("<file content>" )
200192
201- app = StarletteStaticFiles (directories = [tmpdir ])
193+ app = StaticFiles (directories = [tmpdir ])
202194 client = TestClient (app )
203195 first_resp = client .get ("/example.txt" )
204196 assert first_resp .status_code == 200
@@ -217,7 +209,7 @@ def test_staticfiles_304_with_last_modified_compare_last_req(tmpdir):
217209 file .write ("<file content>" )
218210 os .utime (path , (file_last_modified_time , file_last_modified_time ))
219211
220- app = StarletteStaticFiles (directories = [tmpdir ])
212+ app = StaticFiles (directories = [tmpdir ])
221213 client = TestClient (app )
222214 # last modified less than last request, 304
223215 response = client .get (
@@ -243,7 +235,7 @@ def test_staticfiles_html_normal(tmpdir):
243235 with open (path , "w" ) as file :
244236 file .write ("<h1>Hello</h1>" )
245237
246- app = StarletteStaticFiles (directories = [tmpdir ], html = True )
238+ app = StaticFiles (directories = [tmpdir ], html = True )
247239 client = TestClient (app )
248240
249241 response = client .get ("/dir/" )
@@ -273,7 +265,7 @@ def test_staticfiles_html_without_index(tmpdir):
273265 path = os .path .join (tmpdir , "dir" )
274266 os .mkdir (path )
275267
276- app = StarletteStaticFiles (directories = [tmpdir ], html = True )
268+ app = StaticFiles (directories = [tmpdir ], html = True )
277269 client = TestClient (app )
278270
279271 response = client .get ("/dir/" )
@@ -298,7 +290,7 @@ def test_staticfiles_html_without_404(tmpdir):
298290 with open (path , "w" ) as file :
299291 file .write ("<h1>Hello</h1>" )
300292
301- app = StarletteStaticFiles (directories = [tmpdir ], html = True )
293+ app = StaticFiles (directories = [tmpdir ], html = True )
302294 client = TestClient (app )
303295
304296 response = client .get ("/dir/" )
@@ -321,7 +313,7 @@ def test_staticfiles_html_only_files(tmpdir):
321313 with open (path , "w" ) as file :
322314 file .write ("<h1>Hello</h1>" )
323315
324- app = StarletteStaticFiles (directories = [tmpdir ], html = True )
316+ app = StaticFiles (directories = [tmpdir ], html = True )
325317 client = TestClient (app )
326318
327319 with pytest .raises (HTTPException ) as exc_info :
@@ -347,7 +339,7 @@ def test_staticfiles_cache_invalidation_for_deleted_file_html_mode(tmpdir):
347339 os .utime (path_404 , (common_modified_time , common_modified_time ))
348340 os .utime (path_some , (common_modified_time , common_modified_time ))
349341
350- app = StarletteStaticFiles (directories = [tmpdir ], html = True )
342+ app = StaticFiles (directories = [tmpdir ], html = True )
351343 client = TestClient (app )
352344
353345 resp_exists = client .get ("/some.html" )
@@ -377,9 +369,7 @@ def test_staticfiles_with_invalid_dir_permissions_returns_401(tmpdir):
377369
378370 os .chmod (tmpdir , stat .S_IRWXO )
379371
380- routers = [
381- Mount ("/" , app = StarletteStaticFiles (directories = [tmpdir ]), name = "static" )
382- ]
372+ routers = [Mount ("/" , app = StaticFiles (directories = [tmpdir ]), name = "static" )]
383373 app = AppFactory .create_app (routers = routers )
384374 client = TestClient (app )
385375
@@ -393,9 +383,7 @@ def test_staticfiles_with_missing_dir_returns_404(tmpdir):
393383 with open (path , "w" ) as file :
394384 file .write ("<file content>" )
395385
396- routers = [
397- Mount ("/" , app = StarletteStaticFiles (directories = [tmpdir ]), name = "static" )
398- ]
386+ routers = [Mount ("/" , app = StaticFiles (directories = [tmpdir ]), name = "static" )]
399387 app = AppFactory .create_app (routers = routers )
400388 client = TestClient (app )
401389
@@ -409,9 +397,7 @@ def test_staticfiles_access_file_as_dir_returns_404(tmpdir):
409397 with open (path , "w" ) as file :
410398 file .write ("<file content>" )
411399
412- routers = [
413- Mount ("/" , app = StarletteStaticFiles (directories = [tmpdir ]), name = "static" )
414- ]
400+ routers = [Mount ("/" , app = StaticFiles (directories = [tmpdir ]), name = "static" )]
415401 app = AppFactory .create_app (routers = routers )
416402 client = TestClient (app )
417403
@@ -428,9 +414,7 @@ def mock_timeout(*args, **kwargs):
428414 with open (path , "w" ) as file :
429415 file .write ("<file content>" )
430416
431- routers = [
432- Mount ("/" , app = StarletteStaticFiles (directories = [tmpdir ]), name = "static" )
433- ]
417+ routers = [Mount ("/" , app = StaticFiles (directories = [tmpdir ]), name = "static" )]
434418 app = AppFactory .create_app (routers = routers )
435419 client = TestClient (app , raise_server_exceptions = False )
436420
0 commit comments