From 30b79e9dc18a2dc84c25a2dd03426d3c5cecfafc Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 17 Apr 2021 10:39:05 -0500 Subject: [PATCH] add tests for subdir symlinks this is automagically supported by the previous rewrite --- tests/functional_tests.py | 9 +++++++++ tests/test_pages.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/tests/functional_tests.py b/tests/functional_tests.py index a47916f..6bdafd3 100644 --- a/tests/functional_tests.py +++ b/tests/functional_tests.py @@ -139,6 +139,15 @@ def test_that_request_to_symlink_redirects_directory(client): assert response.status_code == 200 +def test_that_request_to_symlink_redirects_subdirectory(client): + """Test that a request to /foo/bar redirects to /what-foo-points-at/bar.""" + response = client.get('/symlink-to-subdir/page-no-title') + assert response.status_code == 301 + assert response.location == 'http://localhost/subdir/page-no-title' + response = client.get('/subdir/page-no-title') + 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/') diff --git a/tests/test_pages.py b/tests/test_pages.py index a1d6f55..839ffe3 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -153,6 +153,13 @@ def test_request_path_to_instance_resource_path_dir_symlink(app): ('pages/subdir', 'symlink')) +def test_request_path_to_instance_resource_path_subdir_symlink(app): + """Test that a request for e.g. '/foo/baz' when /foo is a symlink to /bar redirects.""" + with app.test_request_context(): + assert (request_path_to_instance_resource_path('symlink-to-subdir/page-no-title') == + ('pages/subdir/page-no-title.md', '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():