def test__normalize_val_SQL_eq(self): i = self.get_interface() s = Schema("fake_table_name", ts=Field(datetime.datetime, True)) orm_class = s.create_orm() fstr, fargs = orm_class.query.is_ts(day=10).render(placeholder=True) self.assertTrue('EXTRACT(DAY FROM "ts") = %s' in fstr) self.assertEqual(10, fargs[0]) fstr, fargs = orm_class.query.is_ts(day=11, hour=12).render(placeholder=True) self.assertTrue( 'EXTRACT(DAY FROM "ts") = %s AND EXTRACT(HOUR FROM "ts") = %s' in fstr) self.assertEqual(11, fargs[0]) self.assertEqual(12, fargs[1]) fstr, fargs = orm_class.query.is_ts(None).render(placeholder=True) self.assertTrue('"ts" IS %s' in fstr) fstr, fargs = orm_class.query.not_ts(None).render(placeholder=True) self.assertTrue('"ts" IS NOT %s' in fstr) with self.assertRaises(KeyError): fstr, fargs = orm_class.query.is_ts(bogus=5).render( placeholder=True)
def test__normalize_val_SQL_in(self): i = self.get_interface() s = Schema("fake_table_name", ts=Field(datetime.datetime, True)) orm_class = s.create_orm() fstr, fargs = orm_class.query.in_ts(day=10).render(placeholder=True) self.assertTrue('EXTRACT(DAY FROM "ts") IN (%s)' in fstr) fstr, fargs = orm_class.query.in_ts(day=[11, 13], hour=12).render(placeholder=True) self.assertTrue( 'EXTRACT(DAY FROM "ts") IN (%s, %s) AND EXTRACT(HOUR FROM "ts") IN (%s)' in fstr) self.assertEqual([11, 13, 12], fargs) with self.assertRaises(KeyError): fstr, fargs = orm_class.query.in_ts(bogus=5).render( placeholder=True)