def setUp(self): super(IntegrationTestAutomaticEmails, self).setUp() # prep a fake table now = utc_now() - datetime.timedelta(minutes=30) last_month = now - datetime.timedelta(days=31) config_manager = self._setup_storage_config() with config_manager.context() as config: storage = ElasticSearchCrashStorage(config) # clear the indices cache so the index is created on every test storage.indices_cache = set() storage.save_processed({ 'uuid': '1', 'email': '*****@*****.**', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now, 'classifications': { 'support': { 'classification': 'unknown' } } }) storage.save_processed({ 'uuid': '2', 'email': '"Quidam" <*****@*****.**>', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now, 'classifications': { 'support': { 'classification': None } } }) storage.save_processed({ 'uuid': '3', 'email': '*****@*****.**', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now, 'classifications': { 'support': { 'classification': 'bitguard' } } }) storage.save_processed({ 'uuid': '4', 'email': '*****@*****.**', 'product': 'NightlyTrain', 'version': '1.0', 'release_channel': 'Nightly', 'date_processed': now }) storage.save_processed({ 'uuid': '5', 'email': '*****@*****.**', 'product': 'NightlyTrain', 'version': '1.0', 'release_channel': 'Nightly', 'date_processed': now }) storage.save_processed({ 'uuid': '6', 'email': '*****@*****.**', 'product': 'NightlyTrain', 'version': '1.0', 'release_channel': 'Nightly', 'date_processed': now }) storage.save_processed({ 'uuid': '7', 'email': '*****@*****.**', 'product': 'NightlyTrain', 'version': '1.0', 'release_channel': 'Nightly', 'date_processed': now }) storage.save_processed({ 'uuid': '8', 'email': '*****@*****.**', 'product': 'NightlyTrain', 'version': '1.0', 'release_channel': 'Nightly', 'date_processed': now }) storage.save_processed({ 'uuid': '9', 'email': '*****@*****.**', 'product': 'EarthRaccoon', 'version': '1.0', 'release_channel': 'Nightly', 'date_processed': now }) storage.save_processed({ 'uuid': '18', 'email': 'z\xc3\[email protected]', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now }) # Let's insert a duplicate storage.save_processed({ 'uuid': '10', 'email': '*****@*****.**', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now }) # And let's insert some invalid crashes storage.save_processed({ 'uuid': '11', 'email': None, 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now }) storage.save_processed({ 'uuid': '12', 'email': '*****@*****.**', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': last_month }) storage.save_processed({ 'uuid': '13', 'email': '*****@*****.**', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now }) storage.save_processed({ 'uuid': '14', 'email': '*****@*****.**', 'product': 'WindBear', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now }) # Finally some invalid email addresses storage.save_processed({ 'uuid': '15', 'email': ' ', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now }) storage.save_processed({ 'uuid': '16', 'email': 'invalid@email', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now }) storage.save_processed({ 'uuid': '17', 'email': 'i.do.not.work', 'product': 'WaterWolf', 'version': '20.0', 'release_channel': 'Release', 'date_processed': now }) # Create some email addresses. storage.create_emails_index() storage.es.index( index=config.elasticsearch_emails_index, doc_type='emails', doc={ 'email': '*****@*****.**', 'last_sending': last_month }, id='*****@*****.**', ) storage.es.index( index=config.elasticsearch_emails_index, doc_type='emails', doc={ 'email': '"Quidam" <*****@*****.**>', 'last_sending': last_month }, id='"Quidam" <*****@*****.**>', ) storage.es.index( index=config.elasticsearch_emails_index, doc_type='emails', doc={ 'email': '*****@*****.**', 'last_sending': now }, id='*****@*****.**', ) # As indexing is asynchronous, we need to force elasticsearch to # make the newly created content searchable before we run the # tests. storage.es.refresh()