예제 #1
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])
예제 #2
0
파일: test_es.py 프로젝트: atopal/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)
예제 #3
0
파일: test_es.py 프로젝트: LASarkar/kitsune
    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)
예제 #4
0
파일: test_es.py 프로젝트: LASarkar/kitsune
    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_front_page_only_shows_wiki_and_questions(self):
        """Tests that the front page 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

        """
        ques = question(title=u"audio", save=True)
        ques.tags.add(u"desktop")
        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(product(slug=u"desktop", save=True))
        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_tags": "desktop", "product": "desktop", "q": "audio", "format": "json"}
        )

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content["total"], 2)
예제 #6
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)
예제 #7
0
파일: test_es.py 프로젝트: LASarkar/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 search.forms
        reload(search.forms)
        import search.views
        import search.forms
        search.views.SearchForm = 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 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_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 = forum(save=True)
        t1 = thread(forum=old_forum, save=True)
        p1 = post(thread=t1, created=YESTERDAY, save=True)
        t2 = thread(forum=old_forum, save=True)
        p2 = post(thread=t2, save=True)  # Newest post of all.

        # Setup forum to move latest thread to.
        new_forum = forum(save=True)
        t3 = thread(forum=new_forum, save=True)
        p3 = post(thread=t3, created=YESTERDAY, save=True)

        # 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())
예제 #9
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)
예제 #10
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)

        import search.forms
        reload(search.forms)
        import search.views
        import search.forms
        search.views.SearchForm = 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 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)
예제 #11
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 = forum(save=True)
        t1 = thread(forum=old_forum, save=True)
        p1 = post(thread=t1, created=YESTERDAY, save=True)
        t2 = thread(forum=old_forum, save=True)
        p2 = post(thread=t2, save=True)  # Newest post of all.

        # Setup forum to move latest thread to.
        new_forum = forum(save=True)
        t3 = thread(forum=new_forum, save=True)
        p3 = post(thread=t3, created=YESTERDAY, save=True)

        # 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())
예제 #12
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.uncached.filter(pk=t.id).count())
예제 #13
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.uncached.filter(pk=t.id).count())
예제 #14
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)
예제 #15
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)
예제 #16
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)
예제 #17
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)
예제 #18
0
 def test_update_post_does_not_update_thread(self):
     # Updating/saving an old post in a thread should _not_ update
     # the last_post key in that thread.
     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, old.thread.last_post_id)
예제 #19
0
파일: test_posts.py 프로젝트: timmi/kitsune
 def test_update_post_does_not_update_thread(self):
     # Updating/saving an old post in a thread should _not_ update
     # the last_post key in that thread.
     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, old.thread.last_post_id)
예제 #20
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)
예제 #21
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)
예제 #22
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)
예제 #23
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)
예제 #24
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)
예제 #25
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)
예제 #26
0
    def test_updated_nonexistent(self):
        """updated is set while updated_date is left out of the query."""
        thread1 = thread(save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 2, 'format': 'json', 'updated': 1}
        response = self.client.get(reverse('search'), qs)
        eq_(response.status_code, 200)
예제 #27
0
 def test_thread_last_post_url(self):
     t = thread(save=True)
     post(thread=t, save=True)
     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
예제 #28
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)
예제 #29
0
 def test_thread_last_post_url(self):
     t = thread(save=True)
     post(thread=t, save=True)
     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
예제 #30
0
파일: test_es.py 프로젝트: atopal/kitsune
    def test_updated_invalid(self):
        """Invalid updated_date is ignored."""
        thread1 = thread(save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {"a": 1, "w": 4, "format": "json", "updated": 1, "updated_date": "invalid"}
        response = self.client.get(reverse("search"), qs)
        eq_(1, json.loads(response.content)["total"])
예제 #31
0
    def test_multi_feed_titling(self):
        """Ensure that titles are being applied properly to feeds."""
        t = thread(save=True)
        forum = t.forum
        post(thread=t, save=True)

        response = get(self.client, 'forums.threads', args=[forum.slug])
        doc = pq(response.content)
        eq_(ThreadsFeed().title(forum),
            doc('link[type="application/atom+xml"]')[0].attrib['title'])
예제 #32
0
파일: test_es.py 프로젝트: atopal/kitsune
    def test_updated_nonexistent(self):
        """updated is set while updated_date is left out of the query."""
        thread1 = thread(save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {"a": 1, "w": 2, "format": "json", "updated": 1}
        response = self.client.get(reverse("search"), qs)
        eq_(response.status_code, 200)
예제 #33
0
    def test_multi_feed_titling(self):
        """Ensure that titles are being applied properly to feeds."""
        t = thread(save=True)
        forum = t.forum
        post(thread=t, save=True)

        response = get(self.client, 'forums.threads', args=[forum.slug])
        doc = pq(response.content)
        eq_(ThreadsFeed().title(forum),
            doc('link[type="application/atom+xml"]')[0].attrib['title'])
예제 #34
0
파일: test_es.py 프로젝트: LASarkar/kitsune
    def test_updated_nonexistent(self):
        """updated is set while updated_date is left out of the query."""
        thread1 = thread(save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 2, 'format': 'json', 'updated': 1}
        response = self.client.get(reverse('search'), qs)
        eq_(response.status_code, 200)
예제 #35
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)
예제 #36
0
 def test_post_sorting(self):
     """Posts should be sorted chronologically."""
     t = thread(save=True)
     post(thread=t, created=datetime.now() - timedelta(days=1), save=True)
     post(thread=t, created=datetime.now() - timedelta(days=4), save=True)
     post(thread=t, created=datetime.now() - timedelta(days=7), save=True)
     post(thread=t, created=datetime.now() - timedelta(days=11), save=True)
     post(thread=t, save=True)
     posts = t.post_set.all()
     for i in range(len(posts) - 1):
         self.assert_(posts[i].created <= posts[i + 1].created)
예제 #37
0
    def test_updated_invalid(self):
        """Invalid updated_date is ignored."""
        thread1 = thread(save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json',
              'updated': 1, 'updated_date': 'invalid'}
        response = self.client.get(reverse('search'), qs)
        eq_(1, json.loads(response.content)['total'])
예제 #38
0
파일: test_es.py 프로젝트: atopal/kitsune
    def test_discussion_filter_locked(self):
        """Filter for locked threads."""
        thread1 = thread(title=u"audio", is_locked=True, save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {"a": 1, "w": 4, "format": "json", "thread_type": 2}
        response = self.client.get(reverse("search"), qs)
        results = json.loads(response.content)["results"]
        eq_(len(results), 1)
예제 #39
0
    def test_discussion_filter_locked(self):
        """Filter for locked threads."""
        thread1 = thread(title=u'audio', is_locked=True, save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json', 'thread_type': 2}
        response = self.client.get(reverse('search'), qs)
        results = json.loads(response.content)['results']
        eq_(len(results), 1)
예제 #40
0
파일: test_es.py 프로젝트: atopal/kitsune
    def test_discussion_filter_sticky_locked(self):
        """Filter for locked and sticky threads."""
        thread1 = thread(title=u"audio", is_locked=True, is_sticky=True, save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {"a": 1, "w": 4, "format": "json", "thread_type": (1, 2)}
        response = self.client.get(reverse("search"), qs)
        result = json.loads(response.content)["results"][0]
        eq_(thread1.get_absolute_url(), result["url"])
예제 #41
0
파일: test_es.py 프로젝트: LASarkar/kitsune
    def test_updated_invalid(self):
        """Invalid updated_date is ignored."""
        thread1 = thread(save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json',
              'updated': 1, 'updated_date': 'invalid'}
        response = self.client.get(reverse('search'), qs)
        eq_(1, json.loads(response.content)['total'])
예제 #42
0
 def test_post_sorting(self):
     """Posts should be sorted chronologically."""
     t = thread(save=True)
     post(thread=t, created=datetime.now() - timedelta(days=1), save=True)
     post(thread=t, created=datetime.now() - timedelta(days=4), save=True)
     post(thread=t, created=datetime.now() - timedelta(days=7), save=True)
     post(thread=t, created=datetime.now() - timedelta(days=11), save=True)
     post(thread=t, save=True)
     posts = t.post_set.all()
     for i in range(len(posts) - 1):
         self.assert_(posts[i].created <= posts[i + 1].created)
예제 #43
0
    def test_post_page(self):
        t = thread(save=True)
        # Fill out the first page with posts from yesterday.
        page1 = []
        for i in range(POSTS_PER_PAGE):
            page1.append(post(thread=t, created=YESTERDAY, save=True))
        # Second page post from today.
        p2 = post(thread=t, save=True)

        for p in page1:
            eq_(1, p.page)
        eq_(2, p2.page)
예제 #44
0
    def test_post_page(self):
        t = thread(save=True)
        # Fill out the first page with posts from yesterday.
        page1 = []
        for i in range(POSTS_PER_PAGE):
            page1.append(post(thread=t, created=YESTERDAY, save=True))
        # Second page post from today.
        p2 = post(thread=t, save=True)

        for p in page1:
            eq_(1, p.page)
        eq_(2, p2.page)
예제 #45
0
파일: test_es.py 프로젝트: LASarkar/kitsune
    def test_discussion_filter_locked(self):
        """Filter for locked threads."""
        thread1 = thread(title=u'audio', is_locked=True,
                         save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json', 'thread_type': 2}
        response = self.client.get(reverse('search'), qs)
        results = json.loads(response.content)['results']
        eq_(len(results), 1)
예제 #46
0
파일: test_es.py 프로젝트: LASarkar/kitsune
    def test_discussion_filter_sticky_locked(self):
        """Filter for locked and sticky threads."""
        thread1 = thread(title=u'audio', is_locked=True, is_sticky=True,
                         save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json', 'thread_type': (1, 2)}
        response = self.client.get(reverse('search'), qs)
        result = json.loads(response.content)['results'][0]
        eq_(thread1.get_absolute_url(), result['url'])
예제 #47
0
    def test_discussion_filter_sticky_locked(self):
        """Filter for locked and sticky threads."""
        thread1 = thread(title=u'audio', is_locked=True, is_sticky=True,
                         save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json', 'thread_type': (1, 2)}
        response = self.client.get(reverse('search'), qs)
        result = json.loads(response.content)['results'][0]
        eq_(thread1.get_absolute_url(), result['url'])
예제 #48
0
    def test_forums_search(self):
        """This tests whether forum posts show up in searches."""
        thread1 = thread(title=u'Why don\'t we spell crash backwards?')
        thread1.save()

        post1 = post(thread=thread1,
                     content=u'What, like hsarc?  That\'s silly.')
        post1.save()

        self.refresh()

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

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 1)
예제 #49
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)
예제 #50
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)
예제 #51
0
 def test_save_new_post_no_timestamps(self):
     # Saving a new post should behave as if auto_add_now was set on
     # created and auto_now set on updated.
     p = post(thread=self.thread, content='bar', author=self.user,
              save=True)
     now = datetime.now()
     self.assertDateTimeAlmostEqual(now, p.created, self.delta)
     self.assertDateTimeAlmostEqual(now, p.updated, self.delta)
예제 #52
0
 def test_sorting_last_post_desc(self):
     """Sorting threads by last_post descendingly."""
     t = thread(save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(created=datetime.now() - timedelta(days=1), save=True)
     threads = sort_threads(Thread.objects, 5, 1)
     self.assert_(
         threads[0].last_post.created >= threads[1].last_post.created)
예제 #53
0
 def test_sorting_last_post_desc(self):
     """Sorting threads by last_post descendingly."""
     t = thread(save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(created=datetime.now() - timedelta(days=1), save=True)
     threads = sort_threads(Thread.objects, 5, 1)
     self.assert_(threads[0].last_post.created >=
                  threads[1].last_post.created)
예제 #54
0
파일: test_es.py 프로젝트: LASarkar/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)
예제 #55
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 = thread(save=True)
        post(thread=t, save=True)
        f = t.forum
        last_post = f.last_post

        # add a new thread and post, verify last_post updated
        t = thread(title="test", forum=f, save=True)
        p = post(thread=t, content="test", author=t.creator, save=True)
        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)
예제 #56
0
    def test_last_post_updated(self):
        # Adding/Deleting the last post in a thread and forum should
        # update the last_post field
        orig_post = post(created=YESTERDAY, save=True)
        t = orig_post.thread

        # add a new post, then check that last_post is updated
        new_post = post(thread=t, content="test", save=True)
        f = Forum.objects.get(id=t.forum_id)
        t = Thread.objects.get(id=t.id)
        eq_(f.last_post.id, new_post.id)
        eq_(t.last_post.id, new_post.id)

        # delete the new post, then check that last_post is updated
        new_post.delete()
        f = Forum.objects.get(id=f.id)
        t = Thread.objects.get(id=t.id)
        eq_(f.last_post.id, orig_post.id)
        eq_(t.last_post.id, orig_post.id)
예제 #57
0
    def test_last_post_creator_deleted(self):
        """Delete the creator of the last post and verify forum survives."""
        # Create a post and verify it is the last one in the forum.
        post_ = post(content="test", save=True)
        forum_ = post_.thread.forum
        eq_(forum_.last_post.id, post_.id)

        # Delete the post creator, then check the forum still exists
        post_.author.delete()
        forum_ = Forum.objects.get(id=forum_.id)
        eq_(forum_.last_post, None)
예제 #58
0
    def test_post_absolute_url(self):
        t = thread(save=True)

        # Fill out the first page with posts from yesterday.
        p1 = post(thread=t, created=YESTERDAY, save=True)
        for i in range(POSTS_PER_PAGE - 1):
            post(thread=t, created=YESTERDAY, save=True)
        # Second page post from today.
        p2 = post(thread=t, save=True)

        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())
예제 #59
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 = user(username=name, save=True)
            for i in range(number):
                thread1 = thread(title=u'audio', save=True)
                post(thread=thread1, author=u, save=True)

        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'), qs)
            eq_(total, json.loads(response.content)['total'])