def test_year(self): query = Query().from_table(table=Order, fields=[Year('time')]) query_str = query.get_sql() expected_query = ( 'SELECT CAST(EXTRACT(year FROM querybuilder_tests_order.time) AS INT) AS "time__year" ' 'FROM querybuilder_tests_order') self.assertEqual(query_str, expected_query, get_comparison_str(query_str, expected_query))
def test_year_auto_desc(self): query = Query().from_table(table=Order, fields=[Year('time', auto=True, desc=True)]) query_str = query.get_sql() expected_query = ( 'SELECT CAST(EXTRACT(year FROM querybuilder_tests_order.time) AS INT) AS "time__year", ' 'CAST(EXTRACT(epoch FROM date_trunc(\'year\', querybuilder_tests_order.time)) AS INT) AS "time__epoch" ' 'FROM querybuilder_tests_order ' 'GROUP BY time__year, time__epoch ' 'ORDER BY time__epoch DESC') self.assertEqual(query_str, expected_query, get_comparison_str(query_str, expected_query))