示例#1
0
    def test_filtering(self):
        self.assertTrue(Video.objects.count())
        for video in Video.objects.all():
            video_changed_tasks.delay(video.pk)

        reset_solr()

        rpc = SearchApiClass()

        rdata = RpcMultiValueDict(dict(q=u' ', video_lang='en'))
        result = rpc.search(rdata, self.user, testing=True)['sqs']

        self.assertTrue(len(result))
        for video in VideoIndex.public():
            if video.video_language == 'en':
                self.assertTrue(
                    video.object in [item.object for item in result])

        rdata = RpcMultiValueDict(dict(q=u' ', langs='en'))
        result = rpc.search(rdata, self.user, testing=True)['sqs']

        self.assertTrue(len(result))
        for video in VideoIndex.public():
            if video.languages and 'en' in video.languages:
                self.assertTrue(
                    video.object in [item.object for item in result])
示例#2
0
    def test_empty_query(self):
        rpc = SearchApiClass()

        rdata = RpcMultiValueDict(dict(q=u''))
        rpc.search(rdata, self.user, testing=True)['sqs']

        rdata = RpcMultiValueDict(dict(q=u' '))
        rpc.search(rdata, self.user, testing=True)['sqs']
示例#3
0
    def test_query_clean(self):
        video = Video.objects.all()[0]
        video.title = u"Cher BBC and Dawn French's Lookalikes"
        video.save()
        reset_solr()
        rpc = SearchApiClass()

        rdata = RpcMultiValueDict(dict(q=u'?BBC'))
        result = rpc.search(rdata, self.user, testing=True)['sqs']
        self.assertTrue(len(result))
示例#4
0
    def test_rpc(self):
        rpc = SearchApiClass()
        rdata = RpcMultiValueDict(dict(q=u'BBC'))

        for title in self.titles:
            video = Video.objects.all()[0]
            video.title = title
            video.save()
            reset_solr()

            result = rpc.search(rdata, self.user, testing=True)['sqs']
            self.assertTrue(video in [item.object for item in result], title)
示例#5
0
    def test_search_relevance(self):
        reset_solr()

        rpc = SearchApiClass()
        rdata = RpcMultiValueDict(dict(q=u'unique'))

        result = rpc.search(rdata, self.user, testing=True)['sqs']
        videos = [item.object for item in result]

        # by default, title is more important than description
        self.assertEquals(videos[0].title, u"This is my unique title")
        self.assertEquals(videos[1].title, u"Default")
        self.assertEquals(videos[1].description,
                          u"this is my unique description")

        rdata = RpcMultiValueDict(dict(q=u'unique', sort="total_views"))
        result = rpc.search(rdata, self.user, testing=True)['sqs']
        videos = [item.object for item in result]

        self.assertEquals(videos[0].title, u"Default")
        self.assertEquals(videos[1].title, u"This is my unique title")
示例#6
0
 def test_search_index_updating(self):
     reset_solr()
     rpc = SearchApiClass()
     
     for title in self.titles:
         rdata = RpcMultiValueDict(dict(q=title))
         video = Video.objects.all()[0]
         video.title = title
         video.save()
         video.update_search_index()
         
         result = rpc.search(rdata, self.user, testing=True)['sqs']
         self.assertTrue(video in [item.object for item in result], title)
示例#7
0
 def test_facet_choices(self):
     video_lang_facet_info = [
         ('en', 10),
         ('fr', 20),
     ]
     language_facet_info = [
         ('en', 10),
         ('es', 7),
     ]
     test_utils.get_language_facet_counts.return_value = (
         video_lang_facet_info, language_facet_info
     )
     form = SearchForm(RpcMultiValueDict(dict(q='foo')))
     # we should always list the blank choice first, then the languages
     # with facet info, in descending order
     self.check_choices(form.fields['video_lang'], ['', 'fr', 'en'])
     self.check_choices(form.fields['langs'], ['', 'en', 'es'])
     # check that get_language_facet_counts() was presented with the
     # correct query
     self.check_get_language_facet_counts_query(VideoIndex.public()
                                                .auto_query('foo')
                                                .filter_or(title='foo'))
示例#8
0
 def get_search_qs(self, query, **params):
     form = SearchForm(RpcMultiValueDict(dict(q=query, **params)))
     return form.queryset()
示例#9
0
 def test_facet_choices_empty_query(self):
     form = SearchForm(RpcMultiValueDict(dict(q='')))
     # If we don't have a query, we should use the all videos
     self.check_get_language_facet_counts_query(VideoIndex.public())