Example #1
0
def test_access_object_array_field(field):
    object_field = ObjectField({SECOND_NAME: field})
    array_field = ArrayField(object_field)
    field_access = FieldAccess(FIRST_NAME, FIRST_NAME, array_field, ()).b
    assert field_access.get_field() is object_field.properties[SECOND_NAME]
    assert (field_access.get_path_as_name() == '.'.join(
        (FIRST_NAME, SECOND_NAME)))
Example #2
0
def test_resolve_missing_property_without_default():
    properties = {'a': Field(required=True)}
    assert ObjectField(properties).resolve({}) == {}
Example #3
0
def test_fails_validate_object_additional_properties():
    with pytest.raises(TypeError):
        ObjectField({}, additional_properties=False).validate({'a': None})
Example #4
0
def test_fails_validate_object_property():
    properties = {'a': Field(nullable=False)}
    with pytest.raises(TypeError):
        ObjectField(properties).validate({'a': None})
Example #5
0
def test_fails_validate_object_required_property(value):
    properties = {'a': Field(required=True)}
    with pytest.raises(TypeError):
        ObjectField(properties).validate(value)
Example #6
0
def test_fails_validate_object(value):
    with pytest.raises(TypeError):
        ObjectField(nullable=False).validate(value)
Example #7
0
def test_validate_object(value):
    ObjectField(nullable=False).validate(value)
Example #8
0
def test_resolve_property_without_default():
    properties = {'a': Field(nullable=False, default=1)}
    assert ObjectField(properties).resolve({'a': None}) == {'a': 1}