From 5ff400434a429ef5066193bb0b39b953456a98ee Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 30 Dec 2019 17:56:25 +0100 Subject: [PATCH] Add tests for DirView --- tests/core/test_views.py | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/core/test_views.py b/tests/core/test_views.py index fe7999a4..8ab4fe1c 100644 --- a/tests/core/test_views.py +++ b/tests/core/test_views.py @@ -684,6 +684,7 @@ class SourceViewTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClient class HistoryViewTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestBase): + def test_can_read_permission(self): response = self.client.get(reverse('wiki:history', kwargs={ 'article_id': self.root_article.pk, @@ -694,11 +695,50 @@ class HistoryViewTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClien response = self.client.get(reverse('wiki:history', kwargs={ 'article_id': self.root_article.pk, })) - self.assertIn('History:', str(response.content)) + self.assertContains(response, 'History:') self.assertEqual(response.context['selected_tab'], 'history') +class DirViewTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestBase): + + def test_browse_root(self): + response = self.client.get( + reverse('wiki:dir', kwargs={'path': ''}), + ) + self.assertRegex( + response.rendered_content, + r'Browsing\s+/' + ) + + def test_browse_root_query(self): + self.client.post( + resolve_url('wiki:create', path=''), + {'title': 'Test', 'slug': 'test0', 'content': 'Content .0.'} + ) + self.client.post( + resolve_url('wiki:create', path='test0/'), + {'title': 'Test00', 'slug': 'test00', 'content': 'Content .00.'} + ) + response = self.client.get( + reverse('wiki:dir', kwargs={'path': ''}), + {'query': "Test"}, + ) + self.assertRegex( + response.rendered_content, + r'1 article' + ) + response = self.client.get( + reverse('wiki:dir', kwargs={'path': 'test0/'}), + {'query': "Test00"}, + ) + self.assertRegex( + response.rendered_content, + r'1 article' + ) + + class SettingsViewTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestBase): + def test_change_group(self): group = CustomGroup.objects.create() response = self.client.post( -- 2.45.2