-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #803 from realcr/master
Fixed bug in serving static directory
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def tmp_dir_path(request): | ||
""" | ||
Give a path for a temporary directory | ||
The directory is destroyed at the end of the test. | ||
""" | ||
# Temporary directory. | ||
tmp_dir = tempfile.mkdtemp() | ||
|
||
def teardown(): | ||
# Delete the whole directory: | ||
shutil.rmtree(tmp_dir) | ||
|
||
request.addfinalizer(teardown) | ||
return tmp_dir | ||
|
||
|
||
@pytest.mark.run_loop | ||
def test_access_root_of_static_handler(tmp_dir_path, create_app_and_client): | ||
""" | ||
Tests the operation of static file server. | ||
Try to access the root of static file server, and make | ||
sure that a proper not found error is returned. | ||
""" | ||
# Put a file inside tmp_dir_path: | ||
my_file_path = os.path.join(tmp_dir_path, 'my_file') | ||
with open(my_file_path, 'w') as fw: | ||
fw.write('hello') | ||
|
||
app, client = yield from create_app_and_client() | ||
|
||
# Register global static route: | ||
app.router.add_static('/', tmp_dir_path) | ||
|
||
# Request the root of the static directory. | ||
# Expect an 404 error page. | ||
r = (yield from client.get('/')) | ||
assert r.status == 404 | ||
# data = (yield from r.read()) | ||
yield from r.release() |