Example #1
0
def relation_schema(schema, context, ignore_entities=False):
    relation = mapping('relation', validator=chained(source_not_target))
    relation.add(
        key('type', validator=chained(nonempty_string, in_([schema.name]))))
    if not ignore_entities:
        relation.add(_node(EntitySchemaType(context), 'source'))
        relation.add(_node(EntitySchemaType(context), 'target'))
    return apply_schema(relation, schema)
Example #2
0
def entity_schema(schema):
    entity = mapping('entity')
    entity.add(key('title', validator=chained(
            nonempty_string
        )))
    entity.add(key('type', validator=chained(
            nonempty_string,
            in_([schema.name])
        )))
    return apply_schema(entity, schema)
Example #3
0
def relation_schema(schema, context, ignore_entities=False):
    relation = mapping('relation', validator=chained(
            source_not_target
        ))
    relation.add(key('type', validator=chained(
            nonempty_string,
            in_([schema.name])
        )))
    if not ignore_entities:
        relation.add(_node(EntitySchemaType(context), 'source'))
        relation.add(_node(EntitySchemaType(context), 'target'))
    return apply_schema(relation, schema)
Example #4
0
def entity_schema(schema):
    entity = mapping('entity')
    entity.add(key('title', validator=chained(nonempty_string)))
    entity.add(
        key('type', validator=chained(nonempty_string, in_([schema.name]))))
    return apply_schema(entity, schema)
 def test_apply_schema(self):
     base = mapping('entity')
     schema = Schema.create(self.network, Schema.ENTITY, h.TEST_ENTITY_SCHEMA)
     base = apply_schema(base, schema)
     assert len(base.children)==len(h.TEST_ENTITY_SCHEMA['attributes'])
Example #6
0
 def test_apply_schema(self):
     base = mapping('entity')
     schema = Schema.create(self.network, Schema.ENTITY,
                            h.TEST_ENTITY_SCHEMA)
     base = apply_schema(base, schema)
     assert len(base.children) == len(h.TEST_ENTITY_SCHEMA['attributes'])