def test_query_get_int_filter_lt_result(self): uuid = str(uuid4()) self.TestEntity1(uuid, int_field=1, uuid=uuid).save() result = self.TestEntity1.query.filter( IntField("int_field") < 2).filter( StringField("uuid") == uuid).first() self.assertIsNotNone(result)
def test_query_chained_projection_and_filters(self): uuid1 = str(uuid4()) self.TestEntity1(uuid1, int_field=1, float_field=1.2).save() result = self.TestEntity1.query.only('int_field').filter( IntField('int_field') >= 1).first() self.assertEqual(result['int_field'], 1) self.assertFalse(hasattr(result, 'float_field'))
def test_query_chained_projection_and_filters(ds_entity, uuid_gen): uuid_gen1 = uuid_gen() ds_entity(uuid_gen1, int_field=1, float_field=1.2).save() result = ds_entity.query.only('int_field').filter( IntField('int_field') >= 1).first() assert result['int_field'] == 1 assert not hasattr(result, 'float_field')
def field(): return IntField()
def test_int_field_loads(self): field = IntField() for value in [1, 1.2, True, "foo", object(), {}, []]: self.assertEqual(value, field.loads(value))
def test_int_field_default_callable(self): field = IntField(default=int) self.assertEqual(int(), field.default)
def test_int_field_default_value(self): field = IntField(default=1) self.assertEqual(1, field.default)
def test_int_field_default_default_None(self): field = IntField() self.assertIsNone(field.default)
def test_int_field_dumps_enforce_type(self): field = IntField(enforce_type=True) for value in [1.2, True, "foo", object(), {}, []]: with self.assertRaises(ValueError): field.dumps(value) self.assertEqual(1, field.dumps(1))
def test_int_field_dumps_no_enforce_type(self): field = IntField() for value in [1, 1.2, True, "foo", object(), {}, []]: self.assertEqual(value, field.dumps(value))
def test_query_get_int_filter_eq_no_result(self): result = self.TestEntity1.query.filter(IntField("int_field") == 1).get( str(uuid4())) self.assertIsNone(result)
def test_query_get_int_filter_lt_result(ds_entity, uuid_gen): uuid_gen = uuid_gen() ds_entity(uuid_gen, int_field=1, uuid_gen=uuid_gen).save() result = ds_entity.query.filter(IntField("int_field") < 2).filter( StringField("uuid_gen") == uuid_gen).first() assert result is not None
def test_query_get_int_filter_eq_no_result(ds_entity, uuid_gen): result = ds_entity.query.filter(IntField("int_field") == 1).get(uuid_gen()) assert result is None