Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test__lower__str(self):
q = Q.select(fn.Lower('ABC'))
self.assertEqual("SELECT LOWER('ABC')", str(q))
def test__min(self):
q = Q.from_('abc').select(fn.Min('foo'))
self.assertEqual('SELECT MIN(foo) FROM abc', str(q))
def test_select_field_from_missing_table(self):
with self.assertRaises(JoinException):
Query.from_(self.t0).select(self.t1.foo)
with self.assertRaises(JoinException):
Query.from_(self.t0).where(self.t1.foo == 0)
with self.assertRaises(JoinException):
Query.from_(self.t0).where(fn.Sum(self.t1.foo) == 0)
with self.assertRaises(JoinException):
Query.from_(self.t0).select(fn.Sum(self.t0.bar * 2) + fn.Sum(self.t1.foo * 2))
with self.assertRaises(JoinException):
Query.from_(self.t0).groupby(self.t1.foo)
with self.assertRaises(JoinException):
Query.from_(self.t0).groupby(self.t0.foo).having(self.t1.bar)
def test__max(self):
q = Q.from_('abc').select(fn.Max('foo'))
self.assertEqual('SELECT MAX(foo) FROM abc', str(q))
def test_functions_using_constructor_param(self):
q = Query.from_(self.t).select(fn.Count('*', alias='foo'))
self.assertEqual('SELECT COUNT(*) foo FROM abc', str(q))
def test_function_with_values_and_fields_for_table(self):
f = fn.Mod(self.t0.foo, 2).for_(self.t1)
self.assertEqual('MOD(t1.foo,2)', str(f))
def test_groupby__count_distinct(self):
q = Query.from_(self.t).groupby(self.t.foo).select(self.t.foo, fn.Count('*').distinct())
self.assertEqual('SELECT foo,COUNT(DISTINCT *) FROM abc GROUP BY foo', str(q))
def test__cast__signed(self):
q1 = Q.from_(self.t).select(fn.Signed(self.t.foo))
q2 = Q.from_(self.t).select(fn.Cast(self.t.foo, 'SIGNED'))
self.assertEqual("SELECT CAST(foo AS SIGNED) FROM abc", str(q1))
self.assertEqual("SELECT CAST(foo AS SIGNED) FROM abc", str(q2))
def test_prefixes_added_to_function_in_orderby(self):
test_query = Query.from_(self.t0).join(self.t1).on(
self.t0.foo == self.t1.bar
).select(self.t0.foo, self.t1.buz).orderby(fn.Date(self.t0.foo))
self.assertEqual('SELECT t0.foo,t1.buz FROM abc t0 '
'JOIN efg t1 ON t0.foo=t1.bar '
'ORDER BY DATE(t0.foo)', str(test_query))