예제 #1
0
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
예제 #2
0
파일: entity.py 프로젝트: jmorenoamor/grano
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
예제 #3
0
 def test_source_equals_target(self):
     in_ = deepcopy(TEST_RELATION)
     in_['target'] = in_['source']
     validate_relation(in_, self.schema, self.context)
예제 #4
0
 def test_no_target(self):
     in_ = deepcopy(TEST_RELATION)
     del in_['target']
     validate_relation(in_, self.schema, self.context)
예제 #5
0
 def test_invalid_target(self):
     in_ = deepcopy(TEST_RELATION)
     in_['target'] = 'foo'
     validate_relation(in_, self.schema, self.context)
예제 #6
0
 def test_no_source(self):
     in_ = deepcopy(TEST_RELATION)
     del in_['source']
     validate_relation(in_, self.schema, self.context)
예제 #7
0
 def test_invalid_source(self):
     in_ = deepcopy(TEST_RELATION)
     in_['source'] = 'foo'
     validate_relation(in_, self.schema, self.context)
예제 #8
0
 def test_validate_basic(self):
     try:
         validate_relation(TEST_RELATION, self.schema, self.context)
     except Invalid, i:
         assert False, i.asdict()
예제 #9
0
 def test_invalid_type(self):
     in_ = deepcopy(TEST_RELATION)
     in_['type'] = 'ownedBy'
     validate_relation(in_, self.schema, self.context)
예제 #10
0
 def test_invalid_target(self):
     in_ = deepcopy(TEST_RELATION)
     in_['target'] = 'foo'
     validate_relation(in_, self.schema, self.context)
예제 #11
0
 def test_source_equals_target(self):
     in_ = deepcopy(TEST_RELATION)
     in_['target'] = in_['source']
     validate_relation(in_, self.schema, self.context)
예제 #12
0
 def test_no_target(self):
     in_ = deepcopy(TEST_RELATION)
     del in_['target']
     validate_relation(in_, self.schema, self.context)
예제 #13
0
 def test_invalid_source(self):
     in_ = deepcopy(TEST_RELATION)
     in_['source'] = 'foo'
     validate_relation(in_, self.schema, self.context)
예제 #14
0
 def test_no_source(self):
     in_ = deepcopy(TEST_RELATION)
     del in_['source']
     validate_relation(in_, self.schema, self.context)
예제 #15
0
 def test_invalid_type(self):
     in_ = deepcopy(TEST_RELATION)
     in_['type'] = 'ownedBy'
     validate_relation(in_, self.schema, self.context)
예제 #16
0
 def test_validate_basic(self):
     try:
         validate_relation(TEST_RELATION, self.schema, self.context)
     except Invalid, i:
         assert False, i.asdict()