def test_import_newest_incremental_dump_handler_no_full_dump( self, mock_latest_full_dump, mock_import_dump): """ Test to make sure only latest incremental dump is imported if no full dump is found """ mock_import_dump.return_value = 'listenbrainz-spark-dump-202-20200915-180002-incremental.tar' messages = import_dump.import_newest_incremental_dump_handler() mock_import_dump.assert_called_once_with(dump_id=None) self.assertEqual(len(messages), 1) self.assertListEqual( ['listenbrainz-spark-dump-202-20200915-180002-incremental.tar'], messages[0]['imported_dump'])
def test_import_newest_incremental_dump_handler(self, _, mock_latest_full_dump, __, mock_import_dump, ___, ____): """ Test to make sure required incremental dumps are imported. """ mock_latest_full_dump.return_value = { "dump_id": 202, "imported_at": datetime(2020, 9, 29), "dump_type": DumpType.FULL } mock_import_calls = [] expected_import_list = [] for dump_id in range(204, 210, 3): mock_import_calls.append(call(dump_id)) expected_import_list.append( f"listenbrainz-spark-dump-{dump_id}-incremental.tar") messages = import_dump.import_newest_incremental_dump_handler() mock_import_dump.assert_has_calls(mock_import_calls) self.assertListEqual(expected_import_list, messages[0]['imported_dump'])
def test_import_newest_incremental_dump_handler_error( self, mock_latest_full_dump, mock_search, mock_import_dump): """ Test to make sure import is aborted if there is a fatal error. """ mock_latest_full_dump.return_value = { "dump_id": 202, "imported_at": datetime(2020, 9, 29), "dump_type": "incremental" } mock_import_calls = [] expected_import_list = [] for dump_id in range(204, 210, 3): mock_import_calls.append(call('incremental', False, dump_id)) expected_import_list.append( f"listenbrainz-listens-dump-{dump_id}-spark-incremental.tar.xz" ) messages = import_newest_incremental_dump_handler() mock_import_dump.assert_has_calls(mock_import_calls) # Only three calls should be made self.assertEqual(mock_import_dump.call_count, 3) self.assertListEqual(expected_import_list, messages[0]['imported_dump'])