You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/04/13 00:20:41 UTC

[GitHub] mistercrunch closed pull request #4798: [DeckGL] Added fixtures and Deck test

mistercrunch closed pull request #4798: [DeckGL] Added fixtures and Deck test
URL: https://github.com/apache/incubator-superset/pull/4798
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/viz.py b/superset/viz.py
index f27406b758..8e4d76b2d7 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -2038,7 +2038,8 @@ def query_obj(self):
         metrics = self.get_metrics()
         if metrics:
             d['groupby'] = gb
-            d['metrics'] = self.get_metrics()
+            d['metrics'] = metrics
+            d['columns'] = []
         else:
             d['columns'] = gb
 
diff --git a/tests/fixtures/deck_geojson_form_data.json b/tests/fixtures/deck_geojson_form_data.json
new file mode 100644
index 0000000000..422197a285
--- /dev/null
+++ b/tests/fixtures/deck_geojson_form_data.json
@@ -0,0 +1,47 @@
+{
+  "color_picker": {
+    "a": 1,
+    "b": 135,
+    "g": 122,
+    "r": 0
+  },
+  "datasource": "12__table",
+  "filters": [],
+  "having": "",
+  "js_columns": [
+    "color"
+  ],
+  "js_datapoint_mutator": "d => {\n return {\n ...d,\n color: colors.hexToRGB(d.extraProps.color),\n }\n}",
+  "js_onclick_href": "",
+  "js_tooltip": "",
+  "mapbox_style": "mapbox://styles/mapbox/light-v9",
+  "reverse_long_lat": false,
+  "row_limit": 5000,
+  "since": "7 days ago",
+  "slice_id": 1013,
+  "time_grain_sqla": null,
+  "until": "now",
+  "geojson": "test_col",
+  "viewport": {
+    "altitude": 1.5,
+    "bearing": 0,
+    "height": 1094,
+    "latitude": 37.73671752604488,
+    "longitude": -122.18885402582598,
+    "maxLatitude": 85.05113,
+    "maxPitch": 60,
+    "maxZoom": 20,
+    "minLatitude": -85.05113,
+    "minPitch": 0,
+    "minZoom": 0,
+    "pitch": 0,
+    "width": 669,
+    "zoom": 9.51847667620428
+  },
+  "viz_type": "deck_geojson",
+  "where": "",
+  "granularity_sqla": null,
+  "autozoom": true,
+  "url_params": {},
+  "size": 100
+}
diff --git a/tests/fixtures/deck_path_form_data.json b/tests/fixtures/deck_path_form_data.json
new file mode 100644
index 0000000000..39cc2007f8
--- /dev/null
+++ b/tests/fixtures/deck_path_form_data.json
@@ -0,0 +1,49 @@
+{
+  "color_picker": {
+    "a": 1,
+    "b": 135,
+    "g": 122,
+    "r": 0
+  },
+  "datasource": "12__table",
+  "filters": [],
+  "having": "",
+  "js_columns": [
+    "color"
+  ],
+  "js_datapoint_mutator": "d => {\n return {\n ...d,\n color: colors.hexToRGB(d.extraProps.color),\n }\n}",
+  "js_onclick_href": "",
+  "js_tooltip": "",
+  "line_column": "path_json",
+  "line_type": "json",
+  "line_width": 150,
+  "mapbox_style": "mapbox://styles/mapbox/light-v9",
+  "reverse_long_lat": false,
+  "row_limit": 5000,
+  "since": "7 days ago",
+  "slice_id": 1013,
+  "time_grain_sqla": null,
+  "until": "now",
+  "viewport": {
+    "altitude": 1.5,
+    "bearing": 0,
+    "height": 1094,
+    "latitude": 37.73671752604488,
+    "longitude": -122.18885402582598,
+    "maxLatitude": 85.05113,
+    "maxPitch": 60,
+    "maxZoom": 20,
+    "minLatitude": -85.05113,
+    "minPitch": 0,
+    "minZoom": 0,
+    "pitch": 0,
+    "width": 669,
+    "zoom": 9.51847667620428
+  },
+  "viz_type": "deck_path",
+  "where": "",
+  "granularity_sqla": null,
+  "autozoom": true,
+  "url_params": {},
+  "size": 100
+}
diff --git a/tests/utils.py b/tests/utils.py
new file mode 100644
index 0000000000..d1a5adb01f
--- /dev/null
+++ b/tests/utils.py
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
+import json
+from os import path
+
+FIXTURES_DIR = 'tests/fixtures'
+
+
+def load_fixture(fixture_file_name):
+    with open(path.join(FIXTURES_DIR, fixture_file_name)) as fixture_file:
+        return json.load(fixture_file)
diff --git a/tests/viz_tests.py b/tests/viz_tests.py
index bb20946a0a..cec5464989 100644
--- a/tests/viz_tests.py
+++ b/tests/viz_tests.py
@@ -10,11 +10,14 @@
 from mock import Mock, patch
 import pandas as pd
 
