Esempio n. 1
0
    def test_deleted_articles_list(self):
        c = self.c

        response = c.post(
            reverse('wiki:create', kwargs={'path': ''}), {
                'title': 'Delete Me',
                'slug': 'deleteme',
                'content': 'delete me please!'
            })

        self.assertRedirects(response,
                             reverse('wiki:get', kwargs={'path': 'deleteme/'}))

        response = c.post(
            reverse('wiki:delete', kwargs={'path': 'deleteme/'}), {
                'confirm':
                'on',
                'revision':
                URLPath.objects.get(
                    slug='deleteme').article.current_revision.id
            })

        self.assertRedirects(response, reverse('wiki:get', kwargs={'path':
                                                                   ''}))

        response = c.get(reverse('wiki:deleted_list'))
        self.assertContains(response, 'Delete Me')
Esempio n. 2
0
    def test_edit_save(self):

        c = self.c
        example_data = {
            'content': 'More modifications',
            'current_revision': '1',
            'preview': '0',
            'save': '1',
            'summary': 'why edited',
            'title': 'wiki test'
        }

        # test save and messages
        example2 = example_data
        example2['content'] = 'Something 2'
        response = c.post(reverse('wiki:edit', kwargs={'path': ''}), example2)
        message = getattr(c.cookies['messages'], 'value')

        self.assertRedirects(response, reverse('wiki:root'))

        response = c.get(reverse('wiki:root'))
        # self.dump_db_status('test_preview_save')
        # Why it doesn't display the latest revison text if other test
        # preceded? It is correctly in the db.
        self.assertContains(response, 'Something 2')
        self.assertIn('successfully added', message)
Esempio n. 3
0
    def test_revision_conflict(self):
        """
        Test the warning if the same article is being edited concurrently.
        """

        c = self.c

        example_data = {
            'content': 'More modifications',
            'current_revision': '1',
            'preview': '0',
            'save': '1',
            'summary': 'why edited',
            'title': 'wiki test'
        }

        response = c.post(
            reverse('wiki:edit', kwargs={'path': ''}),
            example_data
        )

        self.assertRedirects(response, reverse('wiki:root'))

        response = c.post(
            reverse('wiki:edit', kwargs={'path': ''}),
            example_data
        )

        self.assertContains(
            response,
            'While you were editing, someone else changed the revision.'
        )
Esempio n. 4
0
    def test_revision_conflict(self):
        """
        Test the warning if the same article is being edited concurrently.
        """

        c = self.c

        example_data = {
            'content': 'More modifications',
            'current_revision':
            str(URLPath.root().article.current_revision.id),
            'preview': '0',
            'save': '1',
            'summary': 'why edited',
            'title': 'wiki test'
        }

        response = c.post(reverse('wiki:edit', kwargs={'path': ''}),
                          example_data)

        self.assertRedirects(response, reverse('wiki:root'))

        response = c.post(reverse('wiki:edit', kwargs={'path': ''}),
                          example_data)

        self.assertContains(
            response,
            'While you were editing, someone else changed the revision.')
Esempio n. 5
0
 def test_anonymous_root(self):
     self.client.logout()
     response = self.client.get(
         reverse("wiki:get", kwargs={"article_id": self.root_article.pk}))
     self.assertEqual(response.status_code, 200)
     response = self.client.get(reverse("wiki:get", kwargs={"path": ""}))
     self.assertEqual(response.status_code, 200)
Esempio n. 6
0
    def test_merge_preview(self):
        """Test merge preview"""

        c = self.c
        first_revision = self.root_article.current_revision
        example_data = {
            'content': 'More modifications\n\nMerge new line',
            'current_revision': str(first_revision.id),
            'preview': '0',
            'save': '1',
            'summary': 'testing merge',
            'title': 'wiki test'
        }

        # save a new revision
        c.post(reverse('wiki:edit', kwargs={'path': ''}), example_data)

        new_revision = models.Article.objects.get(
            id=self.root_article.id).current_revision

        response = c.get(
            reverse('wiki:merge_revision_preview',
                    kwargs={
                        'article_id': self.root_article.id,
                        'revision_id': first_revision.id
                    }), )

        self.assertContains(response, 'Previewing merge between:')
        self.assertContains(
            response,
            '#{rev_number}'.format(rev_number=first_revision.revision_number))
        self.assertContains(
            response,
            '#{rev_number}'.format(rev_number=new_revision.revision_number))
Esempio n. 7
0
    def test_deleted_articles_list(self):
        c = self.c

        response = c.post(
            reverse('wiki:create', kwargs={'path': ''}),
            {'title': 'Delete Me', 'slug': 'deleteme', 'content': 'delete me please!'}
        )

        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': 'deleteme/'})
        )

        response = c.post(
            reverse('wiki:delete', kwargs={'path': 'deleteme/'}),
            {'confirm': 'on', 'revision': '2'}
        )

        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': ''})
        )

        response = c.get(reverse('wiki:deleted_list'))
        self.assertContains(response, 'Delete Me')
Esempio n. 8
0
    def test_edit_save(self):

        c = self.c
        example_data = {
            'content': 'More modifications',
            'current_revision': '1',
            'preview': '0',
            'save': '1',
            'summary': 'why edited',
            'title': 'wiki test'
        }

        # test save and messages
        example2 = example_data
        example2['content'] = 'Something 2'
        response = c.post(reverse('wiki:edit', kwargs={'path': ''}), example2)
        message = getattr(c.cookies['messages'], 'value')

        self.assertRedirects(response, reverse('wiki:root'))

        response = c.get(reverse('wiki:root'))
        # self.dump_db_status('test_preview_save')
        # Why it doesn't display the latest revison text if other test
        # preceded? It is correctly in the db.
        self.assertContains(response, 'Something 2')
        self.assertIn('successfully added', message)
Esempio n. 9
0
 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")
Esempio n. 10
0
 def test_normaluser_root(self):
     self.client.login(username=NORMALUSER1_USERNAME,
                       password=NORMALUSER1_PASSWORD)
     response = self.client.get(
         reverse("wiki:get", kwargs={"article_id": self.root_article.pk}))
     self.assertEqual(response.status_code, 200)
     response = self.client.get(reverse("wiki:get", kwargs={"path": ""}))
     self.assertEqual(response.status_code, 200)
Esempio n. 11
0
 def test_content(self):
     response = self.client.get(
         reverse('wiki:settings',
                 kwargs={
                     'article_id': self.root_article.pk,
                 }))
     self.assertEqual(response.context['selected_tab'], 'settings')
Esempio n. 12
0
    def test_redirects_to_create_with_lowercased_slug(self):

        response = self.get_by_path('Unknown_Linked_Page/')
        self.assertRedirects(
            response,
            reverse('wiki:create', kwargs={'path': ''}) + '?slug=unknown_linked_page'
        )
Esempio n. 13
0
    def test_redirects_to_create_if_the_slug_is_unknown(self):

        response = self.get_by_path('unknown/')
        self.assertRedirects(
            response,
            reverse('wiki:create', kwargs={'path': ''}) + '?slug=unknown'
        )
Esempio n. 14
0
 def test_can_read_permission(self):
     # everybody can see the source of an article
     self.client.logout()
     response = self.client.get(
         reverse("wiki:source", kwargs={"article_id":
                                        self.root_article.pk}))
     self.assertEqual(response.status_code, 200)
Esempio n. 15
0
    def test_redirects_to_create_if_the_slug_is_unknown(self):

        response = self.get_by_path('Unknown/')
        self.assertRedirects(
            response,
            reverse('wiki:create', kwargs={'path': ''}) + '?slug=Unknown'
        )
Esempio n. 16
0
 def test_can_read_permission(self):
     response = self.client.get(
         reverse('wiki:history',
                 kwargs={
                     'article_id': self.root_article.pk,
                 }))
     self.assertEqual(response.status_code, 200)
