def test_field_eq(): assert (Field() == 1) == 1
def test_field_ne(): assert (Field() != 1) == {'$ne': 1}
def test_exists(): assert +Field() == {'$exists': True}
def test_not_exists(): assert -Field() == {'$exists': False}
def test_field_lte(): assert (Field() <= 1) == {'$lte': 1}
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'))
def test_resolve_none_with_default(): field = Field(nullable=False, default=1) assert field.resolve(None) == 1
def test_field_gte(): assert (Field() >= 1) == {'$gte': 1}
def test_fails_validate_object_property(): properties = {'a': Field(nullable=False)} with pytest.raises(TypeError): ObjectField(properties).validate({'a': None})
def test_resolve_missing_property_without_default(): properties = {'a': Field(required=True)} assert ObjectField(properties).resolve({}) == {}
def test_fails_validate_object_required_property(value): properties = {'a': Field(required=True)} with pytest.raises(TypeError): ObjectField(properties).validate(value)
def test_resolve_property_without_default(): properties = {'a': Field(nullable=False, default=1)} assert ObjectField(properties).resolve({'a': None}) == {'a': 1}
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)))
def test_field_gt(): assert (Field() > 1) == {'$gt': 1}
def test_resolve_none_with_get_default(): field = Field(nullable=False, get_default=list) assert field.resolve(None) == []
def test_resolve_none_without_default(): field = Field(nullable=False) assert field.resolve(None) is None
def test_validate_none_nullable(): field = Field() field.validate(None)
def test_field_lt(): assert (Field() < 1) == {'$lt': 1}
def test_validate_none(): field = Field(nullable=False) with pytest.raises(TypeError): field.validate(None)
def test_field_in(): assert (Field() >> [1, 2, 3]) == {'$in': [1, 2, 3]}
def field(): return Field()