def test_query_chained_filters(ds_entity, uuid_gen): uuid_gen = uuid_gen() ds_entity(uuid_gen, str_field="foe", other_field="foe2", uuid_gen=uuid_gen).save() result = ds_entity.query.filter(StringField('str_field') == "foe").filter( StringField('other_field') == "foe2").first() assert result.uuid_gen == uuid_gen
def test_query_get_str_filter_lt_no_result(self): uuid = str(uuid4()) self.TestEntity1(uuid, str_field="foo", uuid=uuid).save() result = self.TestEntity1.query.filter( StringField("str_field") < "foe").filter( StringField("uuid") == uuid).first() self.assertIsNone(result)
def test_query_chained_filters(self): uuid = str(uuid4()) self.TestEntity1(uuid, str_field="foe", other_field="foe2", uuid=uuid).save() result = self.TestEntity1.query.filter( StringField('str_field') == "foe").filter( StringField('other_field') == "foe2").first() self.assertEqual(result.uuid, uuid)
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_get_float_filter_lt_result(ds_entity, uuid_gen): uuid_gen = uuid_gen() a = ds_entity(uuid_gen, float_field=1.0, uuid_gen=uuid_gen) a.save() result = ds_entity.query.filter(FloatField("float_field") < 2.0).filter( StringField("uuid_gen") == uuid_gen).first() assert result is not None
def test_query_get_float_filter_lt_no_result(self): uuid = str(uuid4()) self.TestEntity1(uuid, float_field=2.0, uuid=uuid).save() result = self.TestEntity1.query.filter( FloatField("float_field") < 1.0).filter( StringField("uuid") == uuid).first() self.assertIsNone(result)
def test_string_field_default_default_None(self): field = StringField() self.assertIsNone(field.default)
def test_string_field_dumps_enforce_type(self): field = StringField(enforce_type=True) for value in [1, 1.2, True, object(), {}, []]: with self.assertRaises(ValueError): field.dumps(value) self.assertEqual("foo", field.dumps("foo"))
def test_string_field_dumps_no_enforce_type(self): field = StringField() for value in [1, 1.2, True, "foo", object(), {}, []]: self.assertEqual(value, field.dumps(value))
def test_string_field_loads(self): field = StringField() for value in [1, 1.2, True, "foo", object(), {}, []]: self.assertEqual(value, field.loads(value))
def test_query_get_float_filter_ge_no_result(ds_entity, uuid_gen): uuid_gen = uuid_gen() ds_entity(uuid_gen, float_field=0.0, uuid_gen=uuid_gen).save() result = ds_entity.query.filter(FloatField("float_field") >= 1.0).filter( StringField("uuid_gen") == uuid_gen).first() assert result is None
def test_query_get_str_filter_eq_no_result(self): result = self.TestEntity1.query.filter( StringField("str_field") == "foo").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_str_filter_lt_no_result(ds_entity, uuid_gen): uuid_gen = uuid_gen() ds_entity(uuid_gen, str_field="foo", uuid_gen=uuid_gen).save() result = ds_entity.query.filter(StringField("str_field") < "foe").filter( StringField("uuid_gen") == uuid_gen).first() assert result is None
def test_query_get_str_filter_eq_no_result(ds_entity, uuid_gen): result = ds_entity.query.filter(StringField("str_field") == "foo").get( uuid_gen()) assert result is None
def test_string_field_default_value(self): field = StringField(default="foo") self.assertEqual("foo", field.default)
def test_string_field_default_callable(self): field = StringField(default=str) self.assertEqual(str(), field.default)
def field(): return StringField()