Esempio n. 1
0
 def test_replies_count(self):
     # The Thread.replies value should remain one less than the
     # number of posts in the thread.
     t = ThreadFactory(posts=[{}, {}, {}])
     old = t.replies
     eq_(2, old)
     t.new_post(author=t.creator, content='test').save()
     eq_(old + 1, t.replies)
Esempio n. 2
0
    def test_posts_thread_belongs_to_forum(self):
        """Posts view - redirect if thread does not belong to forum."""
        f = ForumFactory()
        t = ThreadFactory()  # Thread belongs to a different forum

        r = get(self.client, 'forums.posts', args=[f.slug, t.id])
        eq_(200, r.status_code)
        u = r.redirect_chain[0][0]
        assert u.endswith(t.get_absolute_url())
Esempio n. 3
0
 def test_thread_last_post_url(self):
     t = ThreadFactory()
     lp = t.last_post
     f = t.forum
     url = t.get_last_post_url()
     assert f.slug in url
     assert str(t.id) in url
     assert '#post-%s' % lp.id in url
     assert 'last=%s' % lp.id in url
Esempio n. 4
0
 def test_new_post_updates_forum(self):
     # Saving a new post should update the last_post key in the
     # forum to point to the new post.
     t = ThreadFactory()
     PostFactory(thread=t)
     p = t.new_post(author=t.creator, content='another update')
     p.save()
     f = Forum.objects.get(id=t.forum_id)
     eq_(p.id, f.last_post_id)
Esempio n. 5
0
 def test_new_post_updates_thread(self):
     # Saving a new post in a thread should update the last_post
     # key in that thread to point to the new post.
     t = ThreadFactory()
     PostFactory(thread=t)
     p = t.new_post(author=t.creator, content='an update')
     p.save()
     t = Thread.objects.get(id=t.id)
     eq_(p.id, t.last_post_id)
Esempio n. 6
0
    def test_save_old_thread_created(self):
        """Saving an old thread should not change its created date."""
        t = ThreadFactory(created=YESTERDAY)
        t = Thread.objects.get(id=t.id)
        created = t.created

        # Now make an update to the thread and resave. Created shouldn't change.
        t.title = 'new title'
        t.save()
        t = Thread.objects.get(id=t.id)
        eq_(created, t.created)
Esempio n. 7
0
    def test_discussion_filter_sticky_locked(self):
        """Filter for locked and sticky threads."""
        thread1 = ThreadFactory(title=u"audio", is_locked=True, is_sticky=True)
        PostFactory(thread=thread1)

        self.refresh()

        qs = {"a": 1, "w": 4, "format": "json", "thread_type": (1, 2)}
        response = self.client.get(reverse("search.advanced"), qs)
        result = json.loads(response.content)["results"][0]
        eq_(thread1.get_absolute_url(), result["url"])
Esempio n. 8
0
 def test_thread_last_page(self):
     """Thread's last_page property is accurate."""
     t = ThreadFactory()
     # Format: (# replies, # of pages to expect)
     test_data = ((t.replies, 1),  # Test default
                  (50, 3),  # Test a large number
                  (19, 1),  # Test off-by-one error, low
                  (20, 2))  # Test off-by-one error, high
     for replies, pages in test_data:
         t.replies = replies
         eq_(t.last_page, pages)
Esempio n. 9
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. 10
0
    def test_delete_thread_with_last_forum_post(self):
        # Deleting the thread with a forum's last post should update
        # the last_post field on the forum
        t = ThreadFactory()
        f = t.forum
        last_post = f.last_post

        # add a new thread and post, verify last_post updated
        t = ThreadFactory(title='test', forum=f, posts=[])
        p = PostFactory(thread=t, content='test', author=t.creator)
        f = Forum.objects.get(id=f.id)
        eq_(f.last_post.id, p.id)

        # delete the post, verify last_post updated
        t.delete()
        f = Forum.objects.get(id=f.id)
        eq_(f.last_post.id, last_post.id)
        eq_(Thread.objects.filter(pk=t.id).count(), 0)