Esempio n. 17
0
    def process_view(self, request, view_func, view_args, view_kwargs):  # pylint: disable=unused-argument
        """
        This function handles authentication logic for wiki urls and redirects from
        the "root wiki" to the "course wiki" if the user accesses the wiki from a course url
        """
        # we care only about requests to wiki urls
        if not view_func.__module__.startswith('wiki.'):
            return

        # wiki pages are login required
        if not request.user.is_authenticated:
            return redirect(reverse('signin_user'), next=request.path)

        course_id = course_id_from_url(request.path)
        wiki_path = request.path.partition('/wiki/')[2]

        if course_id:
            # This is a /courses/org/name/run/wiki request
            course_path = "/courses/{}".format(text_type(course_id))
            # HACK: django-wiki monkeypatches the reverse function to enable
            # urls to be rewritten
            reverse._transform_url = lambda url: course_path + url  # pylint: disable=protected-access
            # Authorization Check
            # Let's see if user is enrolled or the course allows for public access
            try:
                course = get_course_with_access(request.user, 'load',
                                                course_id)
            except Http404:
                # course does not exist. redirect to root wiki.
                # clearing the referrer will cause process_response not to redirect
                # back to a non-existent course
                request.META['HTTP_REFERER'] = ''
                return redirect('/wiki/{}'.format(wiki_path))

            if not course.allow_public_wiki_access:
                is_enrolled = CourseEnrollment.is_enrolled(
                    request.user, course.id)
                is_staff = has_access(request.user, 'staff', course)
                if not (is_enrolled or is_staff):
                    # if a user is logged in, but not authorized to see a page,
                    # we'll redirect them to the course about page
                    return redirect('about_course', text_type(course_id))

                # If we need enterprise data sharing consent for this course, then redirect to the form.
                consent_url = get_enterprise_consent_url(
                    request, text_type(course_id))
                if consent_url:
                    return redirect(consent_url)

            # set the course onto here so that the wiki template can show the course navigation
            request.course = course
        else:
            # this is a request for /wiki/...

            # Check to see if we don't allow top-level access to the wiki via the /wiki/xxxx/yyy/zzz URLs
            # this will help prevent people from writing pell-mell to the Wiki in an unstructured way
            if not settings.FEATURES.get('ALLOW_WIKI_ROOT_ACCESS', False):
                raise PermissionDenied()

            return self._redirect_from_referrer(request, wiki_path)
Esempio n. 18
0
 def test_login_required(self):
     self.client.logout()
     response = self.client.get(
         reverse("wiki:settings",
                 kwargs={"article_id": self.root_article.pk}))
     # it's redirecting
     self.assertEqual(response.status_code, 302)
Esempio n. 19
0
    def test_redirects_to_create_with_lowercased_slug(self):

        response = self.get_by_path('Unknown_Linked_Page/')
        self.assertRedirects(
            response,
            reverse('wiki:create', kwargs={'path': ''}) +
            '?slug=unknown_linked_page')
Esempio n. 20
0
 def test_content(self):
     response = self.client.get(
         reverse('wiki:source',
                 kwargs={
                     'article_id': self.root_article.pk,
                 }))
     self.assertIn('Source of ', str(response.content))
     self.assertEqual(response.context['selected_tab'], 'source')
Esempio n. 21
0
 def test_template_used(self):
     response = self.client.get(
         reverse('wiki:source',
                 kwargs={
                     'article_id': self.root_article.pk,
                 }))
     self.assertEqual(response.status_code, 200)
     self.assertTemplateUsed(response, template_name='wiki/source.html')
Esempio n. 22
0
 def test_content(self):
     response = self.client.get(
         reverse('wiki:history',
                 kwargs={
                     'article_id': self.root_article.pk,
                 }))
     self.assertContains(response, 'History:')
     self.assertEqual(response.context['selected_tab'], 'history')
Esempio n. 23
0
 def test_diff(self):
     response = self.client.get(reverse('wiki:diff', kwargs={'revision_id': self.root_article.pk}))
     diff = {
         "diff": ["+ root article content"],
         "other_changes": [["New title", "Root Article"]]
     }
     self.assertJSONEqual(str(response.content, encoding='utf8'), diff)
     self.assertIsInstance(response, JsonResponse)
     self.assertEqual(response.status_code, 200)
Esempio n. 24
0
    def process_view(self, request, view_func, view_args, view_kwargs):  # pylint: disable=unused-argument
        """
        This function handles authentication logic for wiki urls and redirects from
        the "root wiki" to the "course wiki" if the user accesses the wiki from a course url
        """
        # we care only about requests to wiki urls
        if not view_func.__module__.startswith('wiki.'):
            return

        # wiki pages are login required
        if not request.user.is_authenticated():
            return redirect(reverse('signin_user'), next=request.path)

        course_id = course_id_from_url(request.path)
        wiki_path = request.path.partition('/wiki/')[2]

        if course_id:
            # This is a /courses/org/name/run/wiki request
            course_path = "/courses/{}".format(course_id.to_deprecated_string())
            # HACK: django-wiki monkeypatches the reverse function to enable
            # urls to be rewritten
            reverse._transform_url = lambda url: course_path + url  # pylint: disable=protected-access
            # Authorization Check
            # Let's see if user is enrolled or the course allows for public access
            try:
                course = get_course_with_access(request.user, 'load', course_id)
            except Http404:
                # course does not exist. redirect to root wiki.
                # clearing the referrer will cause process_response not to redirect
                # back to a non-existent course
                request.META['HTTP_REFERER'] = ''
                return redirect('/wiki/{}'.format(wiki_path))

            if not course.allow_public_wiki_access:
                is_enrolled = CourseEnrollment.is_enrolled(request.user, course.id)
                is_staff = has_access(request.user, 'staff', course)
                if not (is_enrolled or is_staff):
                    # if a user is logged in, but not authorized to see a page,
                    # we'll redirect them to the course about page
                    return redirect('about_course', course_id.to_deprecated_string())

                # If we need enterprise data sharing consent for this course, then redirect to the form.
                consent_url = get_enterprise_consent_url(request, unicode(course_id))
                if consent_url:
                    return redirect(consent_url)

            # set the course onto here so that the wiki template can show the course navigation
            request.course = course
        else:
            # this is a request for /wiki/...

            # Check to see if we don't allow top-level access to the wiki via the /wiki/xxxx/yyy/zzz URLs
            # this will help prevent people from writing pell-mell to the Wiki in an unstructured way
            if not settings.FEATURES.get('ALLOW_WIKI_ROOT_ACCESS', False):
                raise PermissionDenied()

            return self._redirect_from_referrer(request, wiki_path)
Esempio n. 25
0
 def test_diff(self):
     response = self.client.get(reverse('wiki:diff', kwargs={'revision_id': self.root_article.pk}))
     diff = {
         "diff": ["+ root article content"],
         "other_changes": [["New title", "Root Article"]]
     }
     self.assertJSONEqual(str(response.content, encoding='utf8'), diff)
     self.assertIsInstance(response, JsonResponse)
     self.assertEqual(response.status_code, 200)
Esempio n. 26
0
    def test_merge_preview(self):
        """Test merge preview"""

        c = self.c
        example_data = {
            'content': 'More modifications\n\nMerge new line',
            'current_revision': '1',
            'preview': '0',
            'save': '1',
            'summary': 'testing merge',
            'title': 'wiki test'
        }

        previous_revision = self.root_article.current_revision.id

        # save a new revision
        c.post(
            reverse('wiki:edit', kwargs={'path': ''}),
            example_data
        )

        response = c.get(
            reverse(
                'wiki:merge_revision_preview',
                kwargs={'article_id': self.root_article.id, 'revision_id': previous_revision}
            ),
        )

        new_revision = models.Article.objects.get(
            id=self.root_article.id
        ).current_revision.id

        self.assertContains(
            response,
            'Previewing merge between:'
        )
        self.assertContains(
            response,
            '#{rev_id}'.format(rev_id=previous_revision)
        )
        self.assertContains(
            response,
            '#{rev_id}'.format(rev_id=new_revision)
        )
Esempio n. 27
0
 def test_signup(self):
     response = self.client.post(
         wiki_settings.SIGNUP_URL,
         data={
             'password1': 'wiki', 'password2': 'wiki', 'username': '******',
             'email': '*****@*****.**'
         }
     )
     self.assertIs(CustomUser.objects.filter(email='*****@*****.**').exists(), True)
     self.assertRedirects(response, reverse('wiki:login'))
Esempio n. 28
0
    def test_illegal_slug(self):

        c = self.c

        # A slug cannot be '123' because it gets confused with an article ID.
        response = c.post(reverse('wiki:create', kwargs={'path': ''}), {
            'title': 'Illegal slug',
            'slug': '123',
            'content': 'blah'
        })
        self.assertContains(response, escape(validate_slug_numbers.message))
Esempio n. 29
0
 def test_signup(self):
     response = self.client.post(
         wiki_settings.SIGNUP_URL,
         data={
             "password1": "wiki",
             "password2": "wiki",
             "username": "******",
             "email": "*****@*****.**",
         },
     )
     self.assertIs(CustomUser.objects.filter(email="*****@*****.**").exists(), True)
     self.assertRedirects(response, reverse("wiki:login"))
Esempio n. 30
0
 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')
Esempio n. 31
0
    def test_create_nested_article_in_article(self):

        c = self.c

        response = c.post(reverse('wiki:create', kwargs={'path': ''}), {
            'title': 'Level 1',
            'slug': 'Level1',
            'content': 'Content level 1'
        })
        self.assertRedirects(response,
                             reverse('wiki:get', kwargs={'path': 'level1/'}))
        response = c.post(reverse('wiki:create', kwargs={'path': 'Level1/'}), {
            'title': 'test',
            'slug': 'Test',
            'content': 'Content on level 2'
        })
        self.assertRedirects(
            response, reverse('wiki:get', kwargs={'path': 'level1/test/'}))
        response = c.post(reverse('wiki:create', kwargs={'path': ''}), {
            'title': 'test',
            'slug': 'Test',
            'content': 'Other content on level 1'
        })

        self.assertRedirects(response,
                             reverse('wiki:get', kwargs={'path': 'test/'}))
        self.assertContains(self.get_by_path('Test/'),
                            'Other content on level 1')
        self.assertContains(self.get_by_path('Level1/Test/'),
                            'Content')  # on level 2')
Esempio n. 32
0
    def test_articles_cache_is_cleared_after_deleting(self):

        # That bug is tested by one individual test, otherwise it could be
        # revealed only by sequence of tests in some particular order
        c = self.c

        response = c.post(reverse('wiki:create', kwargs={'path': ''}), {
            'title': 'Test cache',
            'slug': 'testcache',
            'content': 'Content 1'
        })

        self.assertRedirects(
            response, reverse('wiki:get', kwargs={'path': 'testcache/'}))

        response = c.post(
            reverse('wiki:delete', kwargs={'path': 'testcache/'}), {
                'confirm': 'on',
                'purge': 'on',
                'revision': '2'
            })

        self.assertRedirects(response, reverse('wiki:get', kwargs={'path':
                                                                   ''}))
        response = c.post(reverse('wiki:create', kwargs={'path': ''}), {
            'title': 'Test cache',
            'slug': 'TestCache',
            'content': 'Content 2'
        })

        self.assertRedirects(
            response, reverse('wiki:get', kwargs={'path': 'testcache/'}))
        # test the cache
        self.assertContains(self.get_by_path('TestCache/'), 'Content 2')
Esempio n. 33
0
    def test_illegal_slug(self):

        c = self.c

        # A slug cannot be '123' because it gets confused with an article ID.
        response = c.post(
            reverse('wiki:create', kwargs={'path': ''}),
            {'title': 'Illegal slug', 'slug': '123', 'content': 'blah'}
        )
        self.assertContains(
            response,
            escape(validate_slug_numbers.message)
        )
Esempio n. 34
0
    def test_update_profile(self):
        c = self.c

        c.post(
            reverse('wiki:profile_update'),
            {"email": "*****@*****.**", "password1": "newPass", "password2": "newPass"},
            follow=True
        )

        test_auth = authenticate(username='******', password='******')

        self.assertNotEqual(test_auth, None)
        self.assertEqual(test_auth.email, '*****@*****.**')
Esempio n. 35
0
    def test_root_article(self):
        """
        Test redirecting to /create-root/,
        creating the root article and a simple markup.
        """

        c = self.c
        response = c.get(reverse('wiki:root'))  # url '/'

        self.assertRedirects(
            response,
            reverse('wiki:root_create')  # url '/create-root/'
        )

        response = c.post(
            reverse('wiki:root_create'),
            {'content': 'test heading h1\n====\n', 'title': 'Wiki Test'}
        )

        self.assertRedirects(response, reverse('wiki:root'))
        response = c.get(reverse('wiki:root'))
        self.assertContains(response, 'test heading h1</h1>')
Esempio n. 36
0
    def test_root_article(self):
        """
        Test redirecting to /create-root/,
        creating the root article and a simple markup.
        """

        c = self.c
        response = c.get(reverse('wiki:root'))  # url '/'

        self.assertRedirects(
            response,
            reverse('wiki:root_create')  # url '/create-root/'
        )

        response = c.post(
            reverse('wiki:root_create'),
            {'content': 'test heading h1\n====\n', 'title': 'Wiki Test'}
        )

        self.assertRedirects(response, reverse('wiki:root'))
        response = c.get(reverse('wiki:root'))
        self.assertContains(response, 'test heading h1</h1>')
