diff options
Diffstat (limited to 'python/tests/import_file_meta.py')
-rw-r--r-- | python/tests/import_file_meta.py | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/python/tests/import_file_meta.py b/python/tests/import_file_meta.py index 949a1075..2555f351 100644 --- a/python/tests/import_file_meta.py +++ b/python/tests/import_file_meta.py @@ -1,4 +1,3 @@ - import json import pytest @@ -12,35 +11,42 @@ from fatcat_tools.importers import FileMetaImporter, JsonLinePusher def file_meta_importer(api): yield FileMetaImporter(api) + def test_file_meta_importer_basic(file_meta_importer): # insert two file entities api = file_meta_importer.api eg = quick_eg(file_meta_importer.api) # with full metadata - f1edit = api.create_file(eg.editgroup_id, FileEntity( - size=372121, - md5="e1fd97475c8aa102568f5d70a1bd0c07", - sha1="0000045687dad717ed6512e395b04ec9c00995b7", - sha256="51bdc9e40cc175089fcb60b0b188e6cbcdcddb1ff8acbe6b039b8f8fff0afff0", - mimetype="application/pdf", - )) + f1edit = api.create_file( + eg.editgroup_id, + FileEntity( + size=372121, + md5="e1fd97475c8aa102568f5d70a1bd0c07", + sha1="0000045687dad717ed6512e395b04ec9c00995b7", + sha256="51bdc9e40cc175089fcb60b0b188e6cbcdcddb1ff8acbe6b039b8f8fff0afff0", + mimetype="application/pdf", + ), + ) # partial/stub metadata - f2edit = api.create_file(eg.editgroup_id, FileEntity( - sha1="00000376ad49f56145721503f1eb5e6e49e779fd", - mimetype="application/pdf", - )) + f2edit = api.create_file( + eg.editgroup_id, + FileEntity( + sha1="00000376ad49f56145721503f1eb5e6e49e779fd", + mimetype="application/pdf", + ), + ) api.accept_editgroup(eg.editgroup_id) - with open('tests/files/example_file_meta.json', 'r') as f: + with open("tests/files/example_file_meta.json", "r") as f: counts = JsonLinePusher(file_meta_importer, f).run() - assert counts['insert'] == 0 - assert counts['exists'] == 0 - assert counts['update'] == 1 - assert counts['skip-no-match'] == 4 - assert counts['skip-missing-field'] == 1 - assert counts['skip-existing-complete'] == 1 + assert counts["insert"] == 0 + assert counts["exists"] == 0 + assert counts["update"] == 1 + assert counts["skip-no-match"] == 4 + assert counts["skip-missing-field"] == 1 + assert counts["skip-existing-complete"] == 1 # cleanup file entities eg = quick_eg(file_meta_importer.api) @@ -48,8 +54,9 @@ def test_file_meta_importer_basic(file_meta_importer): api.delete_file(eg.editgroup_id, f2edit.ident) api.accept_editgroup(eg.editgroup_id) + def test_file_meta_dict_parse(file_meta_importer): - with open('tests/files/example_file_meta.json', 'r') as f: + with open("tests/files/example_file_meta.json", "r") as f: raw = json.loads(f.readline()) f = file_meta_importer.parse_record(raw) |