def test_save_raw_and_processed(self): config = self.get_standard_config() db_sampling = DBCrashStorageWrapperNewCrashSource(config) crash_id = '86b58ff2-9708-487d-bfc4-9dac32121214' fake_raw_crash = SocorroDotDict({ "name": "Gabi", "submitted_timestamp": "2012-12-14T00:00:00" }) fake_dumps_as_files = FileDumpsMapping({ 'upload_file_minidump': '86b58ff2-9708-487d-bfc4-9dac32121214' '.upload_file_minidump.TEMPORARY.dump' }) fake_processed = SocorroDotDict({ "name": "Gabi", "submitted_timestamp": "2012-12-14T00:00:00" }) # the call to be tested db_sampling.save_raw_and_processed( fake_raw_crash, fake_dumps_as_files, fake_processed, crash_id ) # this is what should have happened db_sampling._implementation.save_raw_and_processed \ .assert_called_once_with( fake_raw_crash, fake_dumps_as_files, fake_processed, crash_id )
def get_raw_dumps_as_files(self, prefix_path_tuple): """default implemntation of fetching a dump. parameters: dump_pathnames - a tuple of paths. the second element and beyond are the dump pathnames """ prefix, dump_pathnames = prefix_path_tuple return FileDumpsMapping( zip(self._dump_names_from_pathnames(dump_pathnames[1:]), dump_pathnames[1:]))
def get_raw_dumps_as_files(self, crash_id): parent_dir = self._get_radixed_parent_directory(crash_id) if not os.path.exists(parent_dir): raise CrashIDNotFound dump_paths = [ os.sep.join([parent_dir, dump_file_name]) for dump_file_name in os.listdir(parent_dir) if (dump_file_name.startswith(crash_id) and dump_file_name.endswith(self.config.dump_file_suffix)) ] # we want to return a name/pathname mapping for the raw dumps return FileDumpsMapping(zip(self._dump_names_from_paths(dump_paths), dump_paths))
def test_get_raw_dumps_as_files(self): config = self.get_standard_config() db_sampling = DBCrashStorageWrapperNewCrashSource(config) crash_id = '86b58ff2-9708-487d-bfc4-9dac32121214' fake_dumps_as_files = FileDumpsMapping({ 'upload_file_minidump': '86b58ff2-9708-487d-bfc4-9dac32121214' '.upload_file_minidump.TEMPORARY.dump' }) mocked_get_raw_dumps_as_files = Mock(return_value=fake_dumps_as_files) db_sampling._implementation.get_raw_dumps_as_files = mocked_get_raw_dumps_as_files # the call to be tested raw_dumps_as_files = db_sampling.get_raw_dumps_as_files(crash_id) # this is what should have happened assert fake_dumps_as_files is raw_dumps_as_files db_sampling._implementation.get_raw_dumps_as_files.assert_called_with( crash_id)
def test_basic_crashstorage(self): required_config = Namespace() mock_logging = mock.Mock() required_config.add_option("logger", default=mock_logging) required_config.update(CrashStorageBase.required_config) config_manager = ConfigurationManager( [required_config], app_name="testapp", app_version="1.0", app_description="app description", values_source_list=[{ "logger": mock_logging }], argv_source=[], ) with config_manager.context() as config: crashstorage = CrashStorageBase( config, quit_check_callback=fake_quit_check) crashstorage.save_raw_crash({}, "payload", "ooid") crashstorage.save_processed({}) with pytest.raises(NotImplementedError): crashstorage.get_raw_crash("ooid") with pytest.raises(NotImplementedError): crashstorage.get_raw_dump("ooid") with pytest.raises(NotImplementedError): crashstorage.get_unredacted_processed("ooid") with pytest.raises(NotImplementedError): crashstorage.remove("ooid") assert crashstorage.new_crashes() == [] crashstorage.close() with config_manager.context() as config: class MyCrashStorage(CrashStorageBase): def save_raw_crash(self, raw_crash, dumps, crash_id): assert crash_id == "fake_id" assert raw_crash == "fake raw crash" assert sorted(dumps.keys()) == sorted( ["one", "two", "three"]) assert sorted(dumps.values()) == sorted( ["eins", "zwei", "drei"]) values = ["eins", "zwei", "drei"] def open_function(*args, **kwargs): return values.pop(0) crashstorage = MyCrashStorage(config, quit_check_callback=fake_quit_check) with mock.patch( "socorro.external.crashstorage_base.open") as open_mock: open_mock.return_value = mock.MagicMock() open_mock.return_value.__enter__.return_value.read.side_effect = ( open_function) crashstorage.save_raw_crash_with_file_dumps( "fake raw crash", FileDumpsMapping({ "one": "eins", "two": "zwei", "three": "drei" }), "fake_id", )
def test_basic_crashstorage(self): required_config = Namespace() mock_logging = Mock() required_config.add_option('logger', default=mock_logging) required_config.update(CrashStorageBase.required_config) config_manager = ConfigurationManager( [required_config], app_name='testapp', app_version='1.0', app_description='app description', values_source_list=[{ 'logger': mock_logging, }], argv_source=[] ) with config_manager.context() as config: crashstorage = CrashStorageBase( config, quit_check_callback=fake_quit_check ) crashstorage.save_raw_crash({}, 'payload', 'ooid') crashstorage.save_processed({}) with pytest.raises(NotImplementedError): crashstorage.get_raw_crash('ooid') with pytest.raises(NotImplementedError): crashstorage.get_raw_dump('ooid') with pytest.raises(NotImplementedError): crashstorage.get_unredacted_processed('ooid') with pytest.raises(NotImplementedError): crashstorage.remove('ooid') assert crashstorage.new_crashes() == [] crashstorage.close() with config_manager.context() as config: class MyCrashStorageTest(CrashStorageBase): def save_raw_crash(self, raw_crash, dumps, crash_id): assert crash_id == "fake_id" assert raw_crash == "fake raw crash" assert sorted(dumps.keys()) == sorted(['one', 'two', 'three']) assert sorted(dumps.values()) == sorted(['eins', 'zwei', 'drei']) values = ['eins', 'zwei', 'drei'] def open_function(*args, **kwargs): return values.pop(0) crashstorage = MyCrashStorageTest( config, quit_check_callback=fake_quit_check ) with mock.patch("__builtin__.open") as open_mock: open_mock.return_value = mock.MagicMock() ( open_mock.return_value.__enter__ .return_value.read.side_effect ) = open_function crashstorage.save_raw_crash_with_file_dumps( "fake raw crash", FileDumpsMapping({ 'one': 'eins', 'two': 'zwei', 'three': 'drei' }), 'fake_id' )