def test_search_misc(self): """Try to index an invalid object.""" if not settings.USE_SONIC: # pragma: no cover return # pylint: disable=C0415 from other.asyncio_run import run_sync from other.search import push, index_pair, run_query_sync, push_obj_sync # Test invalid sync doesn't panic run_sync(push((None, None))) self.assertEqual(True, True) # Test indexing of PT blog ent = BlogEntry(title='strategy comp', blog_url=settings.PLACEMENTS_URL) self.assertEqual(index_pair(ent)[0], 'placement') ent = BlogEntry(title='ecomm comp', blog_url=settings.TRAINING_BLOG_URL) self.assertEqual(index_pair(ent)[0], 'training') ent = BlogEntry(title='why this', blog_url='https://google.com') self.assertEqual(index_pair(ent)[0], 'blogs') # Test indexing of news ent = NewsEntry(id='bigid', title='insightiitb', blog_url='https://google.com') self.assertEqual(index_pair(ent)[0], 'news') push_obj_sync(ent) self.assertIn('bigid', run_query_sync('news', 'insightiitb'))
async def refresh(queryset): # Get client client = SonicClient(**settings.SONIC_CONFIG) await client.channel(SonicChannels.INGEST.value) # Index all objects for i, obj in enumerate(queryset): pair = index_pair(obj) # Flush on first object if i == 0: await client.flushc(pair[0]) # Push object await push(pair, client=client)