示例#1
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)
示例#2
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)
示例#3
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)
示例#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_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)
示例#6
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())
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
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)
示例#11
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)
示例#12
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)
示例#13
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.advanced'), qs)
        eq_(response.status_code, 200)
示例#14
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
示例#15
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'])
示例#16
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)
示例#17
0
文件: test_es.py 项目: jdm/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"])
示例#18
0
文件: test_es.py 项目: jdm/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)
示例#19
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-{0!s}'.format(lp.id) in url
     assert 'last={0!s}'.format(lp.id) in url
示例#20
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'])
示例#21
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)
示例#22
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'])
示例#23
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)
示例#24
0
文件: test_es.py 项目: jdm/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"])
示例#25
0
文件: test_es.py 项目: jdm/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)
示例#26
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)
示例#27
0
    def test_created_date_invalid(self):
        """Invalid created_date is ignored."""
        thread1 = thread(save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json',
              'created': constants.INTERVAL_AFTER,
              'created_date': 'invalid'}
        response = self.client.get(reverse('search.advanced'), qs)
        eq_(1, json.loads(response.content)['total'])
示例#28
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)
示例#29
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)
示例#30
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'])
示例#31
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)

        # Archive the article and question. They should no longer appear
        # in default 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)
    def test_created_date_invalid(self):
        """Invalid created_date is ignored."""
        thread1 = thread(save=True)
        post(thread=thread1, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 4, 'format': 'json',
              'created': constants.INTERVAL_AFTER,
              'created_date': 'invalid'}
        response = self.client.get(reverse('search.advanced'), qs)
        eq_(1, json.loads(response.content)['total'])
示例#33
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'])
示例#34
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)
示例#35
0
    def test_forum_search(self):
        """Test searching for forum threads."""
        thread1 = thread(title=u'crash', save=True)
        post(thread=thread1, save=True)

        self.refresh()

        response = self.client.get(reverse('coolsearch.search_forum'), {
            'query': 'crash',
        })
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content['num_results'], 1)
示例#36
0
    def test_forum_search(self):
        """Test searching for forum threads."""
        thread1 = thread(title=u'crash', save=True)
        post(thread=thread1, save=True)

        self.refresh()

        response = self.client.get(reverse('coolsearch.search_forum'), {
            'query': 'crash',
        })
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content['num_results'], 1)
示例#37
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)
示例#38
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)
示例#39
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)
示例#40
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 = product(slug=u"desktop", save=True)
        ques = question(title=u"audio", product=p, save=True)
        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)

        # 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)
示例#41
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)
示例#42
0
    def test_thread_is_reindexed_on_username_change(self):
        search = ThreadMappingType.search()

        u = user(username='******', save=True)

        t = thread(creator=u, title=u'Hello', save=True)
        post(author=u, thread=t, save=True)
        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'])
示例#43
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)
示例#44
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)
示例#45
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)
示例#46
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)
示例#47
0
    def test_thread_is_reindexed_on_username_change(self):
        search = ThreadMappingType.search()

        u = user(username='******', save=True)

        t = thread(creator=u, title=u'Hello', save=True)
        post(author=u, thread=t, save=True)
        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'])
示例#48
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)
示例#49
0
    def test_discussion_forum_with_restricted_forums(self):
        """Tests who can see restricted forums in search form."""
        # This is a long test, but it saves us from doing the setup
        # twice.
        forum1 = forum(name=u'ou812forum', save=True)
        thread1 = thread(forum=forum1, title=u'audio 2', save=True)
        post(thread=thread1, save=True)

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

        self.refresh()

        # Get the Advanced Search Form as an anonymous user
        response = self.client.get(reverse('search.advanced'), {'a': '2'})
        eq_(200, response.status_code)

        # Regular forum should show up
        assert 'ou812forum' in response.content

        # Restricted forum should not show up
        assert 'restrictedkeepout' not in response.content

        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)

        # Get the Advanced Search Form as a logged in user
        self.client.login(username=u.username, password='******')
        response = self.client.get(reverse('search.advanced'), {'a': '2'})
        eq_(200, response.status_code)

        # Both forums should show up for authorized user
        assert 'ou812forum' in response.content
        assert 'restrictedkeepout' in response.content
示例#50
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)
示例#51
0
    def test_delete_post_removes_flag(self):
        """Deleting a post also removes the flags on that post."""
        p = post(save=True)

        u = user(save=True)
        FlaggedObject.objects.create(
            status=0, content_object=p, reason='language', creator_id=u.id)
        eq_(1, FlaggedObject.objects.count())

        p.delete()
        eq_(0, FlaggedObject.objects.count())
示例#52
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())
示例#53
0
 def test_thread_last_page(self):
     """Thread's last_page property is accurate."""
     t = post(save=True).thread
     # 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)
示例#54
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'])
示例#55
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())
示例#56
0
    def test_save_old_post_no_timestamps(self):
        """Saving an existing post should update the updated date."""
        created = datetime(2010, 5, 4, 14, 4, 22)
        updated = datetime(2010, 5, 4, 14, 4, 31)
        p = post(thread=self.thread, created=created, updated=updated,
                 save=True)

        eq_(updated, p.updated)

        p.content = 'baz'
        p.updated_by = self.user
        p.save()
        now = datetime.now()

        self.assertDateTimeAlmostEqual(now, p.updated, self.delta)
        eq_(created, p.created)
示例#57
0
 def test_replies_count(self):
     # The Thread.replies value should remain one less than the
     # number of posts in the thread.
     t = thread(save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     post(thread=t, save=True)
     old = t.replies
     eq_(2, old)
     t.new_post(author=t.creator, content='test').save()
     eq_(old + 1, t.replies)
示例#58
0
    def test_thread_sorting(self):
        # After the sticky threads, threads should be sorted by the
        # created date of the last post.

        # Make sure the datetimes are different.
        post(created=datetime.now() - timedelta(days=1), save=True)
        post(save=True)
        t = thread(is_sticky=True, save=True)
        post(thread=t, save=True)

        threads = Thread.objects.filter(is_sticky=False)
        self.assert_(
            threads[0].last_post.created > threads[1].last_post.created)