Esempio n. 1
0
    def test_reply_redirect(self):
        """Posting a reply should redirect."""
        t = ThreadFactory()
        u = UserFactory()

        self.client.login(username=u.username, password="******")
        url = reverse("forums.reply", args=[t.forum.slug, t.id])
        data = {"content": "some content"}
        r = self.client.post(url, data, follow=False)
        eq_(302, r.status_code)
        assert t.forum.slug in r["location"]
        assert str(t.id) in r["location"]
        assert "last=" in r["location"]
Esempio n. 2
0
    def test_reply_without_post_permission(self):
        """Posting without post_in_forum permission should 403."""
        rforum = RestrictedForumFactory(
            permission_code='forums_forum.post_in_forum')
        t = ThreadFactory(forum=rforum)
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        with patch.object(Forum, 'allows_viewing_by', Mock(return_value=True)):
            response = post(self.client,
                            'forums.reply', {'content': 'Blahs'},
                            args=[t.forum.slug, t.id])
        eq_(403, response.status_code)
Esempio n. 3
0
    def test_restricted_hide_reply(self):
        """Reply fields don't show if user has no permission to post."""
        t = ThreadFactory()
        f = t.forum
        ct = ContentType.objects.get_for_model(f)
        # If the forum has the permission and the user isn't assigned said
        # permission, then they can't post.
        PermissionFactory(codename="forums_forum.post_in_forum", content_type=ct, object_id=f.id)
        u = UserFactory()

        self.client.login(username=u.username, password="******")
        response = get(self.client, "forums.posts", args=[f.slug, t.pk])
        self.assertNotContains(response, "thread-reply")
Esempio n. 4
0
    def test_reply_redirect(self):
        """Posting a reply should redirect."""
        t = ThreadFactory()
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        url = reverse('forums.reply', args=[t.forum.slug, t.id])
        data = {'content': 'some content'}
        r = self.client.post(url, data, follow=False)
        eq_(302, r.status_code)
        assert t.forum.slug in r['location']
        assert str(t.id) in r['location']
        assert 'last=' in r['location']
Esempio n. 5
0
    def test_watch_thread_without_permission(self):
        """Watching threads without the view_in_forum permission should 404.
        """
        rforum = RestrictedForumFactory()
        t = ThreadFactory(forum=rforum)
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        response = self.client.post(reverse('forums.watch_thread',
                                            args=[t.forum.slug, t.id]),
                                    {'watch': 'yes'},
                                    follow=False)
        eq_(404, response.status_code)
Esempio n. 6
0
    def test_empty_reply_errors(self):
        """Posting an empty reply shows errors."""
        u = UserFactory()
        t = ThreadFactory()

        self.client.login(username=u.username, password="******")
        response = post(self.client,
                        "forums.reply", {"content": ""},
                        args=[t.forum.slug, t.id])

        doc = pq(response.content)
        error_msg = doc("ul.errorlist li a")[0]
        eq_(error_msg.text, "Please provide a message.")
Esempio n. 7
0
    def test_empty_reply_errors(self):
        """Posting an empty reply shows errors."""
        u = UserFactory()
        t = ThreadFactory()

        self.client.login(username=u.username, password='******')
        response = post(self.client,
                        'forums.reply', {'content': ''},
                        args=[t.forum.slug, t.id])

        doc = pq(response.content)
        error_msg = doc('ul.errorlist li a')[0]
        eq_(error_msg.text, 'Please provide a message.')
Esempio n. 8
0
    def test_deleted(self):
        # Nothing exists before the test starts
        eq_(ThreadMappingType.search().count(), 0)

        # Creating a new Thread does create a new document in the index.
        new_thread = ThreadFactory()
        self.refresh()
        eq_(ThreadMappingType.search().count(), 1)

        # Deleting the thread deletes the document in the index.
        new_thread.delete()
        self.refresh()
        eq_(ThreadMappingType.search().count(), 0)
Esempio n. 9
0
    def test_thread_is_reindexed_on_username_change(self):
        search = ThreadMappingType.search()

        u = UserFactory(username="******")
        ThreadFactory(creator=u, title="Hello")

        self.refresh()
        eq_(search.query(post_title="hello")[0]["post_author_ord"], ["dexter"])

        # Change the username and verify the index.
        u.username = "******"
        u.save()
        self.refresh()
        eq_(search.query(post_title="hello")[0]["post_author_ord"], ["walter"])
Esempio n. 10
0
    def test_new_thread_without_view_permission(self):
        """Making a new thread without view permission should 404."""
        rforum = RestrictedForumFactory()
        ThreadFactory(forum=rforum)
        u = UserFactory()

        self.client.login(username=u.username, password='******')
        response = post(self.client,
                        'forums.new_thread', {
                            'title': 'Blahs',
                            'content': 'Blahs'
                        },
                        args=[rforum.slug])
        eq_(404, response.status_code)
Esempio n. 11
0
    def test_thread_is_reindexed_on_username_change(self):
        search = ThreadMappingType.search()

        u = UserFactory(username='******')
        ThreadFactory(creator=u, title='Hello')

        self.refresh()
        eq_(search.query(post_title='hello')[0]['post_author_ord'], ['dexter'])

        # Change the username and verify the index.
        u.username = '******'
        u.save()
        self.refresh()
        eq_(search.query(post_title='hello')[0]['post_author_ord'], ['walter'])
Esempio n. 12
0
    def test_edit_thread_errors(self):
        """Editing thread with too short of a title shows errors."""
        t = ThreadFactory()
        creator = t.creator

        self.client.login(username=creator.username, password='******')
        response = post(self.client, 'forums.edit_thread',
                        {'title': 'wha?'}, args=[t.forum.slug, t.id])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text,
            'Your title is too short (4 characters). ' +
            'It must be at least 5 characters.')
Esempio n. 13
0
    def test_num_replies(self):
        """Verify the number of replies label."""
        t = ThreadFactory()

        response = get(self.client, "forums.posts", args=[t.forum.slug, t.id])
        eq_(200, response.status_code)
        assert b'0 Replies' in response.content

        PostFactory(thread=t)
        PostFactory(thread=t)

        response = get(self.client, "forums.posts", args=[t.forum.slug, t.id])
        eq_(200, response.status_code)
        assert b'2 Replies' in response.content
Esempio n. 14
0
    def test_watch_thread(self):
        """Watch and unwatch a thread."""
        t = ThreadFactory()
        u = UserFactory()

        self.client.login(username=u.username, password='******')

        response = post(self.client, 'forums.watch_thread', {'watch': 'yes'},
                        args=[t.forum.slug, t.id])
        self.assertContains(response, 'Stop watching this thread')

        response = post(self.client, 'forums.watch_thread', {'watch': 'no'},
                        args=[t.forum.slug, t.id])
        self.assertNotContains(response, 'Stop watching this thread')
Esempio n. 15
0
    def test_preview_reply(self):
        """Preview a reply."""
        t = ThreadFactory()
        u = t.creator

        content = 'Full of awesome.'
        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.reply',
                        {'content': content, 'preview': 'any string'},
                        args=[t.forum.slug, t.id])
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(content, doc('#post-preview div.content').text())
        eq_(1, t.post_set.count())
Esempio n. 16
0
    def test_posts_fr(self):
        """Posts render for [fr] locale."""
        t = ThreadFactory()

        response = get(
            self.client, "forums.posts", args=[t.forum.slug, t.id], locale="fr"
        )
        eq_(200, response.status_code)
        eq_(
            "{c}/fr/forums/{f}/{t}".format(
                c=settings.CANONICAL_URL, f=t.forum.slug, t=t.id
            ),
            pq(response.content)('link[rel="canonical"]')[0].attrib["href"],
        )
