From 17e1a62d964df67adfa834fcacfc37452e9cbca2 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 15 Oct 2018 10:58:00 -0700 Subject: [PATCH] Make loading examples in scope for tests --- superset/data/__init__.py | 9 ++++--- tests/core_tests.py | 2 +- tests/load_examples_test.py | 51 +++++++++++++++++++++++++++++++++++++ tox.ini | 5 ++-- 4 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 tests/load_examples_test.py diff --git a/superset/data/__init__.py b/superset/data/__init__.py index deb0c0d6c186a..49873eb231bca 100644 --- a/superset/data/__init__.py +++ b/superset/data/__init__.py @@ -7,10 +7,10 @@ import random import textwrap -import pandas as pd -from sqlalchemy import BigInteger, Date, DateTime, Float, String, Text import geohash +import pandas as pd import polyline +from sqlalchemy import BigInteger, Date, DateTime, Float, String, Text from superset import app, db from superset.connectors.connector_registry import ConnectorRegistry @@ -27,7 +27,7 @@ config = app.config -DATA_FOLDER = os.path.join(config.get("BASE_DIR"), 'data') +DATA_FOLDER = os.path.join(config.get('BASE_DIR'), 'data') misc_dash_slices = set() # slices assembled in a "Misc Chart" dashboard @@ -39,7 +39,8 @@ def update_slice_ids(layout_dict, slices): ] sorted_charts = sorted(charts, key=lambda k: k['meta']['chartId']) for i, chart_component in enumerate(sorted_charts): - chart_component['meta']['chartId'] = int(slices[i].id) + if i < len(slices): + chart_component['meta']['chartId'] = int(slices[i].id) def merge_slice(slc): diff --git a/tests/core_tests.py b/tests/core_tests.py index a09117d2cf68a..db1961d980baf 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -372,7 +372,7 @@ def test_warm_up_cache(self): data = self.get_json_resp( '/superset/warm_up_cache?table_name=energy_usage&db_name=main') - assert len(data) == 4 + assert len(data) > 0 def test_shortner(self): self.login(username='admin') diff --git a/tests/load_examples_test.py b/tests/load_examples_test.py new file mode 100644 index 0000000000000..d2b1005cd521a --- /dev/null +++ b/tests/load_examples_test.py @@ -0,0 +1,51 @@ +from superset import data +from superset.cli import load_test_users_run +from .base_tests import SupersetTestCase + + +class SupersetDataFrameTestCase(SupersetTestCase): + + def test_load_css_templates(self): + data.load_css_templates() + + def test_load_energy(self): + data.load_energy() + + def test_load_world_bank_health_n_pop(self): + data.load_world_bank_health_n_pop() + + def test_load_birth_names(self): + data.load_birth_names() + + def test_load_random_time_series_data(self): + data.load_random_time_series_data() + + def test_load_country_map_data(self): + data.load_country_map_data() + + def test_load_multiformat_time_series_data(self): + data.load_multiformat_time_series_data() + + def test_load_paris_iris_geojson(self): + data.load_paris_iris_geojson() + + def test_load_bart_lines(self): + data.load_bart_lines() + + def test_load_multi_line(self): + data.load_multi_line() + + def test_load_misc_dashboard(self): + data.load_misc_dashboard() + + def test_load_unicode_test_data(self): + data.load_unicode_test_data() + + def test_load_deck_dash(self): + data.load_long_lat_data() + data.load_flights() + data.load_sf_population_polygons() + data.load_deck_dash() + + def test_load_test_users_run(self): + load_test_users_run() diff --git a/tox.ini b/tox.ini index f8fa08caa0077..53949a34c9b4e 100644 --- a/tox.ini +++ b/tox.ini @@ -27,9 +27,8 @@ require-code = true [testenv] commands = {toxinidir}/superset/bin/superset db upgrade - {toxinidir}/superset/bin/superset load_test_users - {toxinidir}/superset/bin/superset load_examples - nosetests {posargs} + nosetests tests/load_examples_test.py + nosetests -e load_examples_test {posargs} deps = -rrequirements.txt -rrequirements-dev.txt