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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 259 additions and 22 deletions

View File

@ -20,6 +20,9 @@ import json
import unittest
from unittest import mock
import pytest
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.test_app import app # isort:skip
from superset import db, security_manager
from superset.connectors.connector_registry import ConnectorRegistry
@ -184,6 +187,7 @@ class TestRequestAccess(SupersetTestCase):
)
self.assertEqual(3, len(perms))
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_override_role_permissions_drops_absent_perms(self):
override_me = security_manager.find_role("override_me")
override_me.permissions.append(
@ -272,6 +276,7 @@ class TestRequestAccess(SupersetTestCase):
gamma_user.roles.remove(security_manager.find_role("Alpha"))
session.commit()
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_clean_requests_after_db_grant(self):
session = db.session

View File

@ -33,6 +33,8 @@ from sqlalchemy.sql import func
from tests.test_app import app
from superset.connectors.sqla.models import SqlaTable
from superset.utils.core import AnnotationType, get_example_database
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.fixtures.unicode_dashboard import load_unicode_dashboard_with_slice
from superset.connectors.connector_registry import ConnectorRegistry
from superset.extensions import db, security_manager
from superset.models.annotations import AnnotationLayer
@ -709,6 +711,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
self.assertEqual(rv.status_code, 404)
@pytest.mark.usefixtures("load_unicode_dashboard_with_slice")
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_get_charts(self):
"""
Chart API: Test get charts
@ -761,7 +764,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
self.assertEqual(data["count"], 5)
@pytest.fixture()
def load_charts(self):
def load_energy_charts(self):
with app.app_context():
admin = self.get_user("admin")
energy_table = (
@ -797,7 +800,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
db.session.delete(chart5)
db.session.commit()
@pytest.mark.usefixtures("load_charts")
@pytest.mark.usefixtures("load_energy_charts")
def test_get_charts_custom_filter(self):
"""
Chart API: Test get charts custom filter
@ -830,7 +833,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
self.assertEqual(item["slice_name"], expected_response[index]["slice_name"])
self.assertEqual(item["viz_type"], expected_response[index]["viz_type"])
@pytest.mark.usefixtures("load_charts")
@pytest.mark.usefixtures("load_energy_table_with_slice", "load_energy_charts")
def test_admin_gets_filtered_energy_slices(self):
# test filtering on datasource_name
arguments = {
@ -848,7 +851,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
data = json.loads(rv.data.decode("utf-8"))
self.assertEqual(data["count"], 8)
@pytest.mark.usefixtures("load_charts")
@pytest.mark.usefixtures("load_energy_charts")
def test_user_gets_none_filtered_energy_slices(self):
# test filtering on datasource_name
arguments = {
@ -942,7 +945,9 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
if res["id"] in users_favorite_ids:
assert res["value"]
@pytest.mark.usefixtures("load_unicode_dashboard_with_slice")
@pytest.mark.usefixtures(
"load_unicode_dashboard_with_slice", "load_energy_table_with_slice"
)
def test_get_charts_page(self):
"""
Chart API: Test get charts filter

View File

@ -32,6 +32,7 @@ from superset.connectors.sqla.models import SqlaTable
from superset.models.core import Database
from superset.models.slice import Slice
from tests.base_tests import SupersetTestCase
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.fixtures.importexport import (
chart_config,
chart_metadata_config,
@ -43,10 +44,13 @@ from tests.fixtures.importexport import (
class TestExportChartsCommand(SupersetTestCase):
@patch("superset.security.manager.g")
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_export_chart_command(self, mock_g):
mock_g.user = security_manager.find_user("admin")
example_chart = db.session.query(Slice).all()[0]
example_chart = (
db.session.query(Slice).filter_by(slice_name="Energy Sankey").one_or_none()
)
command = ExportChartsCommand([example_chart.id])
contents = dict(command.run())
@ -97,11 +101,14 @@ class TestExportChartsCommand(SupersetTestCase):
next(contents)
@patch("superset.security.manager.g")
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_export_chart_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_chart = db.session.query(Slice).all()[0]
example_chart = (
db.session.query(Slice).filter_by(slice_name="Energy Sankey").one_or_none()
)
command = ExportChartsCommand([example_chart.id])
contents = dict(command.run())

View File

@ -42,7 +42,6 @@ def setup_sample_data() -> Any:
from superset import examples
examples.load_css_templates()
examples.load_energy(sample=True)
examples.load_world_bank_health_n_pop(sample=True)
examples.load_birth_names(sample=True)
@ -50,7 +49,6 @@ def setup_sample_data() -> Any:
with app.app_context():
engine = get_example_database().get_sqla_engine()
engine.execute("DROP TABLE energy_usage")
engine.execute("DROP TABLE wb_health_population")
engine.execute("DROP TABLE birth_names")

View File

@ -26,6 +26,7 @@ import logging
from typing import Dict, List
from urllib.parse import quote
import pytest
import pytz
import random
import re
@ -37,7 +38,8 @@ import sqlalchemy as sqla
from superset.models.cache import CacheKey
from superset.utils.core import get_example_database
from tests.test_app import app # isort:skip
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.test_app import app
import superset.views.utils
from superset import (
dataframe,
@ -236,6 +238,7 @@ class TestCore(SupersetTestCase):
assert_admin_view_menus_in("Alpha", self.assertNotIn)
assert_admin_view_menus_in("Gamma", self.assertNotIn)
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_save_slice(self):
self.login(username="admin")
slice_name = f"Energy Sankey"
@ -302,6 +305,7 @@ class TestCore(SupersetTestCase):
db.session.delete(slc)
db.session.commit()
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_filter_endpoint(self):
self.login(username="admin")
slice_name = "Energy Sankey"
@ -320,7 +324,7 @@ class TestCore(SupersetTestCase):
# Changing name
resp = self.get_resp(url.format(tbl_id, slice_id))
assert len(resp) > 0
assert "Carbon Dioxide" in resp
assert "energy_target0" in resp
def test_slice_data(self):
# slice data should have some required attributes
@ -333,6 +337,7 @@ class TestCore(SupersetTestCase):
assert "modified" in slc_data_attributes
assert "owners" in slc_data_attributes
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_slices(self):
# Testing by hitting the two supported end points for all slices
self.login(username="admin")
@ -409,6 +414,7 @@ class TestCore(SupersetTestCase):
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_slices_V2(self):
# Add explore-v2-beta role to admin user
# Test all slice urls as user with with explore-v2-beta role
@ -570,6 +576,7 @@ class TestCore(SupersetTestCase):
database.allow_run_async = False
db.session.commit()
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_warm_up_cache(self):
self.login()
slc = self.get_slice("Girls", db.session)

View File

@ -32,6 +32,7 @@ from superset.connectors.sqla.models import SqlaTable
from superset.models import core as models
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from .base_tests import SupersetTestCase
@ -302,6 +303,7 @@ class TestDashboard(SupersetTestCase):
if key not in ["modified", "changed_on", "changed_on_humanized"]:
self.assertEqual(slc[key], resp["slices"][index][key])
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_add_slices(self, username="admin"):
self.login(username=username)
dash = db.session.query(Dashboard).filter_by(slug="births").first()
@ -453,7 +455,7 @@ class TestDashboard(SupersetTestCase):
resp = self.get_resp("/api/v1/dashboard/")
self.assertNotIn("/superset/dashboard/empty_dashboard/", resp)
@pytest.mark.usefixtures("load_dashboard")
@pytest.mark.usefixtures("load_energy_table_with_slice", "load_dashboard")
def test_users_can_view_published_dashboard(self):
resp = self.get_resp("/api/v1/dashboard/")
self.assertNotIn(f"/superset/dashboard/{pytest.hidden_dash_slug}/", resp)

View File

@ -29,7 +29,11 @@ from superset.models.slice import Slice
def create_table_for_dashboard(
df: DataFrame, table_name: str, database: Database, dtype: Dict[str, Any]
df: DataFrame,
table_name: str,
database: Database,
dtype: Dict[str, Any],
table_description: str = "",
) -> SqlaTable:
df.to_sql(
table_name,
@ -48,6 +52,7 @@ def create_table_for_dashboard(
if not table:
table = table_source(table_name=table_name)
table.database = database
table.description = table_description
db.session.merge(table)
db.session.commit()

View File

@ -34,13 +34,13 @@ from superset.models.reports import ReportSchedule, ReportScheduleType
from superset.utils.core import get_example_database, get_main_database
from tests.base_tests import SupersetTestCase
from tests.fixtures.certificates import ssl_certificate
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.fixtures.importexport import (
database_config,
dataset_config,
database_metadata_config,
dataset_metadata_config,
)
from tests.fixtures.unicode_dashboard import load_unicode_dashboard_with_position
from tests.test_app import app
@ -800,7 +800,9 @@ class TestDatabaseApi(SupersetTestCase):
}
self.assertEqual(response, expected_response)
@pytest.mark.usefixtures("load_unicode_dashboard_with_position")
@pytest.mark.usefixtures(
"load_unicode_dashboard_with_position", "load_energy_table_with_slice"
)
def test_get_database_related_objects(self):
"""
Database API: Test get chart and dashboard count related to a database

View File

@ -39,6 +39,7 @@ from superset.utils.core import backend, get_example_database, get_main_database
from superset.utils.dict_import_export import export_to_dict
from tests.base_tests import SupersetTestCase
from tests.conftest import CTAS_SCHEMA_NAME
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.fixtures.importexport import (
database_config,
database_metadata_config,
@ -196,6 +197,7 @@ class TestDatasetApi(SupersetTestCase):
assert response["count"] == 0
assert response["result"] == []
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_get_dataset_item(self):
"""
Dataset API: Test get dataset item

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")

View File

@ -17,17 +17,19 @@
import datetime
from unittest import mock
import pytest
from superset.db_engine_specs import engines
from superset.db_engine_specs.base import BaseEngineSpec, builtin_time_grains
from superset.db_engine_specs.sqlite import SqliteEngineSpec
from superset.sql_parse import ParsedQuery
from superset.utils.core import get_example_database
from tests.db_engine_specs.base_tests import TestDbEngineSpec
from tests.test_app import app
from ..fixtures.energy_dashboard import load_energy_table_with_slice
from ..fixtures.pyodbcRow import Row
from tests.test_app import app # isort:skip
class TestDbEngineSpecs(TestDbEngineSpec):
def test_extract_limit_from_query(self, engine_spec_class=BaseEngineSpec):
@ -194,6 +196,7 @@ class TestDbEngineSpecs(TestDbEngineSpec):
)
self.assertListEqual(base_result_expected, base_result)
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_column_datatype_to_string(self):
example_db = get_example_database()
sqla_table = example_db.get_table("energy_usage")

173
tests/fixtures/energy_dashboard.py vendored Normal file
View File

@ -0,0 +1,173 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import random
import textwrap
from typing import Dict, Set
import pandas as pd
import pytest
from pandas import DataFrame
from sqlalchemy import column, Float, String
from superset import db
from superset.connectors.sqla.models import SqlaTable, SqlMetric
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
from superset.utils.core import get_example_database
from tests.dashboard_utils import create_slice, create_table_for_dashboard
from tests.test_app import app
misc_dash_slices: Set[str] = set()
@pytest.fixture()
def load_energy_table_with_slice():
table_name = "energy_usage"
df = _get_dataframe()
with app.app_context():
_create_energy_table(df, table_name)
yield
_cleanup()
def _get_dataframe():
data = _get_energy_data()
return pd.DataFrame.from_dict(data)
def _create_energy_table(df: DataFrame, table_name: str):
database = get_example_database()
table_description = "Energy consumption"
schema = {"source": String(255), "target": String(255), "value": Float()}
table = create_table_for_dashboard(
df, table_name, database, schema, table_description
)
table.fetch_metadata()
if not any(col.metric_name == "sum__value" for col in table.metrics):
col = str(column("value").compile(db.engine))
table.metrics.append(
SqlMetric(metric_name="sum__value", expression=f"SUM({col})")
)
db.session.merge(table)
db.session.commit()
table.fetch_metadata()
for slice_data in _get_energy_slices():
_create_and_commit_energy_slice(
table,
slice_data["slice_title"],
slice_data["viz_type"],
slice_data["params"],
)
def _create_and_commit_energy_slice(
table: SqlaTable, title: str, viz_type: str, param: Dict[str, str]
):
slice = create_slice(title, viz_type, table, param)
existing_slice = (
db.session.query(Slice).filter_by(slice_name=slice.slice_name).first()
)
if existing_slice:
db.session.delete(existing_slice)
db.session.add(slice)
db.session.commit()
return slice
def _cleanup() -> None:
engine = get_example_database().get_sqla_engine()
engine.execute("DROP TABLE IF EXISTS energy_usage")
for slice_data in _get_energy_slices():
slice = (
db.session.query(Slice)
.filter_by(slice_name=slice_data["slice_title"])
.first()
)
db.session.delete(slice)
metric = (
db.session.query(SqlMetric).filter_by(metric_name="sum__value").one_or_none()
)
if metric:
db.session.delete(metric)
db.session.commit()
def _get_energy_data():
data = []
for i in range(85):
data.append(
{
"source": f"energy_source{i}",
"target": f"energy_target{i}",
"value": random.uniform(0.1, 11.0),
}
)
return data
def _get_energy_slices():
return [
{
"slice_title": "Energy Sankey",
"viz_type": "sankey",
"params": {
"collapsed_fieldsets": "",
"groupby": ["source", "target"],
"metric": "sum__value",
"row_limit": "5000",
"slice_name": "Energy Sankey",
"viz_type": "sankey",
},
},
{
"slice_title": "Energy Force Layout",
"viz_type": "directed_force",
"params": {
"charge": "-500",
"collapsed_fieldsets": "",
"groupby": ["source", "target"],
"link_length": "200",
"metric": "sum__value",
"row_limit": "5000",
"slice_name": "Force",
"viz_type": "directed_force",
},
},
{
"slice_title": "Heatmap",
"viz_type": "heatmap",
"params": {
"all_columns_x": "source",
"all_columns_y": "target",
"canvas_image_rendering": "pixelated",
"collapsed_fieldsets": "",
"linear_color_scheme": "blue_white_yellow",
"metric": "sum__value",
"normalize_across": "heatmap",
"slice_name": "Heatmap",
"viz_type": "heatmap",
"xscale_interval": "1",
"yscale_interval": "1",
},
},
]

View File

@ -19,9 +19,11 @@
import json
import unittest
import pytest
from flask import g
from sqlalchemy.orm.session import make_transient
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.test_app import app
from superset.dashboards.commands.importers.v0 import decode_dashboards
from superset import db, security_manager
@ -399,6 +401,7 @@ class TestImportExport(SupersetTestCase):
meta["chartId"] = imported_dash.slices[0].id
self.assertEqual(expected_position, imported_dash.position)
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_import_dashboard_2_slices(self):
e_slc = self.create_slice("e_slc", id=10007, table_name="energy_usage")
b_slc = self.create_slice("b_slc", id=10008, table_name="birth_names")
@ -450,6 +453,7 @@ class TestImportExport(SupersetTestCase):
expected_json_metadata, json.loads(imported_dash.json_metadata)
)
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_import_override_dashboard_2_slices(self):
e_slc = self.create_slice("e_slc", id=10009, table_name="energy_usage")
b_slc = self.create_slice("b_slc", id=10010, table_name="birth_names")

View File

@ -19,6 +19,7 @@ import textwrap
import unittest
import pandas
import pytest
from sqlalchemy.engine.url import make_url
import tests.test_app
@ -28,6 +29,7 @@ from superset.models.slice import Slice
from superset.utils.core import get_example_database, QueryStatus
from .base_tests import SupersetTestCase
from .fixtures.energy_dashboard import load_energy_table_with_slice
class TestDatabaseModel(SupersetTestCase):
@ -107,6 +109,7 @@ class TestDatabaseModel(SupersetTestCase):
user_name = make_url(model.get_sqla_engine(user_name=example_user).url).username
self.assertNotEqual(example_user, user_name)
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_select_star(self):
db = get_example_database()
table_name = "energy_usage"

View File

@ -14,6 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import pytest
import tests.test_app
from superset import db
from superset.charts.schemas import ChartDataQueryContextSchema
@ -27,6 +29,7 @@ from superset.utils.core import (
TimeRangeEndpoint,
)
from tests.base_tests import SupersetTestCase
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.fixtures.query_context import get_query_context

View File

@ -45,6 +45,7 @@ from .dashboard_utils import (
create_slice,
create_dashboard,
)
from .fixtures.energy_dashboard import load_energy_table_with_slice
from .fixtures.unicode_dashboard import load_unicode_dashboard_with_slice
NEW_SECURITY_CONVERGE_VIEWS = ("CssTemplate", "SavedQuery")
@ -1128,6 +1129,7 @@ class TestRowLevelSecurity(SupersetTestCase):
session.delete(self.get_user("NoRlsRoleUser"))
session.commit()
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_rls_filter_alters_energy_query(self):
g.user = self.get_user(username="alpha")
tbl = self.get_table_by_name("energy_usage")
@ -1135,6 +1137,7 @@ class TestRowLevelSecurity(SupersetTestCase):
assert tbl.get_extra_cache_keys(self.query_obj) == [1]
assert "value > 1" in sql
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_rls_filter_doesnt_alter_energy_query(self):
g.user = self.get_user(
username="admin"