diff --git a/src/linkahead/apiutils.py b/src/linkahead/apiutils.py index bef01201d39f260139440b4cb939a7c22c943a77..e2ed0facea84e6056b1ac877b4417ce6ad8ef504 100644 --- a/src/linkahead/apiutils.py +++ b/src/linkahead/apiutils.py @@ -215,6 +215,10 @@ def compare_entities(old_entity: Entity, new_entity: Entity, compare_referenced_ if old_entity is new_entity: return (olddiff, newdiff) + if type(old_entity) is not type(new_entity): + raise ValueError( + "Comparison of different Entity types is not supported.") + for attr in SPECIAL_ATTRIBUTES: try: oldattr = old_entity.__getattribute__(attr) diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index 80e4273295dcfbebc093934c8ddfbcf3d78ecb4c..ea537ffe8c44a7a7fb79c2d4080b63f9b3da2284 100644 --- a/src/linkahead/common/models.py +++ b/src/linkahead/common/models.py @@ -81,7 +81,7 @@ NONE = "NONE" SPECIAL_ATTRIBUTES = ["name", "role", "datatype", "description", - "id", "path", "checksum", "size"] + "id", "path", "checksum", "size", "value"] class Entity: @@ -154,7 +154,7 @@ class Entity: # Copy special attributes: # TODO: this might rise an exception when copying # special file attributes like checksum and size. - for attribute in SPECIAL_ATTRIBUTES + ["value"]: + for attribute in SPECIAL_ATTRIBUTES: val = getattr(self, attribute) if val is not None: setattr(new, attribute, val) diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py index 3ed719f7b00a4c5bf25583ac6729738d3d872f57..4705f19a1bdfbc4358790f787f2dce9ea97fee48 100644 --- a/unittests/test_apiutils.py +++ b/unittests/test_apiutils.py @@ -103,6 +103,8 @@ def test_compare_entities(): r1.add_parent("lopp") r1.add_property("test", value=2) r2.add_property("test", value=2) + r1.add_property("testi", importance=linkahead.SUGGESTED, value=2) + r2.add_property("testi", importance=linkahead.RECOMMENDED, value=2) r1.add_property("tests", value=3) r2.add_property("tests", value=45) r1.add_property("tester", value=3) @@ -114,8 +116,8 @@ def test_compare_entities(): assert len(diff_r1["parents"]) == 1 assert len(diff_r2["parents"]) == 0 - assert len(diff_r1["properties"]) == 3 - assert len(diff_r2["properties"]) == 3 + assert len(diff_r1["properties"]) == 4 + assert len(diff_r2["properties"]) == 4 assert "test" not in diff_r1["properties"] assert "test" not in diff_r2["properties"] @@ -123,6 +125,9 @@ def test_compare_entities(): assert "tests" in diff_r1["properties"] assert "tests" in diff_r2["properties"] + assert "testi" in diff_r1["properties"] + assert "testi" in diff_r2["properties"] + assert "tester" in diff_r1["properties"] assert "tester" in diff_r2["properties"] @@ -211,7 +216,6 @@ def test_compare_special_properties(): assert len(diff_r2["properties"]) == 0 -@pytest.mark.xfail def test_compare_properties(): p1 = db.Property() p2 = db.Property() @@ -222,21 +226,12 @@ def test_compare_properties(): assert len(diff_r1["properties"]) == 0 assert len(diff_r2["properties"]) == 0 - p1.importance = "SUGGESTED" diff_r1, diff_r2 = compare_entities(p1, p2) assert len(diff_r1["parents"]) == 0 assert len(diff_r2["parents"]) == 0 assert len(diff_r1["properties"]) == 0 assert len(diff_r2["properties"]) == 0 - assert "importance" in diff_r1 - assert diff_r1["importance"] == "SUGGESTED" - - # TODO: I'm not sure why it is not like this: - # assert diff_r2["importance"] is None - # ... but: - assert "importance" not in diff_r2 - p2.importance = "SUGGESTED" p1.value = 42 p2.value = 4