Skip to content

Commit

Permalink
test: autouse app_context in unit tests (apache#20911)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7e836e9)
  • Loading branch information
ktmud authored and jinghua-qa committed Aug 5, 2022
1 parent 601afe4 commit 5ca2ee4
Show file tree
Hide file tree
Showing 37 changed files with 142 additions and 212 deletions.
55 changes: 26 additions & 29 deletions tests/unit_tests/advanced_data_type/types_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
# isort:skip_file
"""Unit tests for Superset"""

from ipaddress import ip_address
import sqlalchemy
from flask.ctx import AppContext
from sqlalchemy import Column, Integer
from tests.integration_tests.base_tests import SupersetTestCase
from superset.advanced_data_type.types import (
AdvancedDataTypeRequest,
AdvancedDataTypeResponse,
Expand All @@ -36,7 +33,7 @@
# tox -e py38 -- tests/unit_tests/advanced_data_type/types_tests.py


def test_ip_func_valid_ip(app_context: None):
def test_ip_func_valid_ip():
"""Test to see if the cidr_func behaves as expected when a valid IP is passed in"""
cidr_request: AdvancedDataTypeRequest = {
"advanced_data_type": "cidr",
Expand All @@ -59,7 +56,7 @@ def test_ip_func_valid_ip(app_context: None):
assert internet_address.translate_type(cidr_request) == cidr_response


def test_cidr_func_invalid_ip(app_context: None):
def test_cidr_func_invalid_ip():
"""Test to see if the cidr_func behaves as expected when an invalid IP is passed in"""
cidr_request: AdvancedDataTypeRequest = {
"advanced_data_type": "cidr",
Expand All @@ -82,7 +79,7 @@ def test_cidr_func_invalid_ip(app_context: None):
assert internet_address.translate_type(cidr_request) == cidr_response


def test_port_translation_func_valid_port_number(app_context: None):
def test_port_translation_func_valid_port_number():
"""Test to see if the port_translation_func behaves as expected when a valid port number
is passed in"""
port_request: AdvancedDataTypeRequest = {
Expand All @@ -106,7 +103,7 @@ def test_port_translation_func_valid_port_number(app_context: None):
assert port.translate_type(port_request) == port_response


def test_port_translation_func_valid_port_name(app_context: None):
def test_port_translation_func_valid_port_name():
"""Test to see if the port_translation_func behaves as expected when a valid port name
is passed in"""
port_request: AdvancedDataTypeRequest = {
Expand All @@ -130,7 +127,7 @@ def test_port_translation_func_valid_port_name(app_context: None):
assert port.translate_type(port_request) == port_response


def test_port_translation_func_invalid_port_name(app_context: None):
def test_port_translation_func_invalid_port_name():
"""Test to see if the port_translation_func behaves as expected when an invalid port name
is passed in"""
port_request: AdvancedDataTypeRequest = {
Expand All @@ -154,7 +151,7 @@ def test_port_translation_func_invalid_port_name(app_context: None):
assert port.translate_type(port_request) == port_response


def test_port_translation_func_invalid_port_number(app_context: None):
def test_port_translation_func_invalid_port_number():
"""Test to see if the port_translation_func behaves as expected when an invalid port
number is passed in"""
port_request: AdvancedDataTypeRequest = {
Expand All @@ -178,7 +175,7 @@ def test_port_translation_func_invalid_port_number(app_context: None):
assert port.translate_type(port_request) == port_response


def test_cidr_translate_filter_func_equals(app_context: None):
def test_cidr_translate_filter_func_equals():
"""Test to see if the cidr_translate_filter_func behaves as expected when the EQUALS
operator is used"""

Expand All @@ -193,7 +190,7 @@ def test_cidr_translate_filter_func_equals(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_not_equals(app_context: None):
def test_cidr_translate_filter_func_not_equals():
"""Test to see if the cidr_translate_filter_func behaves as expected when the NOT_EQUALS
operator is used"""

Expand All @@ -208,7 +205,7 @@ def test_cidr_translate_filter_func_not_equals(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_greater_than_or_equals(app_context: None):
def test_cidr_translate_filter_func_greater_than_or_equals():
"""Test to see if the cidr_translate_filter_func behaves as expected when the
GREATER_THAN_OR_EQUALS operator is used"""

Expand All @@ -225,7 +222,7 @@ def test_cidr_translate_filter_func_greater_than_or_equals(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_greater_than(app_context: None):
def test_cidr_translate_filter_func_greater_than():
"""Test to see if the cidr_translate_filter_func behaves as expected when the
GREATER_THAN operator is used"""

Expand All @@ -242,7 +239,7 @@ def test_cidr_translate_filter_func_greater_than(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_less_than(app_context: None):
def test_cidr_translate_filter_func_less_than():
"""Test to see if the cidr_translate_filter_func behaves as expected when the LESS_THAN
operator is used"""

Expand All @@ -259,7 +256,7 @@ def test_cidr_translate_filter_func_less_than(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_less_than_or_equals(app_context: None):
def test_cidr_translate_filter_func_less_than_or_equals():
"""Test to see if the cidr_translate_filter_func behaves as expected when the
LESS_THAN_OR_EQUALS operator is used"""

Expand All @@ -276,7 +273,7 @@ def test_cidr_translate_filter_func_less_than_or_equals(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_in_single(app_context: None):
def test_cidr_translate_filter_func_in_single():
"""Test to see if the cidr_translate_filter_func behaves as expected when the IN operator
is used with a single IP"""

Expand All @@ -293,7 +290,7 @@ def test_cidr_translate_filter_func_in_single(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_in_double(app_context: None):
def test_cidr_translate_filter_func_in_double():
"""Test to see if the cidr_translate_filter_func behaves as expected when the IN operator
is used with two IP's"""

Expand All @@ -312,7 +309,7 @@ def test_cidr_translate_filter_func_in_double(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_not_in_single(app_context: None):
def test_cidr_translate_filter_func_not_in_single():
"""Test to see if the cidr_translate_filter_func behaves as expected when the NOT_IN
operator is used with a single IP"""

Expand All @@ -329,7 +326,7 @@ def test_cidr_translate_filter_func_not_in_single(app_context: None):
).compare(cidr_translate_filter_response)


def test_cidr_translate_filter_func_not_in_double(app_context: None):
def test_cidr_translate_filter_func_not_in_double():
"""Test to see if the cidr_translate_filter_func behaves as expected when the NOT_IN
operator is used with two IP's"""

Expand All @@ -348,7 +345,7 @@ def test_cidr_translate_filter_func_not_in_double(app_context: None):
).compare(cidr_translate_filter_response)


def test_port_translate_filter_func_equals(app_context: None):
def test_port_translate_filter_func_equals():
"""Test to see if the port_translate_filter_func behaves as expected when the EQUALS
operator is used"""

Expand All @@ -365,7 +362,7 @@ def test_port_translate_filter_func_equals(app_context: None):
)


def test_port_translate_filter_func_not_equals(app_context: None):
def test_port_translate_filter_func_not_equals():
"""Test to see if the port_translate_filter_func behaves as expected when the NOT_EQUALS
operator is used"""

Expand All @@ -382,7 +379,7 @@ def test_port_translate_filter_func_not_equals(app_context: None):
)


def test_port_translate_filter_func_greater_than_or_equals(app_context: None):
def test_port_translate_filter_func_greater_than_or_equals():
"""Test to see if the port_translate_filter_func behaves as expected when the
GREATER_THAN_OR_EQUALS operator is used"""

Expand All @@ -399,7 +396,7 @@ def test_port_translate_filter_func_greater_than_or_equals(app_context: None):
)


def test_port_translate_filter_func_greater_than(app_context: None):
def test_port_translate_filter_func_greater_than():
"""Test to see if the port_translate_filter_func behaves as expected when the
GREATER_THAN operator is used"""

Expand All @@ -416,7 +413,7 @@ def test_port_translate_filter_func_greater_than(app_context: None):
)


def test_port_translate_filter_func_less_than_or_equals(app_context: None):
def test_port_translate_filter_func_less_than_or_equals():
"""Test to see if the port_translate_filter_func behaves as expected when the
LESS_THAN_OR_EQUALS operator is used"""

Expand All @@ -433,7 +430,7 @@ def test_port_translate_filter_func_less_than_or_equals(app_context: None):
)


def test_port_translate_filter_func_less_than(app_context: None):
def test_port_translate_filter_func_less_than():
"""Test to see if the port_translate_filter_func behaves as expected when the LESS_THAN
operator is used"""

Expand All @@ -450,7 +447,7 @@ def test_port_translate_filter_func_less_than(app_context: None):
)


def test_port_translate_filter_func_in_single(app_context: None):
def test_port_translate_filter_func_in_single():
"""Test to see if the port_translate_filter_func behaves as expected when the IN operator
is used with a single port"""

Expand All @@ -467,7 +464,7 @@ def test_port_translate_filter_func_in_single(app_context: None):
)


def test_port_translate_filter_func_in_double(app_context: None):
def test_port_translate_filter_func_in_double():
"""Test to see if the port_translate_filter_func behaves as expected when the IN operator
is used with two ports"""

Expand All @@ -484,7 +481,7 @@ def test_port_translate_filter_func_in_double(app_context: None):
)


def test_port_translate_filter_func_not_in_single(app_context: None):
def test_port_translate_filter_func_not_in_single():
"""Test to see if the port_translate_filter_func behaves as expected when the NOT_IN
operator is used with a single port"""

Expand All @@ -501,7 +498,7 @@ def test_port_translate_filter_func_not_in_single(app_context: None):
)


def test_port_translate_filter_func_not_in_double(app_context: None):
def test_port_translate_filter_func_not_in_double():
"""Test to see if the port_translate_filter_func behaves as expected when the NOT_IN
operator is used with two ports"""

Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/charts/commands/importers/v1/import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sqlalchemy.orm.session import Session


def test_import_chart(app_context: None, session: Session) -> None:
def test_import_chart(session: Session) -> None:
"""
Test importing a chart.
"""
Expand All @@ -45,7 +45,7 @@ def test_import_chart(app_context: None, session: Session) -> None:
assert chart.external_url is None


def test_import_chart_managed_externally(app_context: None, session: Session) -> None:
def test_import_chart_managed_externally(session: Session) -> None:
"""
Test importing a chart that is managed externally.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/columns/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from sqlalchemy.orm.session import Session


def test_column_model(app_context: None, session: Session) -> None:
def test_column_model(session: Session) -> None:
"""
Test basic attributes of a ``Column``.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/commands/export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pytest_mock import MockFixture


def test_export_assets_command(mocker: MockFixture, app_context: None) -> None:
def test_export_assets_command(mocker: MockFixture) -> None:
"""
Test that all assets are exported correctly.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def apply_dttm_defaults(table: "SqlaTable", dttm_defaults: Dict[str, Any]) -> No


@pytest.fixture
def test_table(app_context: None, session: Session) -> "SqlaTable":
def test_table(session: Session) -> "SqlaTable":
"""
Fixture that generates an in-memory table.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def client(app: SupersetApp) -> Any:
yield client


@pytest.fixture
@pytest.fixture(autouse=True)
def app_context(app: SupersetApp) -> Iterator[None]:
"""
A fixture that yields and application context.
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/dao/queries_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sqlalchemy.orm.session import Session


def test_query_dao_save_metadata(app_context: None, session: Session) -> None:
def test_query_dao_save_metadata(session: Session) -> None:
from superset.models.core import Database
from superset.models.sql_lab import Query

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sqlalchemy.orm.session import Session


def test_import_dashboard(app_context: None, session: Session) -> None:
def test_import_dashboard(session: Session) -> None:
"""
Test importing a dashboard.
"""
Expand All @@ -43,9 +43,7 @@ def test_import_dashboard(app_context: None, session: Session) -> None:
assert dashboard.external_url is None


def test_import_dashboard_managed_externally(
app_context: None, session: Session
) -> None:
def test_import_dashboard_managed_externally(session: Session) -> None:
"""
Test importing a dashboard that is managed externally.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_update_id_refs_immune_missing( # pylint: disable=invalid-name
}


def test_update_native_filter_config_scope_excluded(app_context: None):
def test_update_native_filter_config_scope_excluded():
from superset.dashboards.commands.importers.v1.utils import update_id_refs

config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sqlalchemy.orm.session import Session


def test_import_database(app_context: None, session: Session) -> None:
def test_import_database(session: Session) -> None:
"""
Test importing a database.
"""
Expand All @@ -48,9 +48,7 @@ def test_import_database(app_context: None, session: Session) -> None:
assert database.external_url is None


def test_import_database_managed_externally(
app_context: None, session: Session
) -> None:
def test_import_database_managed_externally(session: Session) -> None:
"""
Test importing a database that is managed externally.
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/databases/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from superset.databases.utils import make_url_safe


def test_make_url_safe_string(app_context: None, session: Session) -> None:
def test_make_url_safe_string(session: Session) -> None:
"""
Test converting a string to a safe uri
"""
Expand All @@ -31,7 +31,7 @@ def test_make_url_safe_string(app_context: None, session: Session) -> None:
assert uri_safe == make_url(uri_string)


def test_make_url_safe_url(app_context: None, session: Session) -> None:
def test_make_url_safe_url(session: Session) -> None:
"""
Test converting a url to a safe uri
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/dataframe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from superset.superset_typing import DbapiDescription


def test_df_to_records(app_context: None) -> None:
def test_df_to_records() -> None:
from superset.db_engine_specs import BaseEngineSpec
from superset.result_set import SupersetResultSet

Expand All @@ -41,7 +41,7 @@ def test_df_to_records(app_context: None) -> None:
]


def test_js_max_int(app_context: None) -> None:
def test_js_max_int() -> None:
from superset.db_engine_specs import BaseEngineSpec
from superset.result_set import SupersetResultSet

Expand Down

0 comments on commit 5ca2ee4

Please sign in to comment.