mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
test: birth names (#12226)
* add birth names fixture * fix birth names related tests * fix test_import_v0_dataset_cli_export columns order * fix celery tests drop table * fix mysql datetime type * fix mysql typo in charts/api_tests * refactor * add licence * fix use fixture for presto * fix presto, hive query * fix flaky metadata * fix mysql bigint type * fix run query * fix hive datatype in metadata * fix slice owner for cypress * refactor num_boys num_girls * fix is_dttm column * debug logging * fix query offset * fix presto ds type in metadata * fix presto ds type * clean up debug logging
This commit is contained in:
@@ -21,6 +21,7 @@ import json
|
||||
from io import BytesIO
|
||||
from unittest import mock
|
||||
from zipfile import is_zipfile, ZipFile
|
||||
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
|
||||
|
||||
import prison
|
||||
import pytest
|
||||
@@ -559,6 +560,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
}
|
||||
self.assertEqual(response, expected_response)
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
def test_get_table_metadata(self):
|
||||
"""
|
||||
Database API: Test get table metadata info
|
||||
@@ -622,6 +624,7 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
rv = self.client.get(uri)
|
||||
self.assertEqual(rv.status_code, 404)
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
def test_get_select_star(self):
|
||||
"""
|
||||
Database API: Test get select star
|
||||
@@ -843,7 +846,9 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = False
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"load_unicode_dashboard_with_position", "load_energy_table_with_slice"
|
||||
"load_unicode_dashboard_with_position",
|
||||
"load_energy_table_with_slice",
|
||||
"load_birth_names_dashboard_with_slices",
|
||||
)
|
||||
def test_get_database_related_objects(self):
|
||||
"""
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# pylint: disable=no-self-use, invalid-name
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -31,6 +30,8 @@ from superset.databases.commands.importers.v1 import ImportDatabasesCommand
|
||||
from superset.models.core import Database
|
||||
from superset.utils.core import backend, get_example_database
|
||||
from tests.base_tests import SupersetTestCase
|
||||
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
|
||||
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
|
||||
from tests.fixtures.importexport import (
|
||||
database_config,
|
||||
database_metadata_config,
|
||||
@@ -41,10 +42,15 @@ from tests.fixtures.importexport import (
|
||||
|
||||
class TestExportDatabasesCommand(SupersetTestCase):
|
||||
@patch("superset.security.manager.g")
|
||||
@pytest.mark.usefixtures(
|
||||
"load_birth_names_dashboard_with_slices", "load_energy_table_with_slice"
|
||||
)
|
||||
def test_export_database_command(self, mock_g):
|
||||
mock_g.user = security_manager.find_user("admin")
|
||||
|
||||
example_db = get_example_database()
|
||||
db_uuid = example_db.uuid
|
||||
|
||||
command = ExportDatabasesCommand([example_db.id])
|
||||
contents = dict(command.run())
|
||||
|
||||
@@ -68,6 +74,18 @@ class TestExportDatabasesCommand(SupersetTestCase):
|
||||
|
||||
assert core_files.issubset(set(contents.keys()))
|
||||
|
||||
if example_db.backend == "postgresql":
|
||||
ds_type = "TIMESTAMP WITHOUT TIME ZONE"
|
||||
elif example_db.backend == "hive":
|
||||
ds_type = "TIMESTAMP"
|
||||
elif example_db.backend == "presto":
|
||||
ds_type = "VARCHAR(255)"
|
||||
else:
|
||||
ds_type = "DATETIME"
|
||||
if example_db.backend == "mysql":
|
||||
big_int_type = "BIGINT(20)"
|
||||
else:
|
||||
big_int_type = "BIGINT"
|
||||
metadata = yaml.safe_load(contents["databases/examples.yaml"])
|
||||
assert metadata == (
|
||||
{
|
||||
@@ -87,153 +105,149 @@ class TestExportDatabasesCommand(SupersetTestCase):
|
||||
|
||||
metadata = yaml.safe_load(contents["datasets/examples/birth_names.yaml"])
|
||||
metadata.pop("uuid")
|
||||
assert metadata == {
|
||||
"table_name": "birth_names",
|
||||
"main_dttm_col": None,
|
||||
"description": "Adding a DESCRip",
|
||||
"default_endpoint": "",
|
||||
"offset": 66,
|
||||
"cache_timeout": 55,
|
||||
"schema": "",
|
||||
"sql": "",
|
||||
"params": None,
|
||||
"template_params": None,
|
||||
"filter_select_enabled": True,
|
||||
"fetch_values_predicate": None,
|
||||
"extra": None,
|
||||
"metrics": [
|
||||
{
|
||||
"metric_name": "ratio",
|
||||
"verbose_name": "Ratio Boys/Girls",
|
||||
"metric_type": None,
|
||||
"expression": "sum(num_boys) / sum(num_girls)",
|
||||
"description": "This represents the ratio of boys/girls",
|
||||
"d3format": ".2%",
|
||||
"extra": None,
|
||||
"warning_text": "no warning",
|
||||
},
|
||||
{
|
||||
"metric_name": "sum__num",
|
||||
"verbose_name": "Babies",
|
||||
"metric_type": None,
|
||||
"expression": "SUM(num)",
|
||||
"description": "",
|
||||
"d3format": "",
|
||||
"extra": None,
|
||||
"warning_text": "",
|
||||
},
|
||||
{
|
||||
"metric_name": "count",
|
||||
"verbose_name": "",
|
||||
"metric_type": None,
|
||||
"expression": "count(1)",
|
||||
"description": None,
|
||||
"d3format": None,
|
||||
"extra": None,
|
||||
"warning_text": None,
|
||||
},
|
||||
],
|
||||
|
||||
metadata["columns"].sort(key=lambda x: x["column_name"])
|
||||
expected_metadata = {
|
||||
"cache_timeout": None,
|
||||
"columns": [
|
||||
{
|
||||
"column_name": "num_california",
|
||||
"verbose_name": None,
|
||||
"is_dttm": False,
|
||||
"is_active": None,
|
||||
"type": "NUMBER",
|
||||
"groupby": False,
|
||||
"filterable": False,
|
||||
"expression": "CASE WHEN state = 'CA' THEN num ELSE 0 END",
|
||||
"description": None,
|
||||
"python_date_format": None,
|
||||
},
|
||||
{
|
||||
"column_name": "ds",
|
||||
"verbose_name": "",
|
||||
"is_dttm": True,
|
||||
"is_active": None,
|
||||
"type": "DATETIME",
|
||||
"groupby": True,
|
||||
"description": None,
|
||||
"expression": None,
|
||||
"filterable": True,
|
||||
"expression": "",
|
||||
"description": None,
|
||||
"groupby": True,
|
||||
"is_active": True,
|
||||
"is_dttm": True,
|
||||
"python_date_format": None,
|
||||
},
|
||||
{
|
||||
"column_name": "num_girls",
|
||||
"type": ds_type,
|
||||
"verbose_name": None,
|
||||
"is_dttm": False,
|
||||
"is_active": None,
|
||||
"type": "BIGINT(20)",
|
||||
"groupby": False,
|
||||
"filterable": False,
|
||||
"expression": "",
|
||||
"description": None,
|
||||
"python_date_format": None,
|
||||
},
|
||||
{
|
||||
"column_name": "gender",
|
||||
"verbose_name": None,
|
||||
"description": None,
|
||||
"expression": None,
|
||||
"filterable": True,
|
||||
"groupby": True,
|
||||
"is_active": True,
|
||||
"is_dttm": False,
|
||||
"is_active": None,
|
||||
"type": "VARCHAR(16)",
|
||||
"groupby": True,
|
||||
"filterable": True,
|
||||
"expression": "",
|
||||
"description": None,
|
||||
"python_date_format": None,
|
||||
},
|
||||
{
|
||||
"column_name": "state",
|
||||
"type": "STRING" if example_db.backend == "hive" else "VARCHAR(16)",
|
||||
"verbose_name": None,
|
||||
"is_dttm": None,
|
||||
"is_active": None,
|
||||
"type": "VARCHAR(10)",
|
||||
"groupby": True,
|
||||
"filterable": True,
|
||||
"expression": None,
|
||||
"description": None,
|
||||
"python_date_format": None,
|
||||
},
|
||||
{
|
||||
"column_name": "num_boys",
|
||||
"verbose_name": None,
|
||||
"is_dttm": None,
|
||||
"is_active": None,
|
||||
"type": "BIGINT(20)",
|
||||
"groupby": True,
|
||||
"filterable": True,
|
||||
"expression": None,
|
||||
"description": None,
|
||||
"python_date_format": None,
|
||||
},
|
||||
{
|
||||
"column_name": "num",
|
||||
"verbose_name": None,
|
||||
"is_dttm": None,
|
||||
"is_active": None,
|
||||
"type": "BIGINT(20)",
|
||||
"groupby": True,
|
||||
"filterable": True,
|
||||
"expression": None,
|
||||
"description": None,
|
||||
"python_date_format": None,
|
||||
},
|
||||
{
|
||||
"column_name": "name",
|
||||
"verbose_name": None,
|
||||
"is_dttm": None,
|
||||
"is_active": None,
|
||||
"type": "VARCHAR(255)",
|
||||
"groupby": True,
|
||||
"filterable": True,
|
||||
"expression": None,
|
||||
"description": None,
|
||||
"expression": None,
|
||||
"filterable": True,
|
||||
"groupby": True,
|
||||
"is_active": True,
|
||||
"is_dttm": False,
|
||||
"python_date_format": None,
|
||||
"type": "STRING"
|
||||
if example_db.backend == "hive"
|
||||
else "VARCHAR(255)",
|
||||
"verbose_name": None,
|
||||
},
|
||||
{
|
||||
"column_name": "num",
|
||||
"description": None,
|
||||
"expression": None,
|
||||
"filterable": True,
|
||||
"groupby": True,
|
||||
"is_active": True,
|
||||
"is_dttm": False,
|
||||
"python_date_format": None,
|
||||
"type": big_int_type,
|
||||
"verbose_name": None,
|
||||
},
|
||||
{
|
||||
"column_name": "num_california",
|
||||
"description": None,
|
||||
"expression": "CASE WHEN state = 'CA' THEN num ELSE 0 END",
|
||||
"filterable": True,
|
||||
"groupby": True,
|
||||
"is_active": True,
|
||||
"is_dttm": False,
|
||||
"python_date_format": None,
|
||||
"type": None,
|
||||
"verbose_name": None,
|
||||
},
|
||||
{
|
||||
"column_name": "state",
|
||||
"description": None,
|
||||
"expression": None,
|
||||
"filterable": True,
|
||||
"groupby": True,
|
||||
"is_active": True,
|
||||
"is_dttm": False,
|
||||
"python_date_format": None,
|
||||
"type": "STRING" if example_db.backend == "hive" else "VARCHAR(10)",
|
||||
"verbose_name": None,
|
||||
},
|
||||
{
|
||||
"column_name": "num_boys",
|
||||
"description": None,
|
||||
"expression": None,
|
||||
"filterable": True,
|
||||
"groupby": True,
|
||||
"is_active": True,
|
||||
"is_dttm": False,
|
||||
"python_date_format": None,
|
||||
"type": big_int_type,
|
||||
"verbose_name": None,
|
||||
},
|
||||
{
|
||||
"column_name": "num_girls",
|
||||
"description": None,
|
||||
"expression": None,
|
||||
"filterable": True,
|
||||
"groupby": True,
|
||||
"is_active": True,
|
||||
"is_dttm": False,
|
||||
"python_date_format": None,
|
||||
"type": big_int_type,
|
||||
"verbose_name": None,
|
||||
},
|
||||
],
|
||||
"database_uuid": str(db_uuid),
|
||||
"default_endpoint": None,
|
||||
"description": "",
|
||||
"extra": None,
|
||||
"fetch_values_predicate": None,
|
||||
"filter_select_enabled": True,
|
||||
"main_dttm_col": "ds",
|
||||
"metrics": [
|
||||
{
|
||||
"d3format": None,
|
||||
"description": None,
|
||||
"expression": "COUNT(*)",
|
||||
"extra": None,
|
||||
"metric_name": "count",
|
||||
"metric_type": "count",
|
||||
"verbose_name": "COUNT(*)",
|
||||
"warning_text": None,
|
||||
},
|
||||
{
|
||||
"d3format": None,
|
||||
"description": None,
|
||||
"expression": "SUM(num)",
|
||||
"extra": None,
|
||||
"metric_name": "sum__num",
|
||||
"metric_type": None,
|
||||
"verbose_name": None,
|
||||
"warning_text": None,
|
||||
},
|
||||
],
|
||||
"offset": 0,
|
||||
"params": None,
|
||||
"schema": None,
|
||||
"sql": None,
|
||||
"table_name": "birth_names",
|
||||
"template_params": None,
|
||||
"version": "1.0.0",
|
||||
"database_uuid": str(example_db.uuid),
|
||||
}
|
||||
expected_metadata["columns"].sort(key=lambda x: x["column_name"])
|
||||
assert metadata == expected_metadata
|
||||
|
||||
@patch("superset.security.manager.g")
|
||||
def test_export_database_command_no_access(self, mock_g):
|
||||
|
||||
Reference in New Issue
Block a user