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'))
def run_query_sync(collection: str, query: str, bucket=DEFAULT_BUCKET): return run_sync(run_query(collection, query, bucket))
def handle(self, *args, **options): if not settings.USE_SONIC: return # Refresh all bodies and news run_sync(refresh(Body.objects.all())) run_sync(refresh(NewsEntry.objects.all())) # Refresh events younger than two years run_sync(refresh(get_fresh_events(Event.objects, delta=600))) # Refresh entries younger than two years placement = BlogEntry.objects.filter(published__gte=timezone.now() - timedelta(days=600)) run_sync(refresh(placement)) # Refresh active users run_sync(refresh(UserProfile.objects.filter(active=True))) # Re-consolidate run_sync(consolidate())
def push_obj_sync(obj): return run_sync(push(index_pair(obj)))