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])
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']
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))
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)
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")
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)
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'))
def get_search_qs(self, query, **params): form = SearchForm(RpcMultiValueDict(dict(q=query, **params))) return form.queryset()
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())