From 6a8b57df6a5b7fd470e18880b0735af3b0ce349c Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Wed, 24 Oct 2018 02:44:27 +0200 Subject: [PATCH] Completed test coverage of views.static.directory_name(). --- tests/view_tests/media/subdir/.hidden | 1 + tests/view_tests/media/subdir/visible | 0 tests/view_tests/tests/test_static.py | 8 ++++++++ 3 files changed, 9 insertions(+) create mode 100644 tests/view_tests/media/subdir/.hidden create mode 100644 tests/view_tests/media/subdir/visible diff --git a/tests/view_tests/media/subdir/.hidden b/tests/view_tests/media/subdir/.hidden new file mode 100644 index 0000000000..3a1a5eb607 --- /dev/null +++ b/tests/view_tests/media/subdir/.hidden @@ -0,0 +1 @@ +The directory_name() view ignores files that start with a dot. diff --git a/tests/view_tests/media/subdir/visible b/tests/view_tests/media/subdir/visible new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py index 3154ce1703..f4c58e0611 100644 --- a/tests/view_tests/tests/test_static.py +++ b/tests/view_tests/tests/test_static.py @@ -111,6 +111,14 @@ class StaticTests(SimpleTestCase): def test_index(self): response = self.client.get('/%s/' % self.prefix) self.assertContains(response, 'Index of ./') + # Directories have a trailing slash. + self.assertIn('subdir/', response.context['file_list']) + + def test_index_subdir(self): + response = self.client.get('/%s/subdir/' % self.prefix) + self.assertContains(response, 'Index of subdir/') + # File with a leading dot (e.g. .hidden) aren't displayed. + self.assertEqual(response.context['file_list'], ['visible']) @override_settings(TEMPLATES=[{ 'BACKEND': 'django.template.backends.django.DjangoTemplates',