make request -> instance conversion support symlink dirs

I think this also clarifies the code, a bit
This commit is contained in:
2021-04-17 10:30:01 -05:00
parent c90f0a3a42
commit 60715a3a5c
4 changed files with 57 additions and 25 deletions

View File

@@ -125,6 +125,20 @@ def test_that_request_to_symlink_redirects_file(client):
assert response.location == 'http://localhost/foo.txt'
def test_that_request_to_symlink_redirects_directory(client):
"""Test that a request to /foo/ redirects to /what-foo-points-at/."""
response = client.get('/symlink-to-subdir/')
assert response.status_code == 301
assert response.location == 'http://localhost/subdir'
# sadly, this location also redirects
response = client.get('/subdir')
assert response.status_code == 301
assert response.location == 'http://localhost/subdir/'
# but we do get there
response = client.get('/subdir/')
assert response.status_code == 200
def test_that_dir_request_does_not_redirect(client):
"""Test that a request to /foo/ serves the index page, if foo is a directory."""
response = client.get('/subdir/')

View File

@@ -0,0 +1 @@
subdir

View File

@@ -146,6 +146,13 @@ def test_request_path_to_instance_resource_path_file_symlink(app):
('pages/foo.txt', 'symlink'))
def test_request_path_to_instance_resource_path_dir_symlink(app):
"""Test that a request for e.g. '/foo' when /foo is a symlink to /bar redirects."""
with app.test_request_context():
assert (request_path_to_instance_resource_path('symlink-to-subdir/') ==
('pages/subdir', 'symlink'))
def test_request_path_to_instance_resource_path_nonexistant_file_errors(app):
"""Test that a request for something not on disk errors."""
with app.test_request_context():