def test_success_with_redacted_raw_crash(self, espy_mock): """Test a successful index of a crash report""" modified_config = deepcopy(self.config) modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = 'unsused' modified_config.raw_crash_es_redactor = DotDict() modified_config.raw_crash_es_redactor.redactor_class = RawCrashRedactor modified_config.raw_crash_es_redactor.forbidden_keys = 'unsused' sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock es_storage = ESCrashStorageRedactedSave(config=modified_config) crash_id = a_processed_crash['uuid'] # Add a 'StackTraces' field to be redacted. raw_crash = deepcopy(a_raw_crash) raw_crash['StackTraces'] = 'something' # Submit a crash like normal, except that the back-end ES object is # mocked (see the decorator above). es_storage.save_raw_and_processed( raw_crash=deepcopy(raw_crash), dumps=None, processed_crash=deepcopy(a_processed_crash), crash_id=crash_id, ) # Ensure that the ES objects were instantiated by ConnectionContext. assert espy_mock.Elasticsearch.called # Ensure that the IndicesClient was also instantiated (this happens in # IndexCreator but is part of the crashstorage workflow). assert espy_mock.client.IndicesClient.called expected_processed_crash = deepcopy(a_processed_crash) reconstitute_datetimes(expected_processed_crash) # The actual call to index the document (crash). document = { 'crash_id': crash_id, 'processed_crash': expected_processed_crash, 'raw_crash': a_raw_crash # Note here we expect the original dict } additional = { 'doc_type': 'crash_reports', 'id': crash_id, 'index': 'socorro_integration_test_reports' } sub_mock.index.assert_called_with( body=document, **additional )
def test_success_with_no_stackwalker_class(self, espy_mock): """Test a successful index of a crash report. """ modified_config = deepcopy(self.config) modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = ( "json_dump, " "upload_file_minidump_flash1.json_dump, " "upload_file_minidump_flash2.json_dump, " "upload_file_minidump_browser.json_dump" ) modified_config.raw_crash_es_redactor = DotDict() modified_config.raw_crash_es_redactor.redactor_class = RawCrashRedactor modified_config.raw_crash_es_redactor.forbidden_keys = 'unsused' # It's mocks all the way down. sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock es_storage = ESCrashStorageRedactedSave(config=modified_config) crash_id = a_processed_crash['uuid'] # Submit a crash like normal, except that the back-end ES object is # mocked (see the decorator above). es_storage.save_raw_and_processed( raw_crash=a_raw_crash, dumps=None, processed_crash=a_processed_crash, crash_id=crash_id, ) # Ensure that the ES objects were instantiated by ConnectionContext. ok_(espy_mock.Elasticsearch.called) # Ensure that the IndicesClient was also instantiated (this happens in # IndexCreator but is part of the crashstorage workflow). ok_(espy_mock.client.IndicesClient.called) # The actual call to index the document (crash). document = { 'crash_id': crash_id, 'processed_crash': a_processed_crash_with_no_stackwalker, 'raw_crash': a_raw_crash } additional = { 'doc_type': 'crash_reports', 'id': crash_id, 'index': 'socorro_integration_test_reports' } sub_mock.index.assert_called_with( body=document, **additional )
def test_success_with_no_stackwalker_class(self, espy_mock): """Test a successful index of a crash report""" modified_config = deepcopy(self.config) modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = ( "json_dump, " "upload_file_minidump_flash1.json_dump, " "upload_file_minidump_flash2.json_dump, " "upload_file_minidump_browser.json_dump") modified_config.raw_crash_es_redactor = DotDict() modified_config.raw_crash_es_redactor.redactor_class = RawCrashRedactor modified_config.raw_crash_es_redactor.forbidden_keys = "unsused" sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock es_storage = ESCrashStorageRedactedSave(config=modified_config) crash_id = a_processed_crash["uuid"] # Submit a crash like normal, except that the back-end ES object is # mocked (see the decorator above). es_storage.save_processed_crash( raw_crash=deepcopy(a_raw_crash), processed_crash=deepcopy(a_processed_crash), ) # Ensure that the ES objects were instantiated by ConnectionContext. assert espy_mock.Elasticsearch.called # Ensure that the IndicesClient was also instantiated (this happens in # IndexCreator but is part of the crashstorage workflow). assert espy_mock.client.IndicesClient.called # The actual call to index the document (crash). document = { "crash_id": crash_id, "processed_crash": a_processed_crash_with_no_stackwalker, "raw_crash": a_raw_crash, } additional = { "doc_type": "crash_reports", "id": crash_id, "index": "socorro_integration_test_reports", } sub_mock.index.assert_called_with(body=document, **additional)
def test_success_with_redacted_raw_crash(self, espy_mock): """Test a successful index of a crash report""" modified_config = deepcopy(self.config) modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = "unsused" modified_config.raw_crash_es_redactor = DotDict() modified_config.raw_crash_es_redactor.redactor_class = RawCrashRedactor modified_config.raw_crash_es_redactor.forbidden_keys = "unsused" sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock es_storage = ESCrashStorageRedactedSave(config=modified_config) raw_crash = { "BuildID": "20200605000", "ProductName": "Firefox", "ReleaseChannel": "nightly", # Add a 'StackTraces' field to be redacted. "StackTraces": "something", } processed_crash = { "date_processed": "2012-04-08 10:56:41.558922", "uuid": "936ce666-ff3b-4c7a-9674-367fe2120408", } crash_id = processed_crash["uuid"] # Submit a crash like normal, except that the back-end ES object is # mocked (see the decorator above). es_storage.save_processed_crash( raw_crash=raw_crash, processed_crash=processed_crash, ) # Ensure that the ES objects were instantiated by ConnectionContext. assert espy_mock.Elasticsearch.called # Ensure that the IndicesClient was also instantiated (this happens in # IndexCreator but is part of the crashstorage workflow). assert espy_mock.client.IndicesClient.called expected_raw_crash = deepcopy(raw_crash) del expected_raw_crash["StackTraces"] expected_processed_crash = deepcopy(processed_crash) reconstitute_datetimes(expected_processed_crash) # The actual call to index the document (crash). document = { "crash_id": crash_id, "processed_crash": expected_processed_crash, "raw_crash": expected_raw_crash, } additional = { "doc_type": "crash_reports", "id": crash_id, "index": "socorro_integration_test_reports", } sub_mock.index.assert_called_with(body=document, **additional)