You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2018/04/13 00:20:41 UTC
[incubator-superset] branch master updated: [DeckGL] Added fixtures
and Deck test (#4798)
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 2f5cff7 [DeckGL] Added fixtures and Deck test (#4798)
2f5cff7 is described below
commit 2f5cff7d9ff2f88c1a6fb51632a7b3e29e75f0d1
Author: Hugh A. Miles II <hu...@gmail.com>
AuthorDate: Thu Apr 12 18:20:39 2018 -0600
[DeckGL] Added fixtures and Deck test (#4798)
* added fixtures and deck test
* linting
* linting
* add os.path
* remove para
* fix reference
---
superset/viz.py | 3 +-
tests/fixtures/deck_geojson_form_data.json | 47 +++++++++++++
tests/fixtures/deck_path_form_data.json | 49 +++++++++++++
tests/utils.py | 15 ++++
tests/viz_tests.py | 108 +++++++++++++++++++++++++++++
5 files changed, 221 insertions(+), 1 deletion(-)
diff --git a/superset/viz.py b/superset/viz.py
index 5ec9a23..b1502d8 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -2046,7 +2046,8 @@ class BaseDeckGLViz(BaseViz):
gb = list(set(gb))
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 0000000..422197a
--- /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 0000000..39cc200
--- /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 0000000..d1a5adb
--- /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 bb20946..cec5464 100644
--- a/tests/viz_tests.py
+++ b/tests/viz_tests.py
@@ -10,11 +10,14 @@ import unittest
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 @@ class TimeSeriesTableVizTestCase(unittest.TestCase):
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']
--
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.