~netlandish/django-wiki

29035a3341f8a0444b53d40dd44e21024bda2303 — Benjamin Bach 4 years ago 7dc4067
Fix issue in DeletedView, add test for purging a deleted article
2 files changed, 39 insertions(+), 2 deletions(-)

M src/wiki/views/article.py
M tests/core/test_views.py
M src/wiki/views/article.py => src/wiki/views/article.py +2 -1
@@ 526,7 526,8 @@ class Deleted(Delete):
        }

    def get_context_data(self, **kwargs):
        kwargs['purge_form'] = kwargs.pop('form', None)
        kwargs['purge_form'] = self.get_form()
        kwargs['form'] = kwargs['purge_form']
        return super().get_context_data(**kwargs)



M tests/core/test_views.py => tests/core/test_views.py +37 -1
@@ 357,9 357,45 @@ class DeleteViewTest(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientT
            response,
            resolve_url('wiki:get', path='testcache/')
        )
        # test the cache
        self.assertContains(self.get_by_path('TestCache/'), 'Content 2')

    def test_deleted_view(self):
        """
        Test that a special page is shown for restoring/purging a deleted
        article.
        """
        # 1. Create the article
        self.client.post(
            resolve_url('wiki:create', path=''),
            {'title': 'Test delete', 'slug': 'testdelete', 'content': 'To be deleted'}
        )
        # 2. Soft delete it
        self.client.post(
            resolve_url('wiki:delete', path='testdelete/'),
            {'confirm': 'on', 'purge': '',
             'revision': str(URLPath.objects.get(slug='testdelete').article.current_revision.id)}
        )
        # 3. Get and test that it redirects to the deleted page
        response = self.client.get(
            resolve_url('wiki:get', path='testdelete/'),
            follow=True,
        )
        # test that it's the Deleted page
        self.assertContains(response, 'Article deleted')

        # 4. Test that we can purge the page now
        self.client.post(
            resolve_url('wiki:deleted', path='testdelete/'),
            {'confirm': 'on', 'purge': 'on',
             'revision': str(URLPath.objects.get(slug='testdelete').article.current_revision.id)}
        )
        # 5. Test that it's not found anymore
        response = self.client.get(
            resolve_url('wiki:get', path='testdelete/'),
            follow=True,
        )
        self.assertContains(response, "Add new article")

    # def test_delete_article_without_urlpath(self):
    #     """
    #     We need a test that tests that articles without URLpaths are correctly