diff --git a/tests/integration_tests/base_api_tests.py b/tests/integration_tests/base_api_tests.py index 25b4b135665d0..09a754e392382 100644 --- a/tests/integration_tests/base_api_tests.py +++ b/tests/integration_tests/base_api_tests.py @@ -17,7 +17,8 @@ # isort:skip_file import json from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) import pytest diff --git a/tests/integration_tests/cache_tests.py b/tests/integration_tests/cache_tests.py index 971dcd3264015..62edb514b35cc 100644 --- a/tests/integration_tests/cache_tests.py +++ b/tests/integration_tests/cache_tests.py @@ -23,7 +23,8 @@ from superset.common.db_query_status import QueryStatus from superset.extensions import cache_manager from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from .base_tests import SupersetTestCase diff --git a/tests/integration_tests/celery_tests.py b/tests/integration_tests/celery_tests.py index 317d4b5d5f068..1fd076f25bcc1 100644 --- a/tests/integration_tests/celery_tests.py +++ b/tests/integration_tests/celery_tests.py @@ -24,7 +24,8 @@ import unittest.mock as mock from typing import Optional from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) import pytest diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py index 78b7d7d6e8daa..c688044eb51aa 100644 --- a/tests/integration_tests/charts/api_tests.py +++ b/tests/integration_tests/charts/api_tests.py @@ -39,10 +39,12 @@ from tests.integration_tests.base_api_tests import ApiOwnersTestCaseMixin from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_with_slice, + load_energy_table_data, ) from tests.integration_tests.fixtures.importexport import ( chart_config, @@ -52,10 +54,12 @@ dataset_metadata_config, ) from tests.integration_tests.fixtures.unicode_dashboard import ( - load_unicode_dashboard_with_slice, load_unicode_data + load_unicode_dashboard_with_slice, + load_unicode_data, ) from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) from tests.integration_tests.insert_chart_mixin import InsertChartMixin from tests.integration_tests.test_app import app diff --git a/tests/integration_tests/charts/commands_tests.py b/tests/integration_tests/charts/commands_tests.py index 65d34534a21ff..4e8ffa1af7706 100644 --- a/tests/integration_tests/charts/commands_tests.py +++ b/tests/integration_tests/charts/commands_tests.py @@ -34,7 +34,8 @@ from superset.models.slice import Slice from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_data, + load_energy_table_with_slice, ) from tests.integration_tests.fixtures.importexport import ( chart_config, diff --git a/tests/integration_tests/charts/data/api_tests.py b/tests/integration_tests/charts/data/api_tests.py index 010b7d18172c0..1e6aa5601d034 100644 --- a/tests/integration_tests/charts/data/api_tests.py +++ b/tests/integration_tests/charts/data/api_tests.py @@ -31,7 +31,8 @@ ) from tests.integration_tests.annotation_layers.fixtures import create_annotation_layers from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.test_app import app diff --git a/tests/integration_tests/charts/schema_tests.py b/tests/integration_tests/charts/schema_tests.py index c0e0e019ddb47..c28699f3302e4 100644 --- a/tests/integration_tests/charts/schema_tests.py +++ b/tests/integration_tests/charts/schema_tests.py @@ -25,7 +25,8 @@ from superset.charts.schemas import ChartDataQueryContextSchema from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.query_context import get_query_context diff --git a/tests/integration_tests/cli_tests.py b/tests/integration_tests/cli_tests.py index f471b82925aa2..58616272606cd 100644 --- a/tests/integration_tests/cli_tests.py +++ b/tests/integration_tests/cli_tests.py @@ -29,7 +29,8 @@ import superset.cli from superset import app from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) logger = logging.getLogger(__name__) diff --git a/tests/integration_tests/core_tests.py b/tests/integration_tests/core_tests.py index 8583994892622..67e5e5da0a2df 100644 --- a/tests/integration_tests/core_tests.py +++ b/tests/integration_tests/core_tests.py @@ -26,7 +26,8 @@ from typing import Dict, List from urllib.parse import quote from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) import pytest @@ -43,7 +44,8 @@ from superset.utils.core import get_example_database from tests.integration_tests.conftest import with_feature_flags from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_with_slice, + load_energy_table_data, ) from tests.integration_tests.test_app import app import superset.views.utils @@ -72,7 +74,8 @@ from .base_tests import SupersetTestCase from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) logger = logging.getLogger(__name__) diff --git a/tests/integration_tests/dashboard_tests.py b/tests/integration_tests/dashboard_tests.py index c362ce1fef454..63453d85ee4fc 100644 --- a/tests/integration_tests/dashboard_tests.py +++ b/tests/integration_tests/dashboard_tests.py @@ -32,17 +32,21 @@ from superset.models.dashboard import Dashboard from superset.models.slice import Slice from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_with_slice, + load_energy_table_data, ) from tests.integration_tests.fixtures.public_role import public_role_like_gamma from tests.integration_tests.fixtures.unicode_dashboard import ( load_unicode_dashboard_with_position, + load_unicode_data, ) from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) from .base_tests import SupersetTestCase diff --git a/tests/integration_tests/dashboard_utils.py b/tests/integration_tests/dashboard_utils.py index bf68e0e67b09a..3c314312b9c6a 100644 --- a/tests/integration_tests/dashboard_utils.py +++ b/tests/integration_tests/dashboard_utils.py @@ -41,28 +41,15 @@ def get_table( ) -def create_table_for_dashboard( - df: DataFrame, +def create_table_metadata( table_name: str, database: Database, - dtype: Dict[str, Any], table_description: str = "", fetch_values_predicate: Optional[str] = None, schema: Optional[str] = None, ) -> SqlaTable: schema = schema or get_example_default_schema() - df.to_sql( - table_name, - database.get_sqla_engine(), - if_exists="replace", - chunksize=500, - dtype=dtype, - index=False, - method="multi", - schema=schema, - ) - table = get_table(table_name, database, schema) if not table: table_source = ConnectorRegistry.sources["table"] diff --git a/tests/integration_tests/dashboards/api_tests.py b/tests/integration_tests/dashboards/api_tests.py index aa30e38c62519..755eb3776016d 100644 --- a/tests/integration_tests/dashboards/api_tests.py +++ b/tests/integration_tests/dashboards/api_tests.py @@ -52,10 +52,12 @@ ) from tests.integration_tests.utils.get_dashboards import get_dashboards_ids from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) DASHBOARDS_FIXTURE_COUNT = 10 diff --git a/tests/integration_tests/dashboards/commands_tests.py b/tests/integration_tests/dashboards/commands_tests.py index 1c76d07100e96..7c7a2046f0592 100644 --- a/tests/integration_tests/dashboards/commands_tests.py +++ b/tests/integration_tests/dashboards/commands_tests.py @@ -47,7 +47,8 @@ dataset_metadata_config, ) from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) diff --git a/tests/integration_tests/dashboards/dao_tests.py b/tests/integration_tests/dashboards/dao_tests.py index 77abbe784af18..4a02cd7107acd 100644 --- a/tests/integration_tests/dashboards/dao_tests.py +++ b/tests/integration_tests/dashboards/dao_tests.py @@ -27,7 +27,8 @@ from superset.models.dashboard import Dashboard from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) diff --git a/tests/integration_tests/dashboards/filter_state/api_tests.py b/tests/integration_tests/dashboards/filter_state/api_tests.py index 43aa410fd999b..bd0e2e7d97753 100644 --- a/tests/integration_tests/dashboards/filter_state/api_tests.py +++ b/tests/integration_tests/dashboards/filter_state/api_tests.py @@ -29,7 +29,8 @@ from superset.models.dashboard import Dashboard from tests.integration_tests.base_tests import login from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) from tests.integration_tests.test_app import app diff --git a/tests/integration_tests/dashboards/security/security_dataset_tests.py b/tests/integration_tests/dashboards/security/security_dataset_tests.py index 0b0f5618d7c96..01bce014afdc5 100644 --- a/tests/integration_tests/dashboards/security/security_dataset_tests.py +++ b/tests/integration_tests/dashboards/security/security_dataset_tests.py @@ -28,7 +28,8 @@ from tests.integration_tests.dashboards.dashboard_test_utils import * from tests.integration_tests.dashboards.superset_factory_util import * from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_data, + load_energy_table_with_slice, ) diff --git a/tests/integration_tests/dashboards/security/security_rbac_tests.py b/tests/integration_tests/dashboards/security/security_rbac_tests.py index 58f71613e0acc..5a1f02f1e3243 100644 --- a/tests/integration_tests/dashboards/security/security_rbac_tests.py +++ b/tests/integration_tests/dashboards/security/security_rbac_tests.py @@ -31,7 +31,8 @@ create_slice_to_db, ) from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.public_role import public_role_like_gamma from tests.integration_tests.fixtures.query_context import get_query_context diff --git a/tests/integration_tests/databases/api_tests.py b/tests/integration_tests/databases/api_tests.py index 5664ecf2fd014..a64eb3f7dcfec 100644 --- a/tests/integration_tests/databases/api_tests.py +++ b/tests/integration_tests/databases/api_tests.py @@ -46,14 +46,17 @@ from superset.utils.core import get_example_database, get_main_database from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.certificates import ssl_certificate from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_with_slice, + load_energy_table_data, ) from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) from tests.integration_tests.fixtures.importexport import ( database_config, @@ -63,6 +66,7 @@ ) from tests.integration_tests.fixtures.unicode_dashboard import ( load_unicode_dashboard_with_position, + load_unicode_data, ) from tests.integration_tests.test_app import app diff --git a/tests/integration_tests/databases/commands_tests.py b/tests/integration_tests/databases/commands_tests.py index 456a5d582c786..5860b23fd91bc 100644 --- a/tests/integration_tests/databases/commands_tests.py +++ b/tests/integration_tests/databases/commands_tests.py @@ -43,10 +43,12 @@ from superset.utils.core import backend, get_example_database from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_data, + load_energy_table_with_slice, ) from tests.integration_tests.fixtures.importexport import ( database_config, diff --git a/tests/integration_tests/datasets/api_tests.py b/tests/integration_tests/datasets/api_tests.py index 42eac14872ea0..03209fd94fdf2 100644 --- a/tests/integration_tests/datasets/api_tests.py +++ b/tests/integration_tests/datasets/api_tests.py @@ -45,10 +45,12 @@ from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.conftest import CTAS_SCHEMA_NAME from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_data, + load_energy_table_with_slice, ) from tests.integration_tests.fixtures.importexport import ( database_config, diff --git a/tests/integration_tests/datasets/commands_tests.py b/tests/integration_tests/datasets/commands_tests.py index 45c3a887678ef..67ff3a7918ae1 100644 --- a/tests/integration_tests/datasets/commands_tests.py +++ b/tests/integration_tests/datasets/commands_tests.py @@ -33,7 +33,8 @@ from superset.utils.core import get_example_database, get_example_default_schema from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_data, + load_energy_table_with_slice, ) from tests.integration_tests.fixtures.importexport import ( database_config, @@ -44,7 +45,8 @@ dataset_ui_export, ) from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) diff --git a/tests/integration_tests/datasource_tests.py b/tests/integration_tests/datasource_tests.py index e7974d6eb8b2d..c923f2ebbfdcb 100644 --- a/tests/integration_tests/datasource_tests.py +++ b/tests/integration_tests/datasource_tests.py @@ -30,7 +30,8 @@ from superset.utils.core import get_example_database, get_example_default_schema from tests.integration_tests.base_tests import db_insert_temp_object, SupersetTestCase from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.datasource import get_datasource_post diff --git a/tests/integration_tests/db_engine_specs/base_engine_spec_tests.py b/tests/integration_tests/db_engine_specs/base_engine_spec_tests.py index 294c6801e7532..e568b59a2ba21 100644 --- a/tests/integration_tests/db_engine_specs/base_engine_spec_tests.py +++ b/tests/integration_tests/db_engine_specs/base_engine_spec_tests.py @@ -35,8 +35,14 @@ from tests.integration_tests.db_engine_specs.base_tests import TestDbEngineSpec from tests.integration_tests.test_app import app -from ..fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices -from ..fixtures.energy_dashboard import load_energy_table_with_slice +from ..fixtures.birth_names_dashboard import ( + load_birth_names_dashboard_with_slices, + load_birth_names_data, +) +from ..fixtures.energy_dashboard import ( + load_energy_table_data, + load_energy_table_with_slice, +) from ..fixtures.pyodbcRow import Row diff --git a/tests/integration_tests/db_engine_specs/bigquery_tests.py b/tests/integration_tests/db_engine_specs/bigquery_tests.py index ad9aec4475828..b7405092c5446 100644 --- a/tests/integration_tests/db_engine_specs/bigquery_tests.py +++ b/tests/integration_tests/db_engine_specs/bigquery_tests.py @@ -28,7 +28,8 @@ from superset.sql_parse import Table from tests.integration_tests.db_engine_specs.base_tests import TestDbEngineSpec from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) diff --git a/tests/integration_tests/fixtures/__init__.py b/tests/integration_tests/fixtures/__init__.py index facd523d85078..0e06be352ece5 100644 --- a/tests/integration_tests/fixtures/__init__.py +++ b/tests/integration_tests/fixtures/__init__.py @@ -19,7 +19,7 @@ load_birth_names_dashboard_with_slices, load_birth_names_dashboard_with_slices_module_scope, ) -from .energy_dashboard import load_energy_table_with_slice, load_energy_table_data +from .energy_dashboard import load_energy_table_data, load_energy_table_with_slice from .public_role import public_role_like_gamma, public_role_like_test_role from .unicode_dashboard import ( load_unicode_dashboard_with_position, diff --git a/tests/integration_tests/fixtures/birth_names_dashboard.py b/tests/integration_tests/fixtures/birth_names_dashboard.py index 5c10d977d1c8a..56d1bc2870288 100644 --- a/tests/integration_tests/fixtures/birth_names_dashboard.py +++ b/tests/integration_tests/fixtures/birth_names_dashboard.py @@ -31,10 +31,7 @@ from superset.models.dashboard import Dashboard from superset.models.slice import Slice from superset.utils.core import get_example_database, get_example_default_schema -from tests.integration_tests.dashboard_utils import ( - create_table_for_dashboard, - get_table, -) +from tests.integration_tests.dashboard_utils import create_table_metadata from tests.integration_tests.test_app import app BIRTH_NAMES_TBL_NAME = "birth_names" @@ -51,12 +48,16 @@ def load_birth_names_data(): "state": String(10), "name": String(255), } - _create_table( - df=df, - table_name=BIRTH_NAMES_TBL_NAME, - database=database, + + df.to_sql( + BIRTH_NAMES_TBL_NAME, + database.get_sqla_engine(), + if_exists="replace", + chunksize=500, dtype=dtype, - fetch_values_predicate="123 = 123", + index=False, + method="multi", + schema=get_example_default_schema(), ) yield with app.app_context(): @@ -81,9 +82,14 @@ def load_birth_names_dashboard_with_slices_module_scope(load_birth_names_data): def _create_dashboards(): + table = _create_table( + table_name=BIRTH_NAMES_TBL_NAME, + database=get_example_database(), + fetch_values_predicate="123 = 123", + ) + from superset.examples.birth_names import create_dashboard, create_slices - table = get_table(BIRTH_NAMES_TBL_NAME, get_example_database()) slices, _ = create_slices(table, admin_owner=False) dash = create_dashboard(slices) slices_ids_to_delete = [slice.id for slice in slices] @@ -92,17 +98,11 @@ def _create_dashboards(): def _create_table( - df: DataFrame, - table_name: str, - database: "Database", - dtype: Dict[str, Any], - fetch_values_predicate: Optional[str] = None, + table_name: str, database: "Database", fetch_values_predicate: Optional[str] = None, ): - table = create_table_for_dashboard( - df=df, + table = create_table_metadata( table_name=table_name, database=database, - dtype=dtype, fetch_values_predicate=fetch_values_predicate, ) from superset.examples.birth_names import _add_table_metrics, _set_table_metadata diff --git a/tests/integration_tests/fixtures/energy_dashboard.py b/tests/integration_tests/fixtures/energy_dashboard.py index 2c8b47b6280e4..767c89456a34e 100644 --- a/tests/integration_tests/fixtures/energy_dashboard.py +++ b/tests/integration_tests/fixtures/energy_dashboard.py @@ -24,12 +24,8 @@ from superset import db from superset.connectors.sqla.models import SqlaTable, SqlMetric from superset.models.slice import Slice -from superset.utils.core import get_example_database -from tests.integration_tests.dashboard_utils import ( - create_slice, - create_table_for_dashboard, - get_table, -) +from superset.utils.core import get_example_database, get_example_default_schema +from tests.integration_tests.dashboard_utils import create_slice, create_table_metadata from tests.integration_tests.test_app import app misc_dash_slices: Set[str] = set() @@ -42,11 +38,15 @@ def load_energy_table_data(): with app.app_context(): database = get_example_database() - table_description = "Energy consumption" df = _get_dataframe() - schema = {"source": String(255), "target": String(255), "value": Float()} - create_table_for_dashboard( - df, ENERGY_USAGE_TBL_NAME, database, schema, table_description + df.to_sql( + ENERGY_USAGE_TBL_NAME, + database.get_sqla_engine(), + if_exists="replace", + chunksize=500, + index=False, + method="multi", + schema=get_example_default_schema(), ) yield with app.app_context(): @@ -54,7 +54,6 @@ def load_energy_table_data(): engine.execute("DROP TABLE IF EXISTS energy_usage") - @pytest.fixture() def load_energy_table_with_slice(load_energy_table_data): with app.app_context(): @@ -69,7 +68,9 @@ def _get_dataframe(): def _create_energy_table(): - table = get_table(ENERGY_USAGE_TBL_NAME, get_example_database()) + table = create_table_metadata( + table_name=ENERGY_USAGE_TBL_NAME, database=get_example_database(), + ) table.fetch_metadata() if not any(col.metric_name == "sum__value" for col in table.metrics): diff --git a/tests/integration_tests/fixtures/unicode_dashboard.py b/tests/integration_tests/fixtures/unicode_dashboard.py index 873660fc40874..1f1218c8f7dbc 100644 --- a/tests/integration_tests/fixtures/unicode_dashboard.py +++ b/tests/integration_tests/fixtures/unicode_dashboard.py @@ -22,12 +22,11 @@ from superset.connectors.sqla.models import SqlaTable from superset.models.dashboard import Dashboard from superset.models.slice import Slice -from superset.utils.core import get_example_database +from superset.utils.core import get_example_database, get_example_default_schema from tests.integration_tests.dashboard_utils import ( create_dashboard, create_slice, - create_table_for_dashboard, - get_table, + create_table_metadata, ) from tests.integration_tests.test_app import app @@ -37,12 +36,16 @@ @pytest.fixture(scope="session") def load_unicode_data(): with app.app_context(): - database = get_example_database() - dtype = { - "phrase": String(500), - } - df = _get_dataframe() - create_table_for_dashboard(df, UNICODE_TBL_NAME, database, dtype) + _get_dataframe().to_sql( + UNICODE_TBL_NAME, + get_example_database().get_sqla_engine(), + if_exists="replace", + chunksize=500, + dtype={"phrase": String(500)}, + index=False, + method="multi", + schema=get_example_default_schema(), + ) yield with app.app_context(): @@ -88,7 +91,7 @@ def _get_unicode_data(): def _create_unicode_dashboard(slice_title: str, position: str) -> Dashboard: - table = get_table(UNICODE_TBL_NAME, get_example_database()) + table = create_table_metadata(UNICODE_TBL_NAME, get_example_database()) table.fetch_metadata() if slice_title: diff --git a/tests/integration_tests/fixtures/world_bank_dashboard.py b/tests/integration_tests/fixtures/world_bank_dashboard.py index efcf3a59895cd..0782c8bdf543b 100644 --- a/tests/integration_tests/fixtures/world_bank_dashboard.py +++ b/tests/integration_tests/fixtures/world_bank_dashboard.py @@ -29,11 +29,10 @@ from superset.models.core import Database from superset.models.dashboard import Dashboard from superset.models.slice import Slice -from superset.utils.core import get_example_database +from superset.utils.core import get_example_database, get_example_default_schema from tests.integration_tests.dashboard_utils import ( create_dashboard, - create_table_for_dashboard, - get_table, + create_table_metadata, ) from tests.integration_tests.test_app import app @@ -44,14 +43,22 @@ def load_world_bank_data(): with app.app_context(): database = get_example_database() - df = _get_dataframe(database) dtype = { "year": DateTime if database.backend != "presto" else String(255), "country_code": String(3), "country_name": String(255), "region": String(255), } - create_table_for_dashboard(df, WB_HEALTH_POPULATION, database, dtype) + _get_dataframe(database).to_sql( + WB_HEALTH_POPULATION, + get_example_database().get_sqla_engine(), + if_exists="replace", + chunksize=500, + dtype=dtype, + index=False, + method="multi", + schema=get_example_default_schema(), + ) yield with app.app_context(): @@ -77,7 +84,7 @@ def load_world_bank_dashboard_with_slices_module_scope(load_world_bank_data): def create_dashboard_for_loaded_data(): with app.app_context(): - table = get_table(WB_HEALTH_POPULATION, get_example_database()) + table = create_table_metadata(WB_HEALTH_POPULATION, get_example_database()) slices = _create_world_bank_slices(table) dash = _create_world_bank_dashboard(table, slices) slices_ids_to_delete = [slice.id for slice in slices] diff --git a/tests/integration_tests/import_export_tests.py b/tests/integration_tests/import_export_tests.py index 1b163651bc6e6..1745f5e01c2fe 100644 --- a/tests/integration_tests/import_export_tests.py +++ b/tests/integration_tests/import_export_tests.py @@ -19,7 +19,8 @@ import json import unittest from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) import pytest @@ -27,7 +28,8 @@ from sqlalchemy.orm.session import make_transient from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_with_slice, + load_energy_table_data, ) from tests.integration_tests.test_app import app from superset.dashboards.commands.importers.v0 import decode_dashboards @@ -46,7 +48,8 @@ from superset.utils.core import get_example_database, get_example_default_schema from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) from .base_tests import SupersetTestCase diff --git a/tests/integration_tests/model_tests.py b/tests/integration_tests/model_tests.py index e8779945215ff..bcd57726ff63e 100644 --- a/tests/integration_tests/model_tests.py +++ b/tests/integration_tests/model_tests.py @@ -21,7 +21,8 @@ from superset.exceptions import SupersetException from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) import pytest @@ -38,7 +39,10 @@ from superset.utils.core import get_example_database from .base_tests import SupersetTestCase -from .fixtures.energy_dashboard import load_energy_table_with_slice +from .fixtures.energy_dashboard import ( + load_energy_table_with_slice, + load_energy_table_data, +) class TestDatabaseModel(SupersetTestCase): diff --git a/tests/integration_tests/query_context_tests.py b/tests/integration_tests/query_context_tests.py index 4a319f6cf34ff..91ce67bb84681 100644 --- a/tests/integration_tests/query_context_tests.py +++ b/tests/integration_tests/query_context_tests.py @@ -33,7 +33,8 @@ from superset.utils.core import AdhocMetricExpressionType, backend, TimeRangeEndpoint from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.query_context import get_query_context diff --git a/tests/integration_tests/reports/api_tests.py b/tests/integration_tests/reports/api_tests.py index f1395cc997e15..fa9e36d104a8c 100644 --- a/tests/integration_tests/reports/api_tests.py +++ b/tests/integration_tests/reports/api_tests.py @@ -42,7 +42,8 @@ from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.conftest import with_feature_flags from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.reports.utils import insert_report_schedule diff --git a/tests/integration_tests/reports/commands_tests.py b/tests/integration_tests/reports/commands_tests.py index 5e406c604abac..3a7cc873e3131 100644 --- a/tests/integration_tests/reports/commands_tests.py +++ b/tests/integration_tests/reports/commands_tests.py @@ -58,10 +58,12 @@ from superset.reports.commands.log_prune import AsyncPruneReportScheduleLogCommand from superset.utils.core import get_example_database from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.world_bank_dashboard import ( load_world_bank_dashboard_with_slices_module_scope, + load_world_bank_data, ) from tests.integration_tests.reports.utils import insert_report_schedule from tests.integration_tests.test_app import app diff --git a/tests/integration_tests/schedules_test.py b/tests/integration_tests/schedules_test.py index bc63feff1cc11..b5cfe716051ae 100644 --- a/tests/integration_tests/schedules_test.py +++ b/tests/integration_tests/schedules_test.py @@ -25,7 +25,8 @@ from slack import errors, WebClient from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) from tests.integration_tests.test_app import app from superset import db diff --git a/tests/integration_tests/security_tests.py b/tests/integration_tests/security_tests.py index b84911309d6d3..9863e1b316c35 100644 --- a/tests/integration_tests/security_tests.py +++ b/tests/integration_tests/security_tests.py @@ -47,20 +47,24 @@ from .base_tests import SupersetTestCase from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.energy_dashboard import ( - load_energy_table_with_slice, load_energy_table_data + load_energy_table_with_slice, + load_energy_table_data, ) from tests.integration_tests.fixtures.public_role import ( public_role_like_gamma, public_role_like_test_role, ) from tests.integration_tests.fixtures.unicode_dashboard import ( - load_unicode_dashboard_with_slice, load_unicode_data + load_unicode_dashboard_with_slice, + load_unicode_data, ) from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) NEW_SECURITY_CONVERGE_VIEWS = ( diff --git a/tests/integration_tests/sqla_models_tests.py b/tests/integration_tests/sqla_models_tests.py index ac130d4041520..00d38590091c6 100644 --- a/tests/integration_tests/sqla_models_tests.py +++ b/tests/integration_tests/sqla_models_tests.py @@ -43,7 +43,8 @@ TemporalType, ) from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from .base_tests import SupersetTestCase diff --git a/tests/integration_tests/sqllab_tests.py b/tests/integration_tests/sqllab_tests.py index bd25e7469a575..2dce2c11f3799 100644 --- a/tests/integration_tests/sqllab_tests.py +++ b/tests/integration_tests/sqllab_tests.py @@ -57,7 +57,8 @@ from .base_tests import SupersetTestCase from .conftest import CTAS_SCHEMA_NAME from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) QUERY_1 = "SELECT * FROM birth_names LIMIT 1" diff --git a/tests/integration_tests/strategy_tests.py b/tests/integration_tests/strategy_tests.py index 339157bb7dd00..59430f80b856a 100644 --- a/tests/integration_tests/strategy_tests.py +++ b/tests/integration_tests/strategy_tests.py @@ -20,7 +20,8 @@ import json from unittest.mock import MagicMock from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from sqlalchemy import String, Date, Float @@ -42,8 +43,11 @@ ) from .base_tests import SupersetTestCase -from .dashboard_utils import create_dashboard, create_slice, create_table_for_dashboard -from .fixtures.unicode_dashboard import load_unicode_dashboard_with_slice +from .dashboard_utils import create_dashboard, create_slice, create_table_metadata +from .fixtures.unicode_dashboard import ( + load_unicode_dashboard_with_slice, + load_unicode_data, +) URL_PREFIX = "http://0.0.0.0:8081" diff --git a/tests/integration_tests/tasks/async_queries_tests.py b/tests/integration_tests/tasks/async_queries_tests.py index 58094f78f7ef1..388185a54853d 100644 --- a/tests/integration_tests/tasks/async_queries_tests.py +++ b/tests/integration_tests/tasks/async_queries_tests.py @@ -34,7 +34,8 @@ ) from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) from tests.integration_tests.fixtures.query_context import get_query_context from tests.integration_tests.test_app import app diff --git a/tests/integration_tests/utils_tests.py b/tests/integration_tests/utils_tests.py index 7586ce2e4d4c3..fc9dba4c07214 100644 --- a/tests/integration_tests/utils_tests.py +++ b/tests/integration_tests/utils_tests.py @@ -25,7 +25,8 @@ from typing import Any, Tuple, List, Optional from unittest.mock import Mock, patch from tests.integration_tests.fixtures.birth_names_dashboard import ( - load_birth_names_dashboard_with_slices, load_birth_names_data + load_birth_names_dashboard_with_slices, + load_birth_names_data, ) import numpy as np @@ -80,7 +81,8 @@ ) from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.world_bank_dashboard import ( - load_world_bank_dashboard_with_slices, load_world_bank_data + load_world_bank_dashboard_with_slices, + load_world_bank_data, ) from .fixtures.certificates import ssl_certificate