[DeckGL] Added fixtures and Deck test (#4798)
* added fixtures and deck test * linting * linting * add os.path * remove para * fix reference
This commit is contained in:
parent
6fd4ff45ea
commit
2f5cff7d9f
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
@ -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']
|
||||
|
|
|
|||
Loading…
Reference in New Issue