def validate_deep(data, context, direction, attribute): relations = [] node = sequence(direction) inv = Invalid(node) for i, relation_data in enumerate(data.get(direction, [])): try: other = relation_data.get(attribute, {}) schema = context.network.get_relation_schema( relation_data.get('type')) if schema is None: raise Invalid( node, "Invalid relation type: %e" % relation_data.get('type')) relation = validate_relation(relation_data, schema, context, ignore_entities=True) schema = context.network.get_entity_schema(other.get('type')) if schema is None: raise Invalid(node, "Invalid entity type: %e" % other.get('type')) relation[attribute] = validate_entity(other, schema, context, deep=False) relations.append(relation) except Invalid as sub: inv.add(sub, i) return relations, inv
def validate_deep(data, context, direction, attribute): relations = [] node = sequence(direction) inv = Invalid(node) for i, relation_data in enumerate(data.get(direction, [])): try: other = relation_data.get(attribute, {}) schema = context.network.get_relation_schema(relation_data.get('type')) if schema is None: raise Invalid(node, "Invalid relation type: %e" % relation_data.get('type')) relation = validate_relation(relation_data, schema, context, ignore_entities=True) schema = context.network.get_entity_schema(other.get('type')) if schema is None: raise Invalid(node, "Invalid entity type: %e" % other.get('type')) relation[attribute] = validate_entity(other, schema, context, deep=False) relations.append(relation) except Invalid as sub: inv.add(sub, i) return relations, inv
def test_source_equals_target(self): in_ = deepcopy(TEST_RELATION) in_['target'] = in_['source'] validate_relation(in_, self.schema, self.context)
def test_no_target(self): in_ = deepcopy(TEST_RELATION) del in_['target'] validate_relation(in_, self.schema, self.context)
def test_invalid_target(self): in_ = deepcopy(TEST_RELATION) in_['target'] = 'foo' validate_relation(in_, self.schema, self.context)
def test_no_source(self): in_ = deepcopy(TEST_RELATION) del in_['source'] validate_relation(in_, self.schema, self.context)
def test_invalid_source(self): in_ = deepcopy(TEST_RELATION) in_['source'] = 'foo' validate_relation(in_, self.schema, self.context)
def test_validate_basic(self): try: validate_relation(TEST_RELATION, self.schema, self.context) except Invalid, i: assert False, i.asdict()
def test_invalid_type(self): in_ = deepcopy(TEST_RELATION) in_['type'] = 'ownedBy' validate_relation(in_, self.schema, self.context)