Esempio n. 1
0
def test_create_object_with_custom_features_field():
    """
    Create an object representation of an Address
    """
    e = ey.Object(uri='las://schema/foo', features_key='foobarbaz')
    simple_string = ey.String()
    custom_features = {'bar': simple_string}
    e.set_feature(**custom_features)

    assert e.schema == {
        "$id":
        "las://schema/foo",
        "$schema":
        "http://json-schema.org/draft-07/schema#",
        "type":
        "object",
        "allOf": [{
            "properties": {
                'foobarbaz': {
                    "type":
                    "object",
                    "allOf": [{
                        "properties": {
                            "bar": {
                                "type": "string"
                            }
                        },
                        "required": []
                    }]
                }
            }
        }]
    }
Esempio n. 2
0
def test_extend_entity():
    """
    Create a Student schema extending person schema (i.e., inhertiance)
    """
    student = ey.Object(uri='las://schema/student')
    student_id = ey.String()
    student.set_feature(student_id=student_id)
    student.add_required_features('student_id')
    # Inheritance
    r = ey.ObjectReference('las://schema/person')
    student.extend(r)
    # Redundant inheritance. entity.extend() is protected against this kind of redundancy
    student.extend(r)
    assert student.schema == next(item for item in SCHEMA
                                  if item["$id"] == 'las://schema/student')
Esempio n. 3
0
def test_append_reference():
    """
    Create a reference and append it to an object
    """
    e = ey.Object(uri='las://schema/person')
    simple_string = ey.String()
    address = ey.ObjectReference('las://schema/address')

    features = {
        'firstName': simple_string,
        'lastName': simple_string,
        'address': address
    }
    e.set_feature(**features)
    e.add_required_features('firstName', 'lastName')
    # Match the creaded object against a target schema (i.e., las://schema/address)
    assert e.schema == next(item for item in SCHEMA
                            if item["$id"] == 'las://schema/person')
Esempio n. 4
0
def test_save_object(schema_store):

    e = ey.Object(uri='las://schema/address_foo')
    simple_string = ey.String()
    features = {'street_address': simple_string,
                'city': simple_string, 'state': simple_string}
    e.set_feature(**features)

    e.add_required_features('street_address')
    # entity.add_required_features prevents duplicates
    e.add_required_features('street_address', 'city', 'state')

    schema_store.save(e)

    # get the saved object from the store
    address_foo = schema_store.get_object('las://schema/address_foo')

    # compare with the one in memory
    assert address_foo.schema == e.schema
Esempio n. 5
0
def test_create_object():
    """
    Create an object representation of an Address
    """
    e = ey.Object(uri='las://schema/address')
    simple_string = ey.String()
    features = {
        'street_address': simple_string,
        'city': simple_string,
        'state': simple_string
    }
    e.set_feature(**features)

    e.add_required_features('street_address')
    # entity.add_required_features prevents duplicates
    e.add_required_features('street_address', 'city', 'state')

    # Match the creaded object against a target schema (i.e., las://schema/address)
    assert e.schema == next(item for item in SCHEMA
                            if item["$id"] == 'las://schema/address')