def test_savedsearch_no_user(self): """ A saved search with a null recipient should never be inserted in Solr """ solr = Solr() SavedSearchFactory(user=self.user) update_solr_task(self.test_solr) results = solr.search(q='*:*') # One hit for the search, one for its recipient self.assertEqual(results.hits, 2) solr.delete() search = SavedSearchFactory(user=None) self.assertEqual(object_to_dict(SavedSearch, search), None) update_solr_task(self.test_solr) results = solr.search(q='*:*') self.assertEqual(results.hits, 0)
def test_analytics_log_parsing(self): """ Ensure that analytics logs are parsed and stored in solr correctly """ company = CompanyFactory(id=1) business_unit = BusinessUnitFactory(id=1000) company.job_source_ids.add(business_unit) # match and no_match will be used later to ensure that the correct # number of documents were associated with a company or associated # with the default company match = Mock( wraps=lambda: self.assertEqual(doc['company_id'], company.pk)) no_match = Mock( wraps=lambda: self.assertEqual(doc['company_id'], 999999)) for log_type in ['analytics', 'redirect']: log = MockLog(log_type=log_type) parse_log([log], self.test_solr) solr = Solr() results = solr.search(q='uid:analytics*') # fake logs contain two lines - one human and one bot hit # If it is getting processed correctly, there should be only one # hit recorded self.assertEqual(results.hits, 1) multi_field = 'facets' if log_type == 'redirect': with self.assertRaises(KeyError): results.docs[0][multi_field] else: self.assertEqual(len(results.docs[0][multi_field]), 2) for field in results.docs[0].keys(): if field != multi_field: self.assertTrue(type(results.docs[0][field] != list)) uuid.UUID(results.docs[0]['aguid']) with self.assertRaises(KeyError): results.docs[0]['User_user_guid'] for doc in results.docs: if doc['job_view_buid'] == business_unit.pk: # If business units match, company ids should match match() else: # Business units don't match; company id should be set to # the default company no_match() solr.delete() user = UserFactory(email="*****@*****.**") user.user_guid = '1e5f7e122156483f98727366afe06e0b' user.save() parse_log([log], self.test_solr) results = solr.search(q='uid:analytics*') for guid in ['aguid', 'User_user_guid']: uuid.UUID(results.docs[0][guid]) solr.delete() user.delete() # We have already determined that there are only two documents. # Ensure that there is exactly one document that matches a specific # company and one document that was given the default company self.assertEqual(match.call_count, 1) self.assertEqual(no_match.call_count, 1)