def test_date_dim_with_annual_interval(self): queries = ( mock_dataset.query.widget( f.HighCharts().axis(f.HighCharts.LineSeries(mock_dataset.fields.votes)) ) .dimension(f.year(mock_dataset.fields.timestamp)) .reference(f.DayOverDay(mock_dataset.fields.timestamp)) .sql ) self.assertEqual(2, len(queries)) with self.subTest("base query is same as without reference"): self.assertEqual( "SELECT " 'TRUNC("timestamp",\'Y\') "$timestamp",' 'SUM("votes") "$votes" ' 'FROM "politics"."politician" ' 'GROUP BY "$timestamp" ' 'ORDER BY "$timestamp"', str(queries[0]), ) with self.subTest( "reference query is same as base query with filter on reference dimension shifted" ): self.assertEqual( "SELECT " "TRUNC(TIMESTAMPADD('day',1,TRUNC(\"timestamp\",'Y')),'Y') \"$timestamp\"," 'SUM("votes") "$votes_dod" ' 'FROM "politics"."politician" ' 'GROUP BY "$timestamp" ' 'ORDER BY "$timestamp"', str(queries[1]), )
def test_build_query_with_datetime_interval_annually(self): queries = (mock_dataset.query().widget( f.ReactTable(mock_dataset.fields.votes)).dimension( f.year(mock_dataset.fields.timestamp)).sql) self.assertEqual(len(queries), 1) self.assertEqual( "SELECT " 'TRUNC("timestamp",\'Y\') "$timestamp",' 'SUM("votes") "$votes" ' 'FROM "politics"."politician" ' 'GROUP BY "$timestamp" ' 'ORDER BY "$timestamp" ' 'LIMIT 200000', str(queries[0]), )
def test_date_value_with_year_interval_is_returned_as_date_string_to_the_year( self): for d in (date(2019, 1, 1), datetime(2019, 1, 1, 12, 30, 2)): with self.subTest("with " + d.__class__.__name__): self.assertEqual("2019", formats.display_value(d, year(date_field)))