This is an automated email from the ASF dual-hosted git repository. maximebeauchemin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push: new 725b8f9 Adding tests for the time table viz (#4659) 725b8f9 is described below commit 725b8f94c91f2b07e7ee9c1076a344641c1b1e73 Author: michellethomas <michelle.q.tho...@gmail.com> AuthorDate: Wed Apr 11 13:24:51 2018 -0700 Adding tests for the time table viz (#4659) --- tests/viz_tests.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tests/viz_tests.py b/tests/viz_tests.py index a5adfc1..bb20946 100644 --- a/tests/viz_tests.py +++ b/tests/viz_tests.py @@ -636,3 +636,83 @@ class RoseVisTestCase(unittest.TestCase): ], } self.assertEqual(expected, res) + + +class TimeSeriesTableVizTestCase(unittest.TestCase): + + def test_get_data_metrics(self): + form_data = { + 'metrics': ['sum__A', 'count'], + 'groupby': [], + } + datasource = Mock() + raw = {} + t1 = pd.Timestamp('2000') + t2 = pd.Timestamp('2002') + raw[DTTM_ALIAS] = [t1, t2] + raw['sum__A'] = [15, 20] + raw['count'] = [6, 7] + df = pd.DataFrame(raw) + test_viz = viz.TimeTableViz(datasource, form_data) + data = test_viz.get_data(df) + # Check method correctly transforms data + self.assertEqual(set(['count', 'sum__A']), set(data['columns'])) + time_format = '%Y-%m-%d %H:%M:%S' + expected = { + t1.strftime(time_format): { + 'sum__A': 15, + 'count': 6, + }, + t2.strftime(time_format): { + 'sum__A': 20, + 'count': 7, + }, + } + self.assertEqual(expected, data['records']) + + def test_get_data_group_by(self): + form_data = { + 'metrics': ['sum__A'], + 'groupby': ['groupby1'], + } + datasource = Mock() + raw = {} + t1 = pd.Timestamp('2000') + t2 = pd.Timestamp('2002') + raw[DTTM_ALIAS] = [t1, t1, t1, t2, t2, t2] + raw['sum__A'] = [15, 20, 25, 30, 35, 40] + raw['groupby1'] = ['a1', 'a2', 'a3', 'a1', 'a2', 'a3'] + df = pd.DataFrame(raw) + test_viz = viz.TimeTableViz(datasource, form_data) + data = test_viz.get_data(df) + # Check method correctly transforms data + self.assertEqual(set(['a1', 'a2', 'a3']), set(data['columns'])) + time_format = '%Y-%m-%d %H:%M:%S' + expected = { + t1.strftime(time_format): { + 'a1': 15, + 'a2': 20, + 'a3': 25, + }, + t2.strftime(time_format): { + 'a1': 30, + 'a2': 35, + 'a3': 40, + }, + } + self.assertEqual(expected, data['records']) + + @patch('superset.viz.BaseViz.query_obj') + def test_query_obj_throws_metrics_and_groupby(self, super_query_obj): + datasource = Mock() + form_data = { + 'groupby': ['a'], + } + super_query_obj.return_value = {} + test_viz = viz.TimeTableViz(datasource, form_data) + with self.assertRaises(Exception): + test_viz.query_obj() + form_data['metrics'] = ['x', 'y'] + test_viz = viz.TimeTableViz(datasource, form_data) + with self.assertRaises(Exception): + test_viz.query_obj() -- To stop receiving notification emails like this one, please contact maximebeauche...@apache.org.