Exemple #1
0
def test_field_eq():
    assert (Field() == 1) == 1
Exemple #2
0
def test_field_ne():
    assert (Field() != 1) == {'$ne': 1}
Exemple #3
0
def test_exists():
    assert +Field() == {'$exists': True}
Exemple #4
0
def test_not_exists():
    assert -Field() == {'$exists': False}
Exemple #5
0
def test_field_lte():
    assert (Field() <= 1) == {'$lte': 1}
Exemple #6
0
def test_access_array_field():
    array_field = ArrayField(Field())
    field_access = FieldAccess(FIRST_NAME, FIRST_NAME, array_field)[0]
    assert field_access.get_field() is array_field.items
    assert field_access.get_path_as_name() == '.'.join((FIRST_NAME, '0'))
Exemple #7
0
def test_resolve_none_with_default():
    field = Field(nullable=False, default=1)
    assert field.resolve(None) == 1
Exemple #8
0
def test_field_gte():
    assert (Field() >= 1) == {'$gte': 1}
Exemple #9
0
def test_fails_validate_object_property():
    properties = {'a': Field(nullable=False)}
    with pytest.raises(TypeError):
        ObjectField(properties).validate({'a': None})
Exemple #10
0
def test_resolve_missing_property_without_default():
    properties = {'a': Field(required=True)}
    assert ObjectField(properties).resolve({}) == {}
Exemple #11
0
def test_fails_validate_object_required_property(value):
    properties = {'a': Field(required=True)}
    with pytest.raises(TypeError):
        ObjectField(properties).validate(value)
Exemple #12
0
def test_resolve_property_without_default():
    properties = {'a': Field(nullable=False, default=1)}
    assert ObjectField(properties).resolve({'a': None}) == {'a': 1}
Exemple #13
0
def test_access_object_field():
    object_field = ObjectField({SECOND_NAME: Field()})
    field_access = FieldAccess(FIRST_NAME, FIRST_NAME, object_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)))
Exemple #14
0
def test_field_gt():
    assert (Field() > 1) == {'$gt': 1}
Exemple #15
0
def test_resolve_none_with_get_default():
    field = Field(nullable=False, get_default=list)
    assert field.resolve(None) == []
Exemple #16
0
def test_resolve_none_without_default():
    field = Field(nullable=False)
    assert field.resolve(None) is None
Exemple #17
0
def test_validate_none_nullable():
    field = Field()
    field.validate(None)
Exemple #18
0
def test_field_lt():
    assert (Field() < 1) == {'$lt': 1}
Exemple #19
0
def test_validate_none():
    field = Field(nullable=False)
    with pytest.raises(TypeError):
        field.validate(None)
Exemple #20
0
def test_field_in():
    assert (Field() >> [1, 2, 3]) == {'$in': [1, 2, 3]}
Exemple #21
0
def field():
    return Field()