Esempio n. 37
0
    def test_update_profile(self):
        c = self.c

        c.post(
            reverse('wiki:profile_update'),
            {"email": "*****@*****.**", "password1": "newPass", "password2": "newPass"},
            follow=True
        )

        test_auth = authenticate(username='******', password='******')

        self.assertNotEqual(test_auth, None)
        self.assertEqual(test_auth.email, '*****@*****.**')
Esempio n. 38
0
 def test_root_article(self):
     """
     Test redirecting to /create-root/,
     creating the root article and a simple markup.
     """
     self.get_url('wiki:root')
     self.assertUrlsEqual(reverse('wiki:root_create'))
     self.fill({
         '#id_content': 'test heading h1\n====\n',
         '#id_title': 'Wiki Test',
     })
     self.submit('input[name="save_changes"]')
     self.assertUrlsEqual('/')
     self.assertTextPresent('test heading h1')
     article = URLPath.root().article
     self.assertIn('test heading h1', article.current_revision.content)
Esempio n. 39
0
 def test_normal_user(self):
     """
     Tests that the settings view page renders for a normal user
     Regression test: https://github.com/django-wiki/django-wiki/issues/1058
     """
     response = self.client.post(
         resolve_url("wiki:create", path=""),
         {
             "title": "Level 1",
             "slug": "Level1",
             "content": "Content level 1"
         },
     )
     self.client.login(username=NORMALUSER1_USERNAME,
                       password=NORMALUSER1_PASSWORD)
     response = self.client.get(
         reverse("wiki:settings", kwargs={"path": "level1/"}))
     self.assertEqual(response.status_code, 200)
Esempio n. 40
0
    def test_preview_save(self):
        """Test edit preview, edit save and messages."""

        c = self.c
        example_data = {
            'content': 'The modified text',
            'current_revision': '1',
            'preview': '1',
            # 'save': '1',  # probably not too important
            'summary': 'why edited',
            'title': 'wiki test'
        }

        # test preview
        response = c.post(
            reverse('wiki:preview', kwargs={'path': ''}),  # url: '/_preview/'
            example_data)

        self.assertContains(response, 'The modified text')
Esempio n. 41
0
    def test_preview_save(self):
        """Test edit preview, edit save and messages."""

        c = self.c
        example_data = {
            'content': 'The modified text',
            'current_revision': '1',
            'preview': '1',
            # 'save': '1',  # probably not too important
            'summary': 'why edited',
            'title': 'wiki test'
        }

        # test preview
        response = c.post(
            reverse('wiki:preview', kwargs={'path': ''}),  # url: '/_preview/'
            example_data
        )

        self.assertContains(response, 'The modified text')
Esempio n. 42
0
    def test_article_list_update(self):
        """
        Test automatic adding and removing the new article to/from article_list.
        """

        c = self.c
        root_data = {
            'content': '[article_list depth:2]',
            'current_revision':
            str(URLPath.root().article.current_revision.id),
            'preview': '1',
            'title': 'Root Article'
        }

        response = c.post(reverse('wiki:edit', kwargs={'path': ''}), root_data)
        self.assertRedirects(response, reverse('wiki:root'))

        # verify the new article is added to article_list
        response = c.post(reverse('wiki:create', kwargs={'path': ''}), {
            'title': 'Sub Article 1',
            'slug': 'SubArticle1'
        })

        self.assertRedirects(
            response, reverse('wiki:get', kwargs={'path': 'subarticle1/'}))
        self.assertContains(self.get_by_path(''), 'Sub Article 1')
        self.assertContains(self.get_by_path(''), 'subarticle1/')

        # verify the deleted article is removed from article_list
        response = c.post(
            reverse('wiki:delete', kwargs={'path': 'SubArticle1/'}), {
                'confirm':
                'on',
                'purge':
                'on',
                'revision':
                str(
                    URLPath.objects.get(
                        slug='subarticle1').article.current_revision.id),
            })

        message = getattr(c.cookies['messages'], 'value')

        self.assertRedirects(response, reverse('wiki:get', kwargs={'path':
                                                                   ''}))
        self.assertIn(
            'This article together with all '
            'its contents are now completely gone', message)
        self.assertNotContains(self.get_by_path(''), 'Sub Article 1')
