Commit 02c94112 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

refactor: rename _object_relations to object_relations

Making those attributes private didn't make that much sens.
parent 90522f28f4c5
Pipeline #104649 passed with stages
in 1 minute and 27 seconds
......@@ -185,7 +185,8 @@ class SchemaLoaderTC(TestCase):
],
)
self.assertListEqual(
sorted(entity_schema.object_relations()), ["concerne", "obj_wildcard", "travaille"]
sorted(list(entity_schema.object_relations.values())),
["concerne", "obj_wildcard", "travaille"],
)
entity_schema = self.schema.entity_schema_for("Eetype")
......@@ -198,14 +199,17 @@ class SchemaLoaderTC(TestCase):
["description", "final", "initial_state", "meta", "name", "subj_wildcard"],
)
self.assertListEqual(
sorted(str(r) for r in entity_schema.object_relations()), ["obj_wildcard", "state_of"]
sorted(str(r) for r in entity_schema.object_relations.values()),
["obj_wildcard", "state_of"],
)
entity_schema = self.schema.entity_schema_for("Boolean")
self.assertEqual(entity_schema.description, "")
self.assertEqual(entity_schema.final, True)
self.assertListEqual(sorted(list(entity_schema.subject_relations.values())), [])
self.assertListEqual(sorted(entity_schema.object_relations()), ["final", "meta", "test"])
self.assertListEqual(
sorted(list(entity_schema.object_relations.values())), ["final", "meta", "test"]
)
# test base entity type's subject relation properties #####################
......
......@@ -276,7 +276,9 @@ class EntitySchemaTC(BaseSchemaTC):
self.assertCountEqual(
list(eperson.subject_relations.values()), schema["Person"].subject_relations()
)
self.assertCountEqual(eperson.object_relations(), schema["Person"].object_relations())
self.assertCountEqual(
list(eperson.object_relations.values()), schema["Person"].object_relations()
)
self.assertEqual(schema.entity_schema_for("Person").final, False)
self.assertEqual(schema.entity_schema_for("String").final, True)
self.assertEqual(schema.relation_schema_for("ref").final, True)
......@@ -365,12 +367,12 @@ class EntitySchemaTC(BaseSchemaTC):
def test_object_relations(self):
"""check object relations a returned in the same order as in the
schema definition"""
rels = eaffaire.object_relations()
rels = list(eaffaire.object_relations.values())
expected = ["concerne"]
self.assertEqual(rels, expected)
rels = [schem.type for schem in eaffaire.object_relations()]
rels = [schem.type for schem in eaffaire.object_relations.values()]
self.assertEqual(rels, expected)
self.assertEqual(eaffaire._object_relations["concerne"].type, "concerne")
self.assertEqual(eaffaire.object_relations["concerne"].type, "concerne")
def test_destination_type(self):
"""check subject relations a returned in the same order as in the
......@@ -650,7 +652,9 @@ class SchemaTC(BaseSchemaTC):
self.assertEqual(eperson, pschema["Person"])
self.assertEqual("Person", pschema["Person"])
self.assertEqual(eperson.ordered_relations(), pschema["Person"].ordered_relations())
self.assertEqual(eperson.object_relations(), pschema["Person"].object_relations())
self.assertEqual(
list(eperson.object_relations.values()), pschema["Person"].object_relations()
)
def test_rename_entity_type(self):
affaire = schema.entity_schema_for("Affaire")
......
......@@ -267,7 +267,7 @@ class _RetroCompatRelationsDict(dict):
@deprecation.attribute_renamed(old_name="subjrels", new_name="subject_relations")
@deprecation.attribute_renamed(old_name="objrels", new_name="_object_relations")
@deprecation.attribute_renamed(old_name="objrels", new_name="object_relations")
class EntitySchema(PermissionMixIn, ERSchema):
"""An entity has a type, a set of subject and or object relations
the entity schema defines the possible relations for a given type and some
......@@ -300,7 +300,9 @@ class EntitySchema(PermissionMixIn, ERSchema):
self.subject_relations: Dict[
"RelationSchema", "RelationSchema"
] = _RetroCompatRelationsDict(old_name="subject_relations")
self._object_relations: Dict["RelationSchema", "RelationSchema"] = {}
self.object_relations: Dict[
"RelationSchema", "RelationSchema"
] = _RetroCompatRelationsDict(old_name="object_relations")
self._specialized_type = relation_definition.specialized_type
self._specialized_by = relation_definition.specialized_by
self.final: bool = self.type in BASE_TYPES
......@@ -337,12 +339,12 @@ class EntitySchema(PermissionMixIn, ERSchema):
return "<%s %s - %s>" % (
self.type,
[subject_relation.type for subject_relation in self.subject_relations.values()],
[object_relation.type for object_relation in self.object_relations()],
[object_relation.type for object_relation in self.object_relations.values()],
)
def _rehash(self) -> None:
self.subject_relations = rehash(self.subject_relations)
self._object_relations = rehash(self._object_relations)
self.object_relations = rehash(self.object_relations)
def advertise_new_add_permission(self) -> None:
pass
......@@ -360,7 +362,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
@deprecation.argument_renamed(old_name="rschema", new_name="relation_schema")
def add_object_relation(self, relation_schema: "RelationSchema") -> None:
"""register the relation schema as possible object relation"""
self._object_relations[relation_schema] = relation_schema
self.object_relations[relation_schema] = relation_schema
@deprecation.argument_renamed(old_name="rtype", new_name="relation_schema")
def del_subject_relation(self, relation_schema: "RelationSchema") -> None:
......@@ -373,8 +375,8 @@ class EntitySchema(PermissionMixIn, ERSchema):
@deprecation.argument_renamed(old_name="rtype", new_name="relation_type")
def del_object_relation(self, relation_schema: "RelationSchema") -> None:
if relation_schema in self._object_relations:
del self._object_relations[relation_schema]
if relation_schema in self.object_relations:
del self.object_relations[relation_schema]
# IEntitySchema interface #################################################
......@@ -413,13 +415,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
if role == "subject":
return relation_type in self.subject_relations
return relation_type in self._object_relations
def object_relations(self) -> List["RelationSchema"]:
"""return a list of relations that may have this type of entity as
object
"""
return list(self._object_relations.values())
return relation_type in self.object_relations
@deprecation.argument_renamed(old_name="rtype", new_name="relation_type")
@deprecation.argument_renamed(old_name="targettype", new_name="target_type")
......@@ -491,7 +487,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
if include_final or not relation_schema.final:
yield relation_schema, relation_schema.objects(self), "subject"
for relation_schema in self.object_relations():
for relation_schema in self.object_relations.values():
yield relation_schema, relation_schema.subjects(self), "object"
@deprecation.argument_renamed(old_name="rtype", new_name="relation_schema")
......@@ -644,7 +640,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
if not relation_schema.final and relation_schema.fulltext_container == "subject":
yield relation_schema, "subject"
for relation_schema in self.object_relations():
for relation_schema in self.object_relations.values():
if relation_schema.fulltext_container == "object":
yield relation_schema, "object"
......@@ -656,7 +652,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
if relation_schema.fulltext_container == "object":
yield relation_schema, "object"
for relation_schema in self.object_relations():
for relation_schema in self.object_relations.values():
if relation_schema.fulltext_container == "subject":
yield relation_schema, "subject"
......@@ -671,7 +667,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
"""return True if this entity type is contained by another. If strict,
return True if this entity type *must* be contained by another.
"""
for relation_schema in self.object_relations():
for relation_schema in self.object_relations.values():
if (relation_schema, "object") in skip_relations:
continue
......@@ -1630,7 +1626,7 @@ class Schema:
for object_type in relation_schema.objects(entity_type):
self.del_relation_def(entity_schema, relation_schema, object_type)
for relation_schema in list(entity_schema._object_relations.values()):
for relation_schema in list(entity_schema.object_relations.values()):
for subject_type in relation_schema.subjects(entity_type):
self.del_relation_def(subject_type, relation_schema, entity_schema)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment