Esempio n. 1
0
    def test_comment_traversal(self):
        """Test comment rendering pages"""

        # Create a couple of comments to traverse

        comment = models.Post.objects.create(title="Test",
                                             author=self.owner,
                                             content="Test",
                                             type=models.Post.COMMENT,
                                             root=self.post,
                                             parent=self.post)
        comment2 = models.Post.objects.create(title="Test",
                                              author=self.owner,
                                              content="Test",
                                              type=models.Post.COMMENT,
                                              root=self.post,
                                              parent=comment)

        url = reverse("post_view", kwargs=dict(uid=self.post.uid))

        request = fake_request(url=url, data={}, user=self.owner)

        response = views.post_view(request=request, uid=self.post.uid)

        self.assertTrue(response.status_code == 200,
                        'Error rendering comments')
Esempio n. 2
0
    def test_drag_and_drop(self):
        """
        Test AJAX function used to drag and drop.
        """

        # Create comment to self.parent
        comment1 = models.Post.objects.create(title="Test",
                                              author=self.owner,
                                              content="Test",
                                              type=models.Post.COMMENT,
                                              root=self.post,
                                              parent=self.post)
        # Create another post with parent being above comment
        comment2 = models.Post.objects.create(title="Test",
                                              author=self.owner,
                                              content="Test",
                                              type=models.Post.COMMENT,
                                              root=self.post,
                                              parent=comment1)
        comment3 = models.Post.objects.create(title="Test",
                                              author=self.owner,
                                              content="Test",
                                              type=models.Post.COMMENT,
                                              root=self.post,
                                              parent=comment2)

        # Move comment3 to comment1
        data = {'parent': comment1.uid, 'uid': comment3.uid}
        url = reverse('drag_and_drop')
        request = fake_request(url=url, data=data, user=self.owner)
        json_response = ajax.drag_and_drop(request)
        self.process_response(json_response)
Esempio n. 3
0
    def preform_votes(self, post, user):
        for vtype in ["upvote", "bookmark", "accept"]:

            data = {"vote_type": vtype, "post_uid": post.uid}
            request = fake_request(url=reverse('vote'), data=data, user=user)
            response = ajax.ajax_vote(request)
            self.assertEqual(response.status_code, 200,
                             f"Could not preform vote:{vtype}.")
Esempio n. 4
0
    def test_digest(self):
        """
        Test AJAX function that toggles users digest options
        """

        data = {'pref': 'daily'}

        url = reverse('ajax_digest')
        request = fake_request(url=url, data=data, user=self.owner)
        json_response = ajax.ajax_digest(request)
        self.process_response(json_response)
Esempio n. 5
0
    def test_post_answer(self):
        """
        Test submitting answer through the post view
        """
        url = reverse("post_view", kwargs=dict(uid=self.post.uid))

        # Get form data
        data = dict(content="testing answer", parent_uid=self.post.uid)
        request = fake_request(url=url, data=data, user=self.owner)
        response = views.post_view(request=request, uid=self.post.uid)
        return
Esempio n. 6
0
    def test_duplicate_post(self):
        "Test duplicate post moderation"

        data = {"dupe": "google.com"}

        url = reverse('post_moderate', kwargs=dict(uid=self.post.uid))
        request = fake_request(url=url, data=data, user=self.owner)
        response = views.post_moderate(request=request, uid=self.post.uid)
        self.process_response(response)

        pass
Esempio n. 7
0
    def moderate(self, choices, post, extra={}):

        for action in choices:
            data = {"action": action}
            data.update(extra)
            url = reverse('post_moderate', kwargs=dict(uid=post.uid))
            request = fake_request(url=url, data=data, user=self.owner)
            response = views.post_moderate(request=request, uid=post.uid)
            self.process_response(response)

        return
Esempio n. 8
0
    def test_ajax_subs(self):

        for stype in ["unfollow", "messages", "email", "all", "default"]:

            data = {"sub_type": stype, "root_uid": self.post.uid}
            request = fake_request(url=reverse('vote'),
                                   data=data,
                                   user=self.owner)
            response = ajax.ajax_subs(request)
            self.assertEqual(
                response.status_code, 200,
                f"Could not preform subscription action:{stype}.")
Esempio n. 9
0
    def test_similar_posts(self):
        """
        Test AJAX function used to produce the similar posts sidebar.
        """
        data = {'query': 'Test'}
        url = reverse('similar_posts', kwargs=dict(uid=self.post.uid))

        request = fake_request(url=url,
                               data=data,
                               user=self.owner,
                               method='GET')
        toplevel_response = ajax.similar_posts(request, uid=self.post.uid)
        self.process_response(toplevel_response)
Esempio n. 10
0
    def test_inplace_form(self):
        """
        Test AJAX function used to render inplace form.
        """
        data = {'parent': self.post.uid, 'uid': self.post.uid, 'top': '1'}
        url = reverse('inplace_form')

        request = fake_request(url=url,
                               data=data,
                               user=self.owner,
                               method='GET')
        toplevel_response = ajax.inplace_form(request)
        self.process_response(toplevel_response)
Esempio n. 11
0
    def test_inplace_create(self):
        """
        Test AJAX function used to preform
        """

        nontoplevel_data = {
            'content': "Addin a new comment foo bar",
            'parent': self.post.uid
        }

        url = reverse('ajax_comment_create')

        request = fake_request(url=url, data=nontoplevel_data, user=self.owner)
        nontoplevel_response = ajax.ajax_comment_create(request)
        self.process_response(nontoplevel_response)
Esempio n. 12
0
    def test_inplace_edit(self):
        """
        Test AJAX function for inplace edits
        """
        data = {
            'content': 'New content here foo bar bar',
            'title': 'New title here foo bar bar',
            'post_type': models.Post.FORUM,
            'tag_val': ['new', 'tag']
        }

        url = reverse('ajax_edit', kwargs=dict(uid=self.post.uid))

        request = fake_request(url=url, data=data, user=self.owner)
        json_response = ajax.ajax_edit(request, uid=self.post.uid)

        self.process_response(json_response)
Esempio n. 13
0
    def test_post_create(self):
        """Test post creation with POST request"""

        content = f"@{self.owner.username} " + "testing " * 10

        # Create fake request
        data = {
            'post_type': models.Post.QUESTION,
            'title': 'title tested post',
            "tag_val": "tested,test3",
            "content": content
        }

        request = fake_request(url=reverse('post_create'),
                               data=data,
                               user=self.owner)
        response = views.new_post(request=request)
Esempio n. 14
0
    def test_search_view(self):
        """
        Test search view
        """

        url = reverse("post_search")

        # Get form data
        data = dict(query="Test post")
        request = fake_request(url=url,
                               data=data,
                               method="GET",
                               user=self.owner)

        # Preform search on test index
        response = views.post_search(request=request)

        self.assertEqual(response.status_code, 200, "Error preforming search.")
Esempio n. 15
0
    def Xtest_edit_post(self):
        """
        Test post edit for root and descendants
        """
        url = reverse("post_edit", kwargs=dict(uid=self.post.uid))

        title = "Test title for long test"
        tag_val = "foo,bar,foo"
        content = "Test the content with more things "

        longform_data = dict(title=title,
                             tag_val=tag_val,
                             content=content,
                             post_type=models.Post.TUTORIAL)

        longform_request = fake_request(url=url,
                                        data=longform_data,
                                        user=self.owner)
        longform_response = views.edit_post(request=longform_request,
                                            uid=self.post.uid)