Esempio n. 43
0
    def test_article_list_update(self):
        """
        Test automatic adding and removing the new article to/from article_list.
        """

        c = self.c

        root_data = {
            'content': '[article_list depth:2]',
            'current_revision': '1',
            'preview': '1',
            'title': 'Root Article'
        }

        response = c.post(reverse('wiki:edit', kwargs={'path': ''}), root_data)
        self.assertRedirects(response, reverse('wiki:root'))

        # verify the new article is added to article_list
        response = c.post(
            reverse('wiki:create', kwargs={'path': ''}),
            {'title': 'Sub Article 1', 'slug': 'SubArticle1'}
        )

        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': 'subarticle1/'})
        )
        self.assertContains(self.get_by_path(''), 'Sub Article 1')
        self.assertContains(self.get_by_path(''), 'subarticle1/')

        # verify the deleted article is removed from article_list
        response = c.post(
            reverse('wiki:delete', kwargs={'path': 'SubArticle1/'}),
            {'confirm': 'on', 'purge': 'on', 'revision': '3'}
        )

        message = getattr(c.cookies['messages'], 'value')

        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': ''})
        )
        self.assertIn(
            'This article together with all '
            'its contents are now completely gone',
            message)
        self.assertNotContains(self.get_by_path(''), 'Sub Article 1')
Esempio n. 44
0
    def test_create_nested_article_in_article(self):

        c = self.c

        response = c.post(
            reverse('wiki:create', kwargs={'path': ''}),
            {'title': 'Level 1', 'slug': 'Level1', 'content': 'Content level 1'}
        )
        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': 'level1/'})
        )
        response = c.post(
            reverse('wiki:create', kwargs={'path': 'Level1/'}),
            {'title': 'test', 'slug': 'Test', 'content': 'Content on level 2'}
        )
        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': 'level1/test/'})
        )
        response = c.post(
            reverse('wiki:create', kwargs={'path': ''}),
            {'title': 'test',
             'slug': 'Test',
             'content': 'Other content on level 1'
             }
        )

        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': 'test/'})
        )
        self.assertContains(
            self.get_by_path('Test/'),
            'Other content on level 1'
        )
        self.assertContains(
            self.get_by_path('Level1/Test/'),
            'Content'
        )  # on level 2')
Esempio n. 45
0
    def test_articles_cache_is_cleared_after_deleting(self):

        # That bug is tested by one individual test, otherwise it could be
        # revealed only by sequence of tests in some particular order
        c = self.c

        response = c.post(
            reverse('wiki:create', kwargs={'path': ''}),
            {'title': 'Test cache', 'slug': 'testcache', 'content': 'Content 1'}
        )

        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': 'testcache/'})
        )

        response = c.post(
            reverse('wiki:delete', kwargs={'path': 'testcache/'}),
            {'confirm': 'on', 'purge': 'on', 'revision': '2'}
        )

        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': ''})
        )
        response = c.post(
            reverse('wiki:create', kwargs={'path': ''}),
            {'title': 'Test cache', 'slug': 'TestCache', 'content': 'Content 2'}
        )

        self.assertRedirects(
            response,
            reverse('wiki:get', kwargs={'path': 'testcache/'})
        )
        # test the cache
        self.assertContains(self.get_by_path('TestCache/'), 'Content 2')
Esempio n. 46
0
 def test_already_signed_in(self):
     self.client.force_login(self.superuser1)
     response = self.client.get(wiki_settings.LOGIN_URL)
     self.assertRedirects(response, reverse('wiki:root'))
Esempio n. 47
0
 def test_edit_view(self):
     """Test that the edit page displays"""
     c = self.c
     response = c.get(reverse('wiki:edit', kwargs={'path': ''}))
     self.assertContains(response, 'Edit')
Esempio n. 48
0
    def test_query_string(self):

        c = self.c

        response = c.get(reverse('wiki:search'), {'q': 'Article'})
        self.assertContains(response, 'Root Article')
Esempio n. 49
0
    def test_empty_query_string(self):

        c = self.c

        response = c.get(reverse('wiki:search'), {'q': ''})
        self.assertFalse(response.context['articles'])