Skip to content
Snippets Groups Projects
Commit 8bafce22 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

FIX: correct string creation when backrefs are there

parent 6d799f95
No related branches found
No related tags found
2 merge requests!91Release 0.3,!8backref
......@@ -103,8 +103,10 @@ class Identifiable():
creates a string from the attributes of an identifiable that can be hashed
String has the form "P<parent>N<name>a:5b:10"
"""
rec_string = "P<{}>N<{}>R<{}>".format(identifiable.record_type, identifiable.name,
identifiable.backrefs)
rec_string = "P<{}>N<{}>R<{}>".format(
identifiable.record_type,
identifiable.name,
[Identifiable._value_representation(el) for el in identifiable.backrefs])
# TODO this structure neglects Properties if multiple exist for the same name
for pname in sorted(identifiable.properties.keys()):
rec_string += ("{}:".format(pname) +
......
......@@ -32,9 +32,9 @@ from caoscrawler.identified_cache import IdentifiedCache
def test_create_hashable_string():
assert Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B")) == "P<B>N<A>"
Identifiable(name="A", record_type="B")) == "P<B>N<A>R<[]>"
assert Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': 5})) == "P<B>N<A>a:5"
Identifiable(name="A", record_type="B", properties={'a': 5})) == "P<B>N<A>R<[]>a:5"
a = Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': 4, 'b': 5}))
b = Identifiable._create_hashable_string(
......@@ -43,21 +43,24 @@ def test_create_hashable_string():
assert (
Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': db.Record(id=12)})
) == "P<B>N<A>a:12")
) == "P<B>N<A>R<[]>a:12")
a = Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12)]}))
assert (a == "P<B>N<A>a:[12]")
assert (a == "P<B>N<A>R<[]>a:[12]")
assert (Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>a:[12]")
Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>R<[]>a:[12]")
assert (
Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12), 11]})
) == "P<B>N<A>a:[12, 11]")
) == "P<B>N<A>R<[]>a:[12, 11]")
assert (
Identifiable._create_hashable_string(
Identifiable(record_type="B", properties={'a': [db.Record()]})
) != Identifiable._create_hashable_string(
Identifiable(record_type="B", properties={'a': [db.Record()]})))
assert Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", backrefs=[123, db.Entity(id=124)],
properties={'a': 5})) == "P<B>N<A>R<['123', '124']>a:5"
def test_name():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment