示例#1
0
 def test_sorting_creator(self):
     """Sorting threads by creator."""
     thread(creator=user(username='******', save=True), save=True)
     thread(creator=user(username='******', save=True), save=True)
     threads = sort_threads(Thread.objects, 3, 1)
     self.assert_(threads[0].creator.username >=
                  threads[1].creator.username)
示例#2
0
 def test_sorting_creator(self):
     """Sorting threads by creator."""
     thread(creator=user(username='******', save=True), save=True)
     thread(creator=user(username='******', save=True), save=True)
     threads = sort_threads(Thread.objects, 3, 1)
     self.assert_(
         threads[0].creator.username >= threads[1].creator.username)
示例#3
0
    def test_forums_filter_updated(self):
        """Filter for updated date."""
        post_updated_ds = datetime(2010, 5, 3, 12, 00)

        thread1 = thread(title=u't1 audio', save=True)
        post(thread=thread1, created=post_updated_ds, save=True)

        thread2 = thread(title=u't2 audio', save=True)
        post(thread=thread2,
             created=(post_updated_ds + timedelta(days=2)),
             save=True)

        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'), 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'), qs)
        results = json.loads(response.content)['results']
        eq_([thread2.get_absolute_url()], [r['url'] for r in results])
示例#4
0
    def test_forums_filter_updated(self):
        """Filter for updated date."""
        post_updated_ds = datetime(2010, 5, 3, 12, 00)

        thread1 = thread(title=u't1 audio', save=True)
        post(thread=thread1, created=post_updated_ds, save=True)

        thread2 = thread(title=u't2 audio', save=True)
        post(thread=thread2,
             created=(post_updated_ds + timedelta(days=2)),
             save=True)

        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'), 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'), qs)
        results = json.loads(response.content)['results']
        eq_([thread2.get_absolute_url()], [r['url'] for r in results])
