def test_import_full(DBSession): """ Test the entire Scan, Encode, Import cycle with a video and audio item """ with ProcessMediaTestManager(TEST1_VIDEO_FILES | TEST2_AUDIO_FILES) as manager: manager.scan_media() manager.encode_media(mock=True) stats = import_media(**manager.commandline_kwargs) assert freeze(stats) == freeze(dict( db_end={'test1', 'test2'}, meta_imported={'test1', 'test2'}, meta_unprocessed={}, missing_processed_deleted={}, missing_processed_aborted={}, db_removed=[], db_start={}, meta_set={'test1', 'test2'}, meta_hash_matched_db_hash={}, )) track1 = get_track_dict_full(manager.get('test1').source_hash) assert track1 track2 = get_track_dict_full(manager.get('test2').source_hash) assert track2
def test_basic_import(DBSession): """ Fake import cycle into db with mocked processed files for simple case """ with ProcessMediaTestManager() as manager: # Create mock scan data (as if an encode had just been performed) manager.meta = { "test3.json": { "processed": { "source_hash": "test3_hash", }, }, "test4.json": { "processed": { "source_hash": "test4_hash", } }, } # Create empty files for all expected processed files manager.mock_processed_files( processed_file.relative for processed_file in flatten( manager.get_all_processed_files_associated_with_source_hash(source_hash).values() for source_hash in manager.meta_manager.source_hashs ) ) stats = import_media(path_meta=manager.path_meta, path_processed=manager.path_processed) assert freeze(stats) == freeze(dict( db_end={'test3', 'test4'}, meta_imported={'test3', 'test4'}, meta_unprocessed={}, missing_processed_deleted={}, missing_processed_aborted={}, db_removed=[], db_start={}, meta_set={'test3', 'test4'}, meta_hash_matched_db_hash={}, )) assert DBSession.query(Track).count() == 2 def count_attachments(track): attachments = defaultdict(int) for attachment in track['attachments']: attachments[attachment['type']] += 1 return dict(attachments) track3 = get_track_dict_full('test3_hash') assert freeze(count_attachments(track3)) == EXPECTED_ATTACHMENT_COUNT track4 = get_track_dict_full('test4_hash') assert freeze(count_attachments(track4)) == EXPECTED_ATTACHMENT_COUNT
def test_basic_import(DBSession): """ Fake import cycle into db with mocked processed files for simple case """ with ProcessMediaTestManager() as manager: # Create mock scan data (as if an encode had just been performed) manager.meta = { "test3.json": { "processed": { MetaFile.SOURCE_HASHS_KEY: gen_fake_hash_dict("test3_hash"), }, }, "test4.json": { "processed": { MetaFile.SOURCE_HASHS_KEY: gen_fake_hash_dict("test4_hash"), }, }, } # Create empty files for all expected processed files manager.mock_processed_files( processed_file.relative for m in manager.meta_manager.meta_items for processed_file in m.processed_files.values() ) stats = import_media(**manager.commandline_kwargs) assert freeze(stats) == freeze(dict( db_end={'test3', 'test4'}, meta_imported={'test3', 'test4'}, meta_unprocessed={}, missing_processed_deleted={}, missing_processed_aborted={}, db_removed=[], db_start={}, meta_set={'test3', 'test4'}, meta_hash_matched_db_hash={}, )) assert DBSession.query(Track).count() == 2 def count_attachments(track): attachments = defaultdict(int) for attachment in track['attachments']: attachments[attachment['type']] += 1 return dict(attachments) track3 = get_track_dict_full('test3_hash') assert freeze(count_attachments(track3)) == EXPECTED_ATTACHMENT_COUNT track4 = get_track_dict_full('test4_hash') assert freeze(count_attachments(track4)) == EXPECTED_ATTACHMENT_COUNT