Esempio n. 11
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. 12
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. 13
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. 14
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="desktop")
        ques = QuestionFactory(title="audio", product=p)
        ans = AnswerFactory(question=ques, content="volume")
        AnswerVoteFactory(answer=ans, helpful=True)

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

        thread1 = ThreadFactory(title="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. 15
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. 16
0
    def test_admin_delete_user_with_watched_thread(self, get_current):
        """Test the admin delete view for a user with a watched thread."""
        get_current.return_value.domain = 'testserver'

        t = ThreadFactory()
        u = t.creator
        watcher = UserFactory()
        admin_user = UserFactory(is_staff=True, is_superuser=True)

        self.client.login(username=admin_user.username, password='******')
        self._toggle_watch_thread_as(t, watcher, turn_on=True)
        url = reverse('admin:auth_user_delete', args=[u.id])
        request = RequestFactory().get(url)
        request.user = admin_user
        request.session = self.client.session
        # The following blows up without our monkeypatch.
        ModelAdmin(User, admin.site).delete_view(request, str(u.id))
Esempio n. 17
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. 18
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)
Esempio n. 19
0
    def test_delete_thread_belongs_to_forum(self):
        """Delete thread action - thread belongs to forum."""
        f = ForumFactory()
        t = ThreadFactory()  # Thread belongs to a different forum
        u = UserFactory()

        # Give the user the permission to delete threads.
        g = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename='forums_forum.thread_delete_forum',
                          content_type=ct, object_id=f.id, group=g)
        PermissionFactory(codename='forums_forum.thread_delete_forum',
                          content_type=ct, object_id=t.forum.id, group=g)
        g.user_set.add(u)

        self.client.login(username=u.username, password='******')
        r = get(self.client, 'forums.delete_thread', args=[f.slug, t.id])
        eq_(404, r.status_code)
Esempio n. 20
0
    def test_added(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)

        # Saving a new post in a thread doesn't create a new
        # document in the index.  Therefore, the count remains 1.
        #
        # TODO: This is ambiguous: it's not clear whether we correctly
        # updated the document in the index or whether the post_save
        # hook didn't kick off.  Need a better test.
        PostFactory(thread=new_thread)
        self.refresh()
        eq_(ThreadMappingType.search().count(), 1)
Esempio n. 21
0
    def test_forums_search(self):
        """This tests whether forum posts show up in searches"""
        thread1 = ThreadFactory(title=u'crash')
        PostFactory(thread=thread1)

        self.refresh()

        response = self.client.get(reverse('search.advanced'), {
            'author': '', 'created': '0', 'created_date': '',
            'updated': '0', 'updated_date': '', 'sortby': '0',
            'a': '1', 'w': '4', 'q': 'crash',
            'format': 'json'
        })

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 1)
Esempio n. 22
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. 23
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. 24
0
    def test_thread_is_reindexed_on_username_change(self):
        search = ThreadMappingType.search()

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

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

        # Change the username and verify the index.
        u.username = '******'
        u.save()
        self.refresh()
        eq_(
            search.query(post_title='hello')[0]['post_author_ord'],
            [u'walter'])
Esempio n. 25
0
    def test_post_absolute_url(self):
        t = ThreadFactory(posts=[])

        # Fill out the first page with posts from yesterday.
        p1 = PostFactory(thread=t, created=YESTERDAY)
        PostFactory.create_batch(POSTS_PER_PAGE - 1, created=YESTERDAY, thread=t)
        # Second page post from today.
        p2 = PostFactory(thread=t)

        url = reverse('forums.posts',
                      kwargs={'forum_slug': p1.thread.forum.slug,
                              'thread_id': p1.thread.id})
        eq_(urlparams(url, hash='post-%s' % p1.id), p1.get_absolute_url())

        url = reverse('forums.posts',
                      kwargs={'forum_slug': p2.thread.forum.slug,
                              'thread_id': p2.thread.id})
        exp_ = urlparams(url, hash='post-%s' % p2.id, page=2)
        eq_(exp_, p2.get_absolute_url())
Esempio n. 26
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. 27
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. 28
0
    def test_edit_post_belongs_to_thread_and_forum(self):
        # Edit post action - post belongs to thread and thread belongs
        # to forum.
        f = ForumFactory()
        t = ThreadFactory(forum=f)
        # Post belongs to a different forum and thread.
        p = PostFactory()
        u = p.author

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

        # Post isn't in the passed forum:
        r = get(self.client, 'forums.edit_post',
                args=[f.slug, p.thread.id, p.id])
        eq_(404, r.status_code)

        # Post isn't in the passed thread:
        r = get(self.client, 'forums.edit_post',
                args=[p.thread.forum.slug, t.id, p.id])
        eq_(404, r.status_code)
Esempio n. 29
0
    def test_move_thread(self):
        """Move a thread."""
        t = ThreadFactory()
        f = ForumFactory()
        u = UserFactory()
        g = GroupFactory()

        # Give the user permission to move threads between the two forums.
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename='forums_forum.thread_move_forum', content_type=ct,
                          object_id=f.id, group=g)
        PermissionFactory(codename='forums_forum.thread_move_forum', content_type=ct,
                          object_id=t.forum.id, group=g)
        g.user_set.add(u)

        self.client.login(username=u.username, password='******')
        response = post(self.client, 'forums.move_thread',
                        {'forum': f.id},
                        args=[t.forum.slug, t.id])
        eq_(200, response.status_code)
        t = Thread.objects.get(pk=t.pk)
        eq_(f.id, t.forum.id)
Esempio n. 30
0
    def test_discussion_filter_author(self):
        """Filter by author in discussion forums."""
        author_vals = (
            ('DoesNotExist', 0),
            ('admin', 1),
            ('jsocol', 4),
        )

        for name, number in author_vals:
            u = UserFactory(username=name)
            for i in range(number):
                thread1 = ThreadFactory(title=u'audio')
                PostFactory(thread=thread1, author=u)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json'}

        for author, total in author_vals:
            qs.update({'author': author})
            response = self.client.get(reverse('search.advanced'), qs)
            eq_(total, json.loads(response.content)['total'])
Esempio n. 31
0
    def test_discussion_filter_author(self):
        """Filter by author in discussion forums."""
        author_vals = (
            ("DoesNotExist", 0),
            ("admin", 1),
            ("jsocol", 4),
        )

        for name, number in author_vals:
            u = UserFactory(username=name)
            for i in range(number):
                thread1 = ThreadFactory(title="audio")
                PostFactory(thread=thread1, author=u)

        self.refresh()

        qs = {"a": 1, "w": 4, "format": "json"}

        for author, total in author_vals:
            qs.update({"author": author})
            response = self.client.get(reverse("search.advanced"), qs)
            eq_(total, json.loads(response.content)["total"])
Esempio n. 32
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. 33
0
    def test_delete_thread_with_last_forum_post(self):
        # Deleting the thread with a forum's last post should update
        # the last_post field on the forum
        t = ThreadFactory()
        f = t.forum
        last_post = f.last_post

        # add a new thread and post, verify last_post updated
        t = ThreadFactory(title='test', forum=f, posts=[])
        p = PostFactory(thread=t, content='test', author=t.creator)
        f = Forum.objects.get(id=f.id)
        eq_(f.last_post.id, p.id)

        # delete the post, verify last_post updated
        t.delete()
        f = Forum.objects.get(id=f.id)
        eq_(f.last_post.id, last_post.id)
        eq_(Thread.objects.filter(pk=t.id).count(), 0)
