def test_create_entity_type_named_school(self): paths = AggregationTree.get(self.manager, ENTITY_TYPE_TREE_ID, get_or_create=True).get_paths() self.assertNotIn(self.entity_type, paths) self.assertIn(['reporter'], paths) self.CreateSchoolEntityType() paths = AggregationTree.get(self.manager, ENTITY_TYPE_TREE_ID, get_or_create=True).get_paths() self.assertIn(self.entity_type, paths)
def delete_type(dbm, entity): assert isinstance(dbm, DatabaseManager) entity_tree = AggregationTree.get(dbm, ENTITY_TYPE_TREE_ID, get_or_create=True) for entity_item in entity: entity_tree.remove_node(entity_item) entity_tree.save()
def get_all_entity_types(dbm): """ Return a list of all entity types. If we think of all entity types organized in a hierarchical tree, an entity type is a node in this tree and the node is represented by a list containing the node names in the path to this node. """ return AggregationTree.get(dbm, ENTITY_TYPE_TREE_ID, get_or_create=True).get_paths()
def define_type(dbm, entity_type): """ Add this entity type to the tree of all entity types and save it to the database. entity_type may be a string or a list of strings. """ assert is_not_empty(entity_type) assert is_sequence(entity_type) assert isinstance(dbm, DatabaseManager) if entity_type_already_defined(dbm, entity_type): raise EntityTypeAlreadyDefined(u"Type: %s is already defined" % u'.'.join(entity_type)) entity_tree = AggregationTree.get(dbm, ENTITY_TYPE_TREE_ID, get_or_create=True) entity_tree.add_path([AggregationTree.root_id] + entity_type) entity_tree.save()