Esempio n. 17
0
    def test_move_updates_last_posts(self):
        # Moving the thread containing a forum's last post to a new
        # forum should update the last_post of both
        # forums. Consequently, deleting the last post shouldn't
        # delete the old forum. [bug 588994]

        # Setup forum to move latest thread from.
        old_forum = ForumFactory()
        t1 = ThreadFactory(forum=old_forum, posts=[])
        p1 = PostFactory(thread=t1, created=YESTERDAY)
        t2 = ThreadFactory(forum=old_forum, posts=[])
        p2 = PostFactory(thread=t2)  # Newest post of all.

        # Setup forum to move latest thread to.
        new_forum = ForumFactory()
        t3 = ThreadFactory(forum=new_forum, posts=[])
        p3 = PostFactory(thread=t3, created=YESTERDAY)

        # Verify the last_post's are correct.
        eq_(p2, Forum.objects.get(id=old_forum.id).last_post)
        eq_(p3, Forum.objects.get(id=new_forum.id).last_post)

        # Move the t2 thread.
        t2 = Thread.objects.get(id=t2.id)
        t2.forum = new_forum
        t2.save()

        # Old forum's last_post updated?
        eq_(p1.id, Forum.objects.get(id=old_forum.id).last_post_id)

        # New forum's last_post updated?
        eq_(p2.id, Forum.objects.get(id=new_forum.id).last_post_id)

        # Delete the post, and both forums should still exist:
        p2.delete()
        eq_(1, Forum.objects.filter(id=old_forum.id).count())
        eq_(1, Forum.objects.filter(id=new_forum.id).count())
Esempio n. 18
0
    def test_youtube_in_post(self):
        """Verify youtube video embedding."""
        u = UserFactory()
        t = ThreadFactory()

        self.client.login(username=u.username, password="******")
        response = post(
            self.client,
            "forums.reply",
            {"content": "[[V:http://www.youtube.com/watch?v=oHg5SJYRHA0]]"},
            args=[t.forum.slug, t.id],
        )

        doc = pq(response.content)
        assert doc("iframe")[0].attrib["src"].startswith("//www.youtube.com/embed/oHg5SJYRHA0")
Esempio n. 19
0
    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        t = ThreadFactory()
        u = UserFactory()

        self.client.login(username=u.username, password='******')

        post(self.client, 'forums.watch_thread', {'watch': 'yes'}, args=[t.forum.slug, t.id])
        assert NewPostEvent.is_notifying(u, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(u, t.forum)

        post(self.client, 'forums.watch_thread', {'watch': 'no'},
             args=[t.forum.slug, t.id])
        assert not NewPostEvent.is_notifying(u, t)
Esempio n. 20
0
    def test_youtube_in_post(self):
        """Verify youtube video embedding."""
        u = UserFactory()
        t = ThreadFactory()

        self.client.login(username=u.username, password='******')
        response = post(
            self.client,
            'forums.reply',
            {'content': '[[V:http://www.youtube.com/watch?v=oHg5SJYRHA0]]'},
            args=[t.forum.slug, t.id])

        doc = pq(response.content)
        assert doc('iframe')[0].attrib['src'].startswith(
            '//www.youtube.com/embed/oHg5SJYRHA0')
Esempio n. 21
0
    def test_forums_filter_updated(self):
        """Filter for updated date."""
        post_updated_ds = datetime(2010, 5, 3, 12, 00)

        thread1 = ThreadFactory(title=u't1 audio')
        PostFactory(thread=thread1, created=post_updated_ds)

        thread2 = ThreadFactory(title=u't2 audio')
        PostFactory(thread=thread2, created=(post_updated_ds + timedelta(days=2)))

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json',
              'sortby': 1, 'updated_date': '05/04/2010'}

        qs['updated'] = constants.INTERVAL_BEFORE
        response = self.client.get(reverse('search.advanced'), qs)
        results = json.loads(response.content)['results']
        eq_([thread1.get_absolute_url()], [r['url'] for r in results])

        qs['updated'] = constants.INTERVAL_AFTER
        response = self.client.get(reverse('search.advanced'), qs)
        results = json.loads(response.content)['results']
        eq_([thread2.get_absolute_url()], [r['url'] for r in results])
Esempio n. 22
0
    def test_only_show_wiki_and_questions(self):
        """Tests that the simple search doesn't show forums

        This verifies that we're only showing documents of the type
        that should be shown and that the filters on model are working
        correctly.

        Bug #767394

        """
        p = ProductFactory(slug=u'desktop')
        ques = QuestionFactory(title=u'audio', product=p)
        ans = AnswerFactory(question=ques, content=u'volume')
        AnswerVoteFactory(answer=ans, helpful=True)

        doc = DocumentFactory(title=u'audio', locale=u'en-US', category=10)
        doc.products.add(p)
        RevisionFactory(document=doc, is_approved=True)

        thread1 = ThreadFactory(title=u'audio')
        PostFactory(thread=thread1)

        self.refresh()

        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json'})

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 2)

        # Archive the article and question. They should no longer appear
        # in simple search results.
        ques.is_archived = True
        ques.save()
        doc.is_archived = True
        doc.save()

        self.refresh()

        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json'})

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 0)
Esempio n. 23
0
    def test_updated_invalid(self):
        """Invalid updated_date is ignored."""
        thread1 = ThreadFactory()
        PostFactory(thread=thread1)

        self.refresh()

        qs = {
            "a": 1,
            "w": 4,
            "format": "json",
            "updated": 1,
            "updated_date": "invalid"
        }
        response = self.client.get(reverse("search.advanced"), qs)
        eq_(1, json.loads(response.content)["total"])
Esempio n. 24
0
    def test_watch_thread(self):
        """Watch and unwatch a thread."""
        t = ThreadFactory()
        u = UserFactory()

        self.client.login(username=u.username, password="******")

        response = post(
            self.client, "forums.watch_thread", {"watch": "yes"}, args=[t.forum.slug, t.id],
        )
        self.assertContains(response, "Stop watching this thread")

        response = post(
            self.client, "forums.watch_thread", {"watch": "no"}, args=[t.forum.slug, t.id],
        )
        self.assertNotContains(response, "Stop watching this thread")
Esempio n. 25
0
    def test_edit_thread_errors(self):
        """Editing thread with too short of a title shows errors."""
        t = ThreadFactory()
        creator = t.creator

        self.client.login(username=creator.username, password="******")
        response = post(
            self.client, "forums.edit_thread", {"title": "wha?"}, args=[t.forum.slug, t.id],
        )

        doc = pq(response.content)
        errors = doc("ul.errorlist li a")
        eq_(
            errors[0].text,
            "Your title is too short (4 characters). " + "It must be at least 5 characters.",
        )
Esempio n. 26
0
    def test_watch_forum_then_new_post_as_self(self, get_current):
        """Watching a forum and replying as myself should not send email."""
        get_current.return_value.domain = 'testserver'

        t = ThreadFactory()
        f = t.forum
        PostFactory(thread=t)
        watcher = UserFactory()

        self._toggle_watch_forum_as(f, watcher, turn_on=True)
        self.client.login(username=watcher.username, password='******')
        post(self.client,
             'forums.reply', {'content': 'a post'},
             args=[f.slug, t.id])
        # Assert no email is sent.
        assert not mail.outbox
Esempio n. 27
0
    def test_updated_invalid(self):
        """Invalid updated_date is ignored."""
        thread1 = ThreadFactory()
        PostFactory(thread=thread1)

        self.refresh()

        qs = {
            'a': 1,
            'w': 4,
            'format': 'json',
            'updated': 1,
            'updated_date': 'invalid'
        }
        response = self.client.get(reverse('search.advanced'), qs)
        eq_(1, json.loads(response.content)['total'])
Esempio n. 28
0
    def test_preview_reply(self):
        """Preview a reply."""
        t = ThreadFactory()
        u = t.creator

        content = "Full of awesome."
        self.client.login(username=u.username, password="******")
        response = post(
            self.client,
            "forums.reply",
            {"content": content, "preview": "any string"},
            args=[t.forum.slug, t.id],
        )
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(content, doc("#post-preview div.content").text())
        eq_(1, t.post_set.count())
Esempio n. 29
0
    def test_new_thread_without_view_permission(self):
        """Making a new thread without view permission should 404."""
        rforum = RestrictedForumFactory()
        ThreadFactory(forum=rforum)
        u = UserFactory()

        self.client.login(username=u.username, password="******")
        response = post(
            self.client,
            "forums.new_thread",
            {
                "title": "Blahs",
                "content": "Blahs"
            },
            args=[rforum.slug],
        )
        eq_(404, response.status_code)
Esempio n. 30
0
    def test_edit_thread_moderator(self):
        """Editing post as a moderator works."""
        t = ThreadFactory()
        f = t.forum
        u = UserFactory()
        g = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename='forums_forum.thread_edit_forum', content_type=ct,
                          object_id=f.id, group=g)
        g.user_set.add(u)

        self.client.login(username=u.username, password='******')
        r = post(self.client, 'forums.edit_thread',
                 {'title': 'new title'}, args=[f.slug, t.id])
        eq_(200, r.status_code)
        edited_t = Thread.objects.get(id=t.id)
        eq_('new title', edited_t.title)