test: World bank examples (#12161)

* add world bank data fixture

* fix fixture cleanup, add fixture to dashboard_tests

* apply world bank fixtures, fix tests

* fix fixture typo, dashboard ids

* fix export dashboard metadata

* fix test_export_dashboard_command_key_order

* fix export dash tests, not add row when no orphans

* debug timeout

* fixes after merge

* fix lint

* run pre-commit

* comment test for debug

* fix save.test.js

Co-authored-by: Karol Kostrzewa <karol.kostrzewa@polidea.com>
This commit is contained in:
Karol Kostrzewa
2021-01-13 23:20:05 +01:00
committed by Ville Brofeldt
parent 0acd2ccaaa
commit bc53be95a5
22 changed files with 807 additions and 225 deletions

View File

@@ -33,6 +33,7 @@ import yaml
from sqlalchemy import and_, or_
from sqlalchemy.sql import func
from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices
from tests.test_app import app
from superset.charts.commands.data import ChartDataCommand
from superset.connectors.connector_registry import ConnectorRegistry
@@ -435,7 +436,10 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
db.session.delete(user_alpha2)
db.session.commit()
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@pytest.mark.usefixtures(
"load_world_bank_dashboard_with_slices",
"load_birth_names_dashboard_with_slices",
)
def test_create_chart(self):
"""
Chart API: Test create chart
@@ -544,15 +548,18 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
response, {"message": {"datasource_id": ["Datasource does not exist"]}}
)
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_update_chart(self):
"""
Chart API: Test update
"""
admin = self.get_user("admin")
gamma = self.get_user("gamma")
chart_id = self.insert_chart("title", [admin.id], 1, admin).id
birth_names_table_id = SupersetTestCase.get_table_by_name("birth_names").id
chart_id = self.insert_chart(
"title", [admin.id], birth_names_table_id, admin
).id
dash_id = db.session.query(Dashboard.id).filter_by(slug="births").first()[0]
chart_data = {
"slice_name": "title1_changed",
"description": "description1",
@@ -562,14 +569,14 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
"cache_timeout": 1000,
"datasource_id": birth_names_table_id,
"datasource_type": "table",
"dashboards": [1],
"dashboards": [dash_id],
}
self.login(username="admin")
uri = f"api/v1/chart/{chart_id}"
rv = self.put_assert_metric(uri, chart_data, "put")
self.assertEqual(rv.status_code, 200)
model = db.session.query(Slice).get(chart_id)
related_dashboard = db.session.query(Dashboard).get(1)
related_dashboard = db.session.query(Dashboard).filter_by(slug="births").first()
self.assertEqual(model.created_by, admin)
self.assertEqual(model.slice_name, "title1_changed")
self.assertEqual(model.description, "description1")
@@ -581,7 +588,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
self.assertEqual(model.datasource_id, birth_names_table_id)
self.assertEqual(model.datasource_type, "table")
self.assertEqual(model.datasource_name, "birth_names")
self.assertIn(related_dashboard, model.dashboards)
self.assertIn(model.id, [slice.id for slice in related_dashboard.slices])
db.session.delete(model)
db.session.commit()
@@ -698,6 +705,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
expected_response = {"message": {"owners": ["Owners are invalid"]}}
self.assertEqual(response, expected_response)
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_get_chart(self):
"""
Chart API: Test get chart
@@ -758,6 +766,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
"load_energy_table_with_slice",
"load_birth_names_dashboard_with_slices",
"load_unicode_dashboard_with_slice",
"load_world_bank_dashboard_with_slices",
)
def test_get_charts(self):
"""
@@ -798,7 +807,10 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
db.session.delete(chart)
db.session.commit()
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@pytest.mark.usefixtures(
"load_world_bank_dashboard_with_slices",
"load_birth_names_dashboard_with_slices",
)
def test_get_charts_filter(self):
"""
Chart API: Test get charts filter
@@ -1008,6 +1020,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
@pytest.mark.usefixtures(
"load_unicode_dashboard_with_slice",
"load_energy_table_with_slice",
"load_world_bank_dashboard_with_slices",
"load_birth_names_dashboard_with_slices",
)
def test_get_charts_page(self):