示例#5
0
    def test_autowatch_reply(self, get_current):
        """Replying to a thread creates a watch."""
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = thread(save=True)
        t2 = thread(save=True)

        assert not NewPostEvent.is_notifying(u, t1)
        assert not NewPostEvent.is_notifying(u, t2)

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

        # If the poster has the forums_watch_after_reply setting set to True,
        # they will start watching threads they reply to.
        s = Setting.objects.create(user=u, name='forums_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'forums.reply', data, args=[t1.forum.slug, t1.pk])
        assert NewPostEvent.is_notifying(u, t1)

        # Setting forums_watch_after_reply back to False, now they shouldn't
        # start watching threads they reply to.
        s.value = 'False'
        s.save()
        post(self.client, 'forums.reply', data, args=[t2.forum.slug, t2.pk])
        assert not NewPostEvent.is_notifying(u, t2)
示例#6
0
    def test_autowatch_reply(self, get_current):
        """Replying to a thread creates a watch."""
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = thread(save=True)
        t2 = thread(save=True)

        assert not NewPostEvent.is_notifying(u, t1)
        assert not NewPostEvent.is_notifying(u, t2)

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

        # If the poster has the forums_watch_after_reply setting set to True,
        # they will start watching threads they reply to.
        s = Setting.objects.create(user=u,
                                   name='forums_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'forums.reply', data, args=[t1.forum.slug, t1.pk])
        assert NewPostEvent.is_notifying(u, t1)

        # Setting forums_watch_after_reply back to False, now they shouldn't
        # start watching threads they reply to.
        s.value = 'False'
        s.save()
        post(self.client, 'forums.reply', data, args=[t2.forum.slug, t2.pk])
        assert not NewPostEvent.is_notifying(u, t2)
示例#7
0
文件: test_es.py 项目: jdm/kitsune
    def test_discussion_filter_forum(self):
        """Filter by forum in discussion forums."""
        forum1 = forum(name=u"Forum 1", save=True)
        thread1 = thread(forum=forum1, title=u"audio 1", save=True)
        post(thread=thread1, save=True)

        forum2 = forum(name=u"Forum 2", save=True)
        thread2 = thread(forum=forum2, title=u"audio 2", save=True)
        post(thread=thread2, save=True)

        import kitsune.search.forms

        reload(kitsune.search.forms)
        import kitsune.search.views
        import kitsune.search.forms

        kitsune.search.views.SearchForm = kitsune.search.forms.SearchForm

        # Wait... reload? WTF is that about? What's going on here is
        # that SearchForm pulls the list of forums from the db **at
        # module load time**. Since we need it to include the two
        # forums we just created, we need to reload the module and
        # rebind it in kitsune.search.views. Otherwise when we go to get
        # cleaned_data from it, it ditches the forum data we so
        # lovingly put in our querystring and then our filters are
        # wrong and then this test FAILS.

        self.refresh()

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

        for forum_id in (forum1.id, forum2.id):
            qs["forum"] = int(forum_id)
            response = self.client.get(reverse("search"), qs)
            eq_(json.loads(response.content)["total"], 1)
示例#8
0
    def test_forums_search_authorized_forums(self):
        """Only authorized people can search certain forums"""
        # Create two threads: one in a restricted forum and one not.
        forum1 = forum(name=u'ou812forum', save=True)
        thread1 = thread(forum=forum1, save=True)
        post(thread=thread1, content=u'audio', save=True)

        forum2 = restricted_forum(name=u'restrictedkeepout', save=True)
        thread2 = thread(forum=forum2, save=True)
        post(thread=thread2, content=u'audio restricted', save=True)

        self.refresh()

        # Do a search as an anonymous user but don't specify the
        # forums to filter on. Should only see one of the posts.
        response = self.client.get(reverse('search'), {
            'author': '',
            'created': '0',
            'created_date': '',
            'updated': '0',
            'updated_date': '',
            'sortby': '0',
            '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 but don't specify the
        # forums to filter on. Should see both posts.
        u = user(save=True)
        g = group(save=True)
        g.user_set.add(u)
        ct = ContentType.objects.get_for_model(forum2)
        permission(codename='forums_forum.view_in_forum', content_type=ct,
                   object_id=forum2.id, group=g, save=True)

        self.client.login(username=u.username, password='******')
        response = self.client.get(reverse('search'), {
            'author': '',
            'created': '0',
            'created_date': '',
            'updated': '0',
            'updated_date': '',
            'sortby': '0',
            '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)
示例#9
0
    def test_forums_search_authorized_forums(self):
        """Only authorized people can search certain forums"""
        # Create two threads: one in a restricted forum and one not.
        forum1 = forum(name=u'ou812forum', save=True)
        thread1 = thread(forum=forum1, save=True)
        post(thread=thread1, content=u'audio', save=True)

        forum2 = restricted_forum(name=u'restrictedkeepout', save=True)
        thread2 = thread(forum=forum2, save=True)
        post(thread=thread2, content=u'audio restricted', save=True)

        self.refresh()

        # Do a search as an anonymous user but don't specify the
        # forums to filter on. Should only see one of the posts.
        response = self.client.get(reverse('search'), {
            'author': '',
            'created': '0',
            'created_date': '',
            'updated': '0',
            'updated_date': '',
            'sortby': '0',
            '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 but don't specify the
        # forums to filter on. Should see both posts.
        u = user(save=True)
        g = group(save=True)
        g.user_set.add(u)
        ct = ContentType.objects.get_for_model(forum2)
        permission(codename='forums_forum.view_in_forum', content_type=ct,
                   object_id=forum2.id, group=g, save=True)

        self.client.login(username=u.username, password='******')
        response = self.client.get(reverse('search'), {
            'author': '',
            'created': '0',
            'created_date': '',
            'updated': '0',
            'updated_date': '',
            'sortby': '0',
            '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)
示例#10
0
 def test_has_perm_or_owns_thread_edit(self):
     """Users can edit their own threads."""
     my_t = thread(save=True)
     me = my_t.creator
     other_t = thread(save=True)
     self.context['request'].user = me
     perm = 'forums_forum.thread_edit_forum'
     assert has_perm_or_owns(self.context, perm, my_t, self.forum_1)
     assert not has_perm_or_owns(self.context, perm, other_t, self.forum_1)
示例#11
0
 def test_has_perm_or_owns_thread_edit(self):
     """Users can edit their own threads."""
     my_t = thread(save=True)
     me = my_t.creator
     other_t = thread(save=True)
     self.context['request'].user = me
     perm = 'forums_forum.thread_edit_forum'
     assert has_perm_or_owns(self.context, perm, my_t, self.forum_1)
     assert not has_perm_or_owns(self.context, perm, other_t, self.forum_1)
示例#12
0
    def test_locked_thread(self):
        """Trying to reply to a locked thread should raise an exception."""
        locked = thread(is_locked=True, save=True)
        unlocked = thread(save=True)
        user1 = user(save=True)
        fn = lambda: locked.new_post(author=user1, content='empty')
        self.assertRaises(ThreadLockedError, fn)

        # This should not raise an exception.
        unlocked.new_post(author=user1, content='empty')
示例#13
0
    def test_threads_sort(self):
        """Ensure that threads are being sorted properly by date/time."""
        # Threads are sorted descending by last post date.
        f = forum(save=True)
        t1 = thread(forum=f, created=YESTERDAY, save=True)
        post(thread=t1, created=YESTERDAY, save=True)
        t2 = thread(forum=f, save=True)
        post(thread=t2, save=True)

        eq_(t2.id, ThreadsFeed().items(f)[0].id)
示例#14
0
    def test_locked_thread(self):
        """Trying to reply to a locked thread should raise an exception."""
        locked = thread(is_locked=True, save=True)
        unlocked = thread(save=True)
        user1 = user(save=True)
        fn = lambda: locked.new_post(author=user1, content='empty')
        self.assertRaises(ThreadLockedError, fn)

        # This should not raise an exception.
        unlocked.new_post(author=user1, content='empty')
示例#15
0
 def test_util_has_perm_or_owns_sanity(self):
     """Sanity check for access.has_perm_or_owns."""
     from kitsune.forums.tests import thread
     me = user(save=True)
     my_t = thread(creator=me, save=True)
     other_t = thread(save=True)
     perm = 'forums_forum.thread_edit_forum'
     allowed = access.has_perm_or_owns(me, perm, my_t, my_t.forum)
     eq_(allowed, True)
     allowed = access.has_perm_or_owns(me, perm, other_t, other_t.forum)
     eq_(allowed, False)
示例#16
0
    def test_new_thread_without_view_permission(self):
        """Making a new thread without view permission should 404."""
        rforum = restricted_forum()
        thread(forum=rforum, save=True)
        u = user(save=True)

        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)
示例#17
0
 def test_util_has_perm_or_owns_sanity(self):
     """Sanity check for access.has_perm_or_owns."""
     from kitsune.forums.tests import thread
     me = user(save=True)
     my_t = thread(creator=me, save=True)
     other_t = thread(save=True)
     perm = 'forums_forum.thread_edit_forum'
     allowed = access.has_perm_or_owns(me, perm, my_t, my_t.forum)
     eq_(allowed, True)
     allowed = access.has_perm_or_owns(me, perm, other_t, other_t.forum)
     eq_(allowed, False)
示例#18
0
    def test_recent_threads(self):
        """Verify the Community Discussions section."""
        f = forum(slug='contributors', save=True)
        thread(forum=f, title='we are SUMO!!!!!!', save=True)

        self.refresh()

        response = self.client.get(urlparams(reverse('community.home')))
        eq_(response.status_code, 200)
        doc = pq(response.content)
        eq_(1, len(doc('#recent-threads')))
        assert 'we are SUMO!' in doc('#recent-threads li').html()
示例#19
0
    def test_recent_threads(self):
        """Verify the Community Discussions section."""
        f = forum(slug='contributors', save=True)
        thread(forum=f, title='we are SUMO!!!!!!', save=True)

        self.refresh()

        response = self.client.get(urlparams(reverse('community.home')))
        eq_(response.status_code, 200)
        doc = pq(response.content)
        eq_(1, len(doc('#recent-threads')))
        assert 'we are SUMO!' in doc('#recent-threads li').html()
示例#20
0
    def test_watch_other_thread_then_reply(self):
        # Watching a different thread than the one we're replying to
        # shouldn't notify.
        t1 = thread(save=True)
        t2 = thread(save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_thread_as(t1, watcher, turn_on=True)
        self.client.login(username=poster.username, password="******")
        post(self.client, "forums.reply", {"content": "a post"}, args=[t2.forum.slug, t2.id])

        assert not mail.outbox
示例#21
0
    def test_watch_other_thread_then_reply(self):
        # Watching a different thread than the one we're replying to
        # shouldn't notify.
        t1 = thread(save=True)
        t2 = thread(save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_thread_as(t1, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client, 'forums.reply', {'content': 'a post'},
             args=[t2.forum.slug, t2.id])

        assert not mail.outbox
示例#22
0
    def test_new_thread_without_view_permission(self):
        """Making a new thread without view permission should 404."""
        rforum = restricted_forum()
        thread(forum=rforum, save=True)
        u = user(save=True)

        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)
示例#23
0
 def test_save_thread_no_created(self):
     """Saving a new thread should behave as if auto_add_now was set."""
     t = thread(forum=self.forum, title='foo', creator=self.user,
                save=True)
     t.save()
     now = datetime.now()
     self.assertDateTimeAlmostEqual(now, t.created, self.delta)
示例#24
0
    def test_forums_search(self):
        """This tests whether forum posts show up in searches"""
        thread1 = thread(title=u'crash', save=True)
        post(thread=thread1, save=True)

        self.refresh()

        response = self.client.get(
            reverse('search'), {
                '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)
示例#25
0
    def test_read_without_permission(self):
        """Listing posts without the view_in_forum permission should 404."""
        rforum = restricted_forum()
        t = thread(forum=rforum, save=True)

        response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id])
        eq_(404, response.status_code)
示例#26
0
 def test_save_thread_no_created(self):
     """Saving a new thread should behave as if auto_add_now was set."""
     t = thread(forum=self.forum, title='foo', creator=self.user,
                save=True)
     t.save()
     now = datetime.now()
     self.assertDateTimeAlmostEqual(now, t.created, self.delta)
示例#27
0
    def test_default_only_shows_wiki_and_questions(self):
        """Tests that the default 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 = product(slug=u'desktop', save=True)
        ques = question(title=u'audio', save=True)
        ques.products.add(p)
        ans = answer(question=ques, content=u'volume', save=True)
        answervote(answer=ans, helpful=True, save=True)

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

        thread1 = thread(title=u'audio', save=True)
        post(thread=thread1, save=True)

        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)
示例#28
0
    def test_default_only_shows_wiki_and_questions(self):
        """Tests that the default 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 = product(slug=u'desktop', save=True)
        ques = question(title=u'audio', save=True)
        ques.products.add(p)
        ans = answer(question=ques, content=u'volume', save=True)
        answervote(answer=ans, helpful=True, save=True)

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

        thread1 = thread(title=u'audio', save=True)
        post(thread=thread1, save=True)

        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)
示例#29
0
    def test_read_without_permission(self):
        """Listing posts without the view_in_forum permission should 404."""
        rforum = restricted_forum()
        t = thread(forum=rforum, save=True)

        response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id])
        eq_(404, response.status_code)
示例#30
0
    def test_delete_post_belongs_to_thread_and_forum(self):
        # Delete post action - post belongs to thread and thread
        # belongs to forum.
        f = forum(save=True)
        t = thread(forum=f, save=True)
        # Post belongs to a different forum and thread.
        p = forum_post(save=True)
        u = p.author

        # Give the user the permission to delete posts.
        g = group(save=True)
        ct = ContentType.objects.get_for_model(f)
        permission(codename='forums_forum.post_delete_forum',
                   content_type=ct, object_id=p.thread.forum_id, group=g,
                   save=True)
        permission(codename='forums_forum.post_delete_forum',
                   content_type=ct, object_id=f.id, group=g, save=True)
        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)
示例#31
0
    def test_watch_thread_then_reply(self, get_current):
        """The event fires and sends emails when watching a thread."""
        get_current.return_value.domain = 'testserver'

        t = thread(save=True)
        f = t.forum
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_thread_as(t, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client,
             'forums.reply', {'content': 'a post'},
             args=[t.forum.slug, t.id])

        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0],
                 to=[watcher.email],
                 subject='Re: {f} - {t}'.format(f=f, t=t))
        body = REPLY_EMAIL.format(username=poster.username,
                                  forum_slug=f.slug,
                                  thread=t.title,
                                  thread_id=t.id,
                                  post_id=p.id)
        starts_with(mail.outbox[0].body, body)
示例#32
0
    def test_watch_both_then_new_post(self, get_current):
        """Watching both forum and thread.

        Replying to a thread should send ONE email."""
        get_current.return_value.domain = 'testserver'

        t = thread(save=True)
        f = t.forum
        forum_post(thread=t, save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_forum_as(f, watcher, turn_on=True)
        self._toggle_watch_thread_as(t, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client, 'forums.reply', {'content': 'a post'},
             args=[f.slug, t.id])

        eq_(1, len(mail.outbox))
        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0], to=[watcher.email],
                 subject='Re: {f} - {t}'.format(f=f, t=t))
        body = REPLY_EMAIL.format(
            username=poster.username,
            forum_slug=f.slug,
            thread=t.title,
            thread_id=t.id,
            post_id=p.id)
        starts_with(mail.outbox[0].body, body)
示例#33
0
    def test_watch_both_then_new_post(self, get_current):
        """Watching both forum and thread.

        Replying to a thread should send ONE email."""
        get_current.return_value.domain = 'testserver'

        t = thread(save=True)
        f = t.forum
        forum_post(thread=t, save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_forum_as(f, watcher, turn_on=True)
        self._toggle_watch_thread_as(t, watcher, turn_on=True)
        self.client.login(username=poster.username, password='******')
        post(self.client,
             'forums.reply', {'content': 'a post'},
             args=[f.slug, t.id])

        eq_(1, len(mail.outbox))
        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0],
                 to=[watcher.email],
                 subject='Re: {f} - {t}'.format(f=f, t=t))
        body = REPLY_EMAIL.format(username=poster.username,
                                  forum_slug=f.slug,
                                  thread=t.title,
                                  thread_id=t.id,
                                  post_id=p.id)
        starts_with(mail.outbox[0].body, body)
示例#34
0
文件: test_es.py 项目: jdm/kitsune
    def test_forums_search(self):
        """This tests whether forum posts show up in searches"""
        thread1 = thread(title=u"crash", save=True)
        post(thread=thread1, save=True)

        self.refresh()

        response = self.client.get(
            reverse("search"),
            {
                "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)
示例#35
0
 def test_fire_on_reply(self, fire):
     """The event fires when there is a reply."""
     u = user(save=True)
     t = thread(save=True)
     self.client.login(username=u.username, password="******")
     post(self.client, "forums.reply", {"content": "a post"}, args=[t.forum.slug, t.id])
     # NewPostEvent.fire() is called.
     assert fire.called
示例#36
0
    def test_delete_last_and_only_post_in_thread(self):
        """Deleting the only post in a thread should delete the thread"""
        t = thread(save=True)
        post(thread=t, save=True)

        eq_(1, t.post_set.count())
        t.delete()
        eq_(0, Thread.objects.filter(pk=t.id).count())
示例#37
0
    def test_delete_last_and_only_post_in_thread(self):
        """Deleting the only post in a thread should delete the thread"""
        t = thread(save=True)
        post(thread=t, save=True)

        eq_(1, t.post_set.count())
        t.delete()
        eq_(0, Thread.objects.filter(pk=t.id).count())
示例#38
0
 def test_save_thread_created(self):
     # Saving a new thread that already has a created date should
     # respect that created date.
     created = datetime(1992, 1, 12, 9, 48, 23)
     t = thread(forum=self.forum, title='foo', creator=self.user,
                created=created, save=True)
     t.save()
     eq_(created, t.created)
示例#39
0
 def test_save_thread_created(self):
     # Saving a new thread that already has a created date should
     # respect that created date.
     created = datetime(1992, 1, 12, 9, 48, 23)
     t = thread(forum=self.forum, title='foo', creator=self.user,
                created=created, save=True)
     t.save()
     eq_(created, t.created)
示例#40
0
    def test_reply_thread_405(self):
        """Replying to a thread via a GET instead of a POST request."""
        t = thread(save=True)
        u = user(save=True)

        self.client.login(username=u.username, password='******')
        response = get(self.client, 'forums.reply', args=[t.forum.slug, t.id])
        eq_(405, response.status_code)
示例#41
0
 def test_update_forum_does_not_update_thread(self):
     # Updating/saving an old post in a forum should _not_ update
     # the last_post key in that forum.
     t = thread(save=True)
     old = post(thread=t, save=True)
     last = post(thread=t, save=True)
     old.content = 'updated content'
     old.save()
     eq_(last.id, t.forum.last_post_id)
示例#42
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 = thread(save=True)
     post(thread=t, save=True)
     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)
示例#43
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 = thread(save=True)
     post(thread=t, save=True)
     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)
示例#44
0
    def test_reply_thread_belongs_to_forum(self):
        """Reply action - thread belongs to forum."""
        f = forum(save=True)
        t = thread(save=True)  # Thread belongs to a different forum
        u = user(save=True)

        self.client.login(username=u.username, password='******')
        r = post(self.client, 'forums.reply', {}, args=[f.slug, t.id])
        eq_(404, r.status_code)
示例#45
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 = thread(save=True)
     post(thread=t, save=True)
     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)
示例#46
0
    def test_posts_sort(self):
        """Ensure that posts are being sorted properly by date/time."""
        t = thread(save=True)
        post(thread=t, created=YESTERDAY, save=True)
        post(thread=t, created=YESTERDAY, save=True)
        p = post(thread=t, save=True)

        # The newest post should be the first one listed.
        eq_(p.id, PostsFeed().items(t)[0].id)
示例#47
0
    def test_reply_thread_405(self):
        """Replying to a thread via a GET instead of a POST request."""
        t = thread(save=True)
        u = user(save=True)

        self.client.login(username=u.username, password='******')
        response = get(self.client, 'forums.reply',
                       args=[t.forum.slug, t.id])
        eq_(405, response.status_code)
示例#48
0
 def test_sorting_replies(self):
     """Sorting threads by replies."""
     t = thread(save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(save=True)
     threads = sort_threads(Thread.objects, 4)
     self.assert_(threads[0].replies <= threads[1].replies)
示例#49
0
    def test_discussion_filter_forum(self):
        """Filter by forum in discussion forums."""
        forum1 = forum(name=u'Forum 1', save=True)
        thread1 = thread(forum=forum1, title=u'audio 1', save=True)
        post(thread=thread1, save=True)

        forum2 = forum(name=u'Forum 2', save=True)
        thread2 = thread(forum=forum2, title=u'audio 2', save=True)
        post(thread=thread2, save=True)

        self.refresh()

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

        for forum_id in (forum1.id, forum2.id):
            qs['forum'] = int(forum_id)
            response = self.client.get(reverse('search'), qs)
            eq_(json.loads(response.content)['total'], 1)
示例#50
0
    def test_sticky_threads_first(self):
        # Sticky threads should come before non-sticky threads.
        t = post(save=True).thread
        sticky = thread(forum=t.forum, is_sticky=True, save=True)
        yesterday = datetime.now() - timedelta(days=1)
        post(thread=sticky, created=yesterday, save=True)

        # The older sticky thread shows up first.
        eq_(sticky.id, Thread.objects.all()[0].id)
示例#51
0
 def test_sorting_replies(self):
     """Sorting threads by replies."""
     t = thread(save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(save=True)
     threads = sort_threads(Thread.objects, 4)
     self.assert_(threads[0].replies <= threads[1].replies)
示例#52
0
    def test_sticky_threads_first(self):
        # Sticky threads should come before non-sticky threads.
        t = post(save=True).thread
        sticky = thread(forum=t.forum, is_sticky=True, save=True)
        yesterday = datetime.now() - timedelta(days=1)
        post(thread=sticky, created=yesterday, save=True)

        # The older sticky thread shows up first.
        eq_(sticky.id, Thread.objects.all()[0].id)
示例#53
0
 def test_update_forum_does_not_update_thread(self):
     # Updating/saving an old post in a forum should _not_ update
     # the last_post key in that forum.
     t = thread(save=True)
     old = post(thread=t, save=True)
     last = post(thread=t, save=True)
     old.content = 'updated content'
     old.save()
     eq_(last.id, t.forum.last_post_id)
示例#54
0
    def test_reply_thread_belongs_to_forum(self):
        """Reply action - thread belongs to forum."""
        f = forum(save=True)
        t = thread(save=True)  # Thread belongs to a different forum
        u = user(save=True)

        self.client.login(username=u.username, password='******')
        r = post(self.client, 'forums.reply', {}, args=[f.slug, t.id])
        eq_(404, r.status_code)
示例#55
0
    def test_long_title_truncated_in_crumbs(self):
        """A very long thread title gets truncated in the breadcrumbs"""
        t = thread(title='A thread with a very very long title', save=True)
        forum_post(thread=t, save=True)

        response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id])
        doc = pq(response.content)
        crumb = doc('#breadcrumbs li:last-child')
        eq_(crumb.text(), 'A thread with a very very ...')
示例#56
0
    def test_long_title_truncated_in_crumbs(self):
        """A very long thread title gets truncated in the breadcrumbs"""
        t = thread(title='A thread with a very very long title', save=True)
        forum_post(thread=t, save=True)

        response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id])
        doc = pq(response.content)
        crumb = doc('#breadcrumbs li:last-child')
        eq_(crumb.text(), 'A thread with a very very ...')
示例#57
0
    def test_posts_thread_belongs_to_forum(self):
        """Posts view - redirect if thread does not belong to forum."""
        f = forum(save=True)
        t = thread(save=True)  # 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())
示例#58
0
    def test_discussion_filter_forum(self):
        """Filter by forum in discussion forums."""
        forum1 = forum(name=u'Forum 1', save=True)
        thread1 = thread(forum=forum1, title=u'audio 1', save=True)
        post(thread=thread1, save=True)

        forum2 = forum(name=u'Forum 2', save=True)
        thread2 = thread(forum=forum2, title=u'audio 2', save=True)
        post(thread=thread2, save=True)

        self.refresh()

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

        for forum_id in (forum1.id, forum2.id):
            qs['forum'] = int(forum_id)
            response = self.client.get(reverse('search'), qs)
            eq_(json.loads(response.content)['total'], 1)
示例#59
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 = thread(save=True)
     post(thread=t, save=True)
     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)