+from tests.utils import load_fixture
+
 from superset.utils import DTTM_ALIAS
 import superset.viz as viz
 
 
 class BaseVizTestCase(unittest.TestCase):
+
     def test_constructor_exception_no_datasource(self):
         form_data = {}
         datasource = None
@@ -716,3 +719,108 @@ def test_query_obj_throws_metrics_and_groupby(self, super_query_obj):
         test_viz = viz.TimeTableViz(datasource, form_data)
         with self.assertRaises(Exception):
             test_viz.query_obj()
+
+
+class BaseDeckGLVizTestCase(unittest.TestCase):
+
+    def test_get_metrics(self):
+        form_data = load_fixture('deck_path_form_data.json')
+        datasource = {'type': 'table'}
+        test_viz_deckgl = viz.BaseDeckGLViz(datasource, form_data)
+        result = test_viz_deckgl.get_metrics()
+        assert result == [form_data.get('size')]
+
+        form_data = {}
+        test_viz_deckgl = viz.BaseDeckGLViz(datasource, form_data)
+        result = test_viz_deckgl.get_metrics()
+        assert result == []
+
+    def test_scatterviz_get_metrics(self):
+        form_data = load_fixture('deck_path_form_data.json')
+        datasource = {'type': 'table'}
+
+        form_data = {}
+        test_viz_deckgl = viz.DeckScatterViz(datasource, form_data)
+        test_viz_deckgl.point_radius_fixed = {'type': 'metric', 'value': 'int'}
+        result = test_viz_deckgl.get_metrics()
+        assert result == ['int']
+
+        form_data = {}
+        test_viz_deckgl = viz.DeckScatterViz(datasource, form_data)
+        test_viz_deckgl.point_radius_fixed = {}
+        result = test_viz_deckgl.get_metrics()
+        assert result is None
+
+    def test_get_js_columns(self):
+        form_data = load_fixture('deck_path_form_data.json')
+        datasource = {'type': 'table'}
+        mock_d = {
+            'a': 'dummy1',
+            'b': 'dummy2',
+            'c': 'dummy3',
+        }
+        test_viz_deckgl = viz.BaseDeckGLViz(datasource, form_data)
+        result = test_viz_deckgl.get_js_columns(mock_d)
+
+        assert result == {'color': None}
+
+    def test_get_properties(self):
+        mock_d = {}
+        form_data = load_fixture('deck_path_form_data.json')
+        datasource = {'type': 'table'}
+        test_viz_deckgl = viz.BaseDeckGLViz(datasource, form_data)
+
+        with self.assertRaises(NotImplementedError) as context:
+            test_viz_deckgl.get_properties(mock_d)
+
+        self.assertTrue('' in str(context.exception))
+
+    def test_process_spatial_query_obj(self):
+        form_data = load_fixture('deck_path_form_data.json')
+        datasource = {'type': 'table'}
+        mock_key = 'spatial_key'
+        mock_gb = []
+        test_viz_deckgl = viz.BaseDeckGLViz(datasource, form_data)
+
+        with self.assertRaises(ValueError) as context:
+            test_viz_deckgl.process_spatial_query_obj(mock_key, mock_gb)
+
+        self.assertTrue('Bad spatial key' in str(context.exception))
+
+        test_form_data = {
+            'latlong_key': {
+                'type': 'latlong',
+                'lonCol': 'lon',
+                'latCol': 'lat',
+            },
+            'delimited_key': {
+                'type': 'delimited',
+                'lonlatCol': 'lonlat',
+            },
+            'geohash_key': {
+                'type': 'geohash',
+                'geohashCol': 'geo',
+            },
+        }
+
+        datasource = {'type': 'table'}
+        expected_results = {
+            'latlong_key': ['lon', 'lat'],
+            'delimited_key': ['lonlat'],
+            'geohash_key': ['geo'],
+        }
+        for mock_key in ['latlong_key', 'delimited_key', 'geohash_key']:
+            mock_gb = []
+            test_viz_deckgl = viz.BaseDeckGLViz(datasource, test_form_data)
+            test_viz_deckgl.process_spatial_query_obj(mock_key, mock_gb)
+            assert expected_results.get(mock_key) == mock_gb
+
+    def test_geojson_query_obj(self):
+        form_data = load_fixture('deck_geojson_form_data.json')
+        datasource = {'type': 'table'}
+        test_viz_deckgl = viz.DeckGeoJson(datasource, form_data)
+        results = test_viz_deckgl.query_obj()
+
+        assert results['metrics'] == []
+        assert results['groupby'] == []
+        assert results['columns'] == ['test_col']


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services