Esempio n. 34
0
    def test_delete_post_belongs_to_thread_and_forum(self):
        # Delete post action - post belongs to thread and thread
        # belongs to forum.
        f = ForumFactory()
        t = ThreadFactory(forum=f)
        # Post belongs to a different forum and thread.
        p = PostFactory()
        u = p.author

        # Give the user the permission to delete posts.
        g = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(
            codename="forums_forum.post_delete_forum",
            content_type=ct,
            object_id=p.thread.forum_id,
            group=g,
        )
        PermissionFactory(codename="forums_forum.post_delete_forum",
                          content_type=ct,
                          object_id=f.id,
                          group=g)
        g.user_set.add(u)

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

        # Post isn't in the passed forum:
        r = get(self.client,
                "forums.delete_post",
                args=[f.slug, p.thread.id, p.id])
        eq_(404, r.status_code)

        # Post isn't in the passed thread:
        r = get(self.client,
                "forums.delete_post",
                args=[p.thread.forum.slug, t.id, p.id])
        eq_(404, r.status_code)
Esempio n. 35
0
    def test_sticky_thread_belongs_to_forum(self):
        """Sticky action - thread belongs to forum."""
        f = ForumFactory()
        t = ThreadFactory()  # Thread belongs to a different forum
        u = UserFactory()

        # Give the user the permission to sticky threads.
        g = GroupFactory()
        ct = ContentType.objects.get_for_model(f)
        PermissionFactory(codename="forums_forum.thread_sticky_forum",
                          content_type=ct,
                          object_id=f.id,
                          group=g)
        PermissionFactory(
            codename="forums_forum.thread_sticky_forum",
            content_type=ct,
            object_id=t.forum.id,
            group=g,
        )
        g.user_set.add(u)

        self.client.login(username=u.username, password="******")
        r = post(self.client, "forums.sticky_thread", {}, args=[f.slug, t.id])
        eq_(404, r.status_code)
Esempio n. 36
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. 37
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. 38
0
 def test_sorting_replies(self):
     """Sorting threads by replies."""
     ThreadFactory(posts=[{}, {}, {}])
     ThreadFactory()
     threads = sort_threads(Thread.objects, 4)
     self.assertTrue(threads[0].replies <= threads[1].replies)
Esempio n. 39
0
    def test_forums_thread_created(self):
        """Tests created/created_date filtering for forums"""
        post_created_ds = datetime(2010, 1, 1, 12, 00)
        thread1 = ThreadFactory(title="crash", created=post_created_ds)
        PostFactory(thread=thread1,
                    created=(post_created_ds + timedelta(hours=1)))

        self.refresh()

        # The thread/post should not show up in results for items
        # created AFTER 1/12/2010.
        response = self.client.get(
            reverse("search.advanced"),
            {
                "author": "",
                "created": "2",
                "created_date": "01/12/2010",
                "updated": "0",
                "updated_date": "",
                "sortby": "0",
                "a": "1",
                "w": "4",
                "q": "crash",
                "format": "json",
            },
        )

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content["total"], 0)

        # The thread/post should show up in results for items created
        # AFTER 1/1/2010.
        response = self.client.get(
            reverse("search.advanced"),
            {
                "author": "",
                "created": "2",
                "created_date": "01/01/2010",
                "updated": "0",
                "updated_date": "",
                "sortby": "0",
                "a": "1",
                "w": "4",
                "q": "crash",
                "format": "json",
            },
        )

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content["total"], 1)

        # The thread/post should show up in results for items created
        # BEFORE 1/12/2010.
        response = self.client.get(
            reverse("search.advanced"),
            {
                "author": "",
                "created": "1",
                "created_date": "01/12/2010",
                "updated": "0",
                "updated_date": "",
                "sortby": "0",
                "a": "1",
                "w": "4",
                "q": "crash",
                "format": "json",
            },
        )

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content["total"], 1)

        # The thread/post should NOT show up in results for items
        # created BEFORE 12/31/2009.
        response = self.client.get(
            reverse("search.advanced"),
            {
                "author": "",
                "created": "1",
                "created_date": "12/31/2009",
                "updated": "0",
                "updated_date": "",
                "sortby": "0",
                "a": "1",
                "w": "4",
                "q": "crash",
                "format": "json",
            },
        )

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content["total"], 0)
Esempio n. 40
0
    def test_forums_search_authorized_forums_specifying_forums(self):
        """Only authorized people can search certain forums they specified"""
        # Create two threads: one in a restricted forum and one not.
        forum1 = ForumFactory(name="ou812forum")
        thread1 = ThreadFactory(forum=forum1)
        PostFactory(thread=thread1, content="audio")

        forum2 = RestrictedForumFactory(name="restrictedkeepout")
        thread2 = ThreadFactory(forum=forum2)
        PostFactory(thread=thread2, content="audio restricted")

        self.refresh()

        # Do a search as an anonymous user and specify both
        # forums. Should only see the post from the unrestricted
        # forum.
        response = self.client.get(
            reverse("search.advanced"),
            {
                "author": "",
                "created": "0",
                "created_date": "",
                "updated": "0",
                "updated_date": "",
                "sortby": "0",
                "forum": [forum1.id, forum2.id],
                "a": "1",
                "w": "4",
                "q": "audio",
                "format": "json",
            },
        )

        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content["total"], 1)

        # Do a search as an authorized user and specify both
        # forums. Should see both posts.
        u = UserFactory()
        g = GroupFactory()
        g.user_set.add(u)
        ct = ContentType.objects.get_for_model(forum2)
        PermissionFactory(codename="forums_forum.view_in_forum",
                          content_type=ct,
                          object_id=forum2.id,
                          group=g)

        self.client.login(username=u.username, password="******")
        response = self.client.get(
            reverse("search.advanced"),
            {
                "author": "",
                "created": "0",
                "created_date": "",
                "updated": "0",
                "updated_date": "",
                "sortby": "0",
                "forum": [forum1.id, forum2.id],
                "a": "1",
                "w": "4",
                "q": "audio",
                "format": "json",
            },
        )

        # Sees both results
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content["total"], 2)
Esempio n. 41
0
 def test_delete_removes_watches(self):
     t = ThreadFactory()
     NewPostEvent.notify('*****@*****.**', t)
     assert NewPostEvent.is_notifying('*****@*****.**', t)
     t.delete()
     assert not NewPostEvent.is_notifying('*****@*****.**', t)
Esempio n. 42
0
 def test_unlocked_thread(self):
     unlocked = ThreadFactory()
     user = UserFactory()
     # This should not raise an exception
     unlocked.new_post(author=user, content='empty')
Esempio n. 43
0
    def test_thread_absolute_url(self):
        t = ThreadFactory()

        eq_('/forums/%s/%s' % (t.forum.slug, t.id),
            t.get_absolute_url())
Esempio n. 44
0
 def test_locked_thread(self):
     """Trying to reply to a locked thread should raise an exception."""
     locked = ThreadFactory(is_locked=True)
     user = UserFactory()
     # This should raise an exception
     locked.new_post(author=user, content='empty')
Esempio n. 45
0
 def test_locked_thread(self):
     """Trying to reply to a locked thread should raise an exception."""
     locked = ThreadFactory(is_locked=True)
     user = UserFactory()
     # This should raise an exception
     locked.new_post(author=user, content='empty')
Esempio n. 46
0
 def test_unlocked_thread(self):
     unlocked = ThreadFactory()
     user = UserFactory()
     # This should not raise an exception
     unlocked.new_post(author=user, content='empty')
Esempio n. 47
0
 def test_delete_last_and_only_post_in_thread(self):
     """Deleting the only post in a thread should delete the thread"""
     t = ThreadFactory()
     eq_(1, t.post_set.count())
     t.delete()
     eq_(0, Thread.objects.filter(pk=t.id).count())