tests: added fixture with energy usage instead of example (#11308)

* Added energy usage fixture. Updated dashboard utils and unicode fixture with new method parameters.

* Add energy fixture to tests/access_tests.py

* Add energy fixture to tests/core_tests.py

* Add energy fixture to tests/dashboard_tests.py

* Add energy fixture to tests/datasets/api_tests.py

* Add energy fixture to tests/db_engine_specs/base_engine_spec_tests.py

* Add energy fixture to tests/import_export_tests.py

* Add energy fixture to tests/model_tests.py

* Add energy fixture to tests/query_context_tests.py

* Add energy fixture to tests/security_tests.py

* Add energy fixture to tests/charts/api_tests.py

* Changed formatting of slices' parameters in energy usage fixture

* Removed loading energy udage data from test conf file

* Add energy fixture to tests/databases/api_tests.py

* Fixes after review: removed isort:skip, load_charts->load_energy_charts, removed unused import.

* Added energy fixture to tests/charts/commands_tests.py and retrieving proper Slice by name

* Fixed charts/api_tests.py to use energy_usage from fixtures

* Fixed datasets/commands_tests.py to retrieve dataset by name and use energy_usage fixture

* Changed energy usage data to generated data and fixed chart tests which was checking energy usage data
This commit is contained in:
Kasia Kucharczyk
2020-12-09 21:02:29 +01:00
committed by GitHub
parent 6270fa2026
commit 4da47f1635
16 changed files with 259 additions and 22 deletions

View File

@@ -17,6 +17,7 @@
# pylint: disable=no-self-use, invalid-name, line-too-long
from operator import itemgetter
from typing import Any, List
from unittest.mock import patch
import pytest
@@ -33,6 +34,7 @@ from superset.datasets.commands.importers import v0, v1
from superset.models.core import Database
from superset.utils.core import get_example_database
from tests.base_tests import SupersetTestCase
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.fixtures.importexport import (
database_config,
database_metadata_config,
@@ -45,11 +47,14 @@ from tests.fixtures.importexport import (
class TestExportDatasetsCommand(SupersetTestCase):
@patch("superset.security.manager.g")
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_export_dataset_command(self, mock_g):
mock_g.user = security_manager.find_user("admin")
example_db = get_example_database()
example_dataset = example_db.tables[0]
example_dataset = _get_table_from_list_by_name(
"energy_usage", example_db.tables
)
command = ExportDatasetsCommand([example_dataset.id])
contents = dict(command.run())
@@ -76,7 +81,7 @@ class TestExportDatasetsCommand(SupersetTestCase):
{
"column_name": "source",
"description": None,
"expression": None,
"expression": "",
"filterable": True,
"groupby": True,
"is_active": True,
@@ -88,7 +93,7 @@ class TestExportDatasetsCommand(SupersetTestCase):
{
"column_name": "target",
"description": None,
"expression": None,
"expression": "",
"filterable": True,
"groupby": True,
"is_active": True,
@@ -100,7 +105,7 @@ class TestExportDatasetsCommand(SupersetTestCase):
{
"column_name": "value",
"description": None,
"expression": None,
"expression": "",
"filterable": True,
"groupby": True,
"is_active": True,
@@ -171,12 +176,15 @@ class TestExportDatasetsCommand(SupersetTestCase):
next(contents)
@patch("superset.security.manager.g")
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_export_dataset_command_key_order(self, mock_g):
"""Test that they keys in the YAML have the same order as export_fields"""
mock_g.user = security_manager.find_user("admin")
example_db = get_example_database()
example_dataset = example_db.tables[0]
example_dataset = _get_table_from_list_by_name(
"energy_usage", example_db.tables
)
command = ExportDatasetsCommand([example_dataset.id])
contents = dict(command.run())
@@ -454,3 +462,10 @@ class TestImportDatasetsCommand(SupersetTestCase):
db.session.delete(database.tables[0])
db.session.delete(database)
db.session.commit()
def _get_table_from_list_by_name(name: str, tables: List[Any]):
for table in tables:
if table.table_name == name:
return table
raise ValueError(f"Table {name} does not exists in database")