Skip to content

Commit

Permalink
Handle partial processing results (#178)
Browse files Browse the repository at this point in the history
* Handle missing data in backend (#135)

* Test missing data processing
  • Loading branch information
stepan-anokhin authored Nov 4, 2020
1 parent 5e5b87a commit 98c78c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/server/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

def prepare_serialization(data):
"""Perform a shallow serialization of field values if needed."""
if data is None:
return data
for key, value in data.items():
if type(value) in _SERIALIZE:
serialize = _SERIALIZE[type(value)]
Expand Down Expand Up @@ -57,7 +59,7 @@ def file_dict(file, *, meta=False, signature=False, scenes=False, exif=False):
}
if meta:
data["meta"] = Transform.metadata_dict(file.meta)
if signature:
if signature and file.signature is not None:
data["signature"] = file.signature.signature
if scenes:
data["scenes"] = [Transform.scene_dict(scene, file=False) for scene in file.scenes]
Expand All @@ -69,6 +71,8 @@ def file_dict(file, *, meta=False, signature=False, scenes=False, exif=False):
@serializable
def metadata_dict(meta):
"""Get plain data representation for VideoMetadata."""
if meta is None:
return None
fields = entity_fields(meta)
fields -= {"id", "file_id", "file"}
return {field: getattr(meta, field) for field in fields}
Expand All @@ -90,6 +94,8 @@ def scene_dict(scene, file=False):
@serializable
def exif_dict(exif):
"""Get plain data representation for Exif."""
if exif is None:
return None
fields = entity_fields(exif)
fields -= {"id", "file_id", "file", "Json_full_exif"}
return {field: getattr(exif, field) for field in fields}
Expand Down
10 changes: 10 additions & 0 deletions server/tests/server/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ def test_transform_file():
data = Transform.file_dict(file, exif=True)
assert data["file_path"] == file.file_path
assert data["exif"]["General_FileSize"] == file.exif.General_FileSize


def test_transform_partial():
file = Files(file_path="foo", sha256="bar", meta=None, exif=None, signature=None)

data = Transform.file_dict(file, meta=True, signature=True, exif=True)

assert data.get("meta") is None
assert data.get("exif") is None
assert data.get("signature") is None

0 comments on commit 98c78c2

Please sign in to comment.