Skip to content

Commit

Permalink
refactor(tests): decouple unittests from integration tests (apache#15473
Browse files Browse the repository at this point in the history
)

* refactor move all tests to be under integration_tests package

* refactor decouple unittests from integration tests - commands

* add unit_tests package

* fix celery_tests.py

* fix wrong FIXTURES_DIR value
  • Loading branch information
ofekisr authored and cccs-RyanS committed Dec 17, 2021
1 parent f130bb0 commit 61e8f18
Show file tree
Hide file tree
Showing 172 changed files with 456 additions and 262 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bashlib.sh
Expand Up @@ -192,7 +192,7 @@ cypress-run-all() {
say "::endgroup::"

# Rerun SQL Lab tests with backend persist enabled
export SUPERSET_CONFIG=tests.superset_test_config_sqllab_backend_persist
export SUPERSET_CONFIG=tests.integration_tests.superset_test_config_sqllab_backend_persist

# Restart Flask with new configs
kill $flaskProcessId
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/superset-e2e.yml
Expand Up @@ -25,7 +25,7 @@ jobs:
env:
FLASK_ENV: development
ENABLE_REACT_CRUD_VIEWS: true
SUPERSET_CONFIG: tests.superset_test_config
SUPERSET_CONFIG: tests.integration_tests.superset_test_config
SUPERSET__SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://superset:superset@127.0.0.1:15432/superset
PYTHONPATH: ${{ github.workspace }}
REDIS_PORT: 16379
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/superset-python-presto-hive.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: [3.8]
env:
PYTHONPATH: ${{ github.workspace }}
SUPERSET_CONFIG: tests.superset_test_config
SUPERSET_CONFIG: tests.integration_tests.superset_test_config
REDIS_PORT: 16379
SUPERSET__SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://superset:superset@127.0.0.1:15432/superset
SUPERSET__SQLALCHEMY_EXAMPLES_URI: presto://localhost:15433/memory/default
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
python-version: [3.8]
env:
PYTHONPATH: ${{ github.workspace }}
SUPERSET_CONFIG: tests.superset_test_config
SUPERSET_CONFIG: tests.integration_tests.superset_test_config
REDIS_PORT: 16379
SUPERSET__SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://superset:superset@127.0.0.1:15432/superset
SUPERSET__SQLALCHEMY_EXAMPLES_URI: hive://localhost:10000/default
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/superset-python-unittest.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: [3.7]
env:
PYTHONPATH: ${{ github.workspace }}
SUPERSET_CONFIG: tests.superset_test_config
SUPERSET_CONFIG: tests.integration_tests.superset_test_config
REDIS_PORT: 16379
SUPERSET__SQLALCHEMY_DATABASE_URI: |
mysql+mysqldb://superset:superset@127.0.0.1:13306/superset?charset=utf8mb4&binary_prefix=true
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
python-version: [3.7, 3.8]
env:
PYTHONPATH: ${{ github.workspace }}
SUPERSET_CONFIG: tests.superset_test_config
SUPERSET_CONFIG: tests.integration_tests.superset_test_config
REDIS_PORT: 16379
SUPERSET__SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://superset:superset@127.0.0.1:15432/superset
services:
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
python-version: [3.7]
env:
PYTHONPATH: ${{ github.workspace }}
SUPERSET_CONFIG: tests.superset_test_config
SUPERSET_CONFIG: tests.integration_tests.superset_test_config
REDIS_PORT: 16379
SUPERSET__SQLALCHEMY_DATABASE_URI: |
sqlite:///${{ github.workspace }}/.temp/unittest.db
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -771,7 +771,7 @@ npm run test -- path/to/file.js
We use [Cypress](https://www.cypress.io/) for integration tests. Tests can be run by `tox -e cypress`. To open Cypress and explore tests first setup and run test server:
```bash
export SUPERSET_CONFIG=tests.superset_test_config
export SUPERSET_CONFIG=tests.integration_tests.superset_test_config
export SUPERSET_TESTENV=true
export ENABLE_REACT_CRUD_VIEWS=true
export CYPRESS_BASE_URL="http://localhost:8081"
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-bootstrap.sh
Expand Up @@ -21,7 +21,7 @@ set -eo pipefail
REQUIREMENTS_LOCAL="/app/docker/requirements-local.txt"
# If Cypress run – overwrite the password for admin and export env variables
if [ "$CYPRESS_CONFIG" == "true" ]; then
export SUPERSET_CONFIG=tests.superset_test_config
export SUPERSET_CONFIG=tests.integration_tests.superset_test_config
export SUPERSET_TESTENV=true
export ENABLE_REACT_CRUD_VIEWS=true
export SUPERSET__SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://superset:superset@db:5432/superset
Expand Down
2 changes: 1 addition & 1 deletion scripts/python_tests.sh
Expand Up @@ -18,7 +18,7 @@
#
set -e

export SUPERSET_CONFIG=${SUPERSET_CONFIG:-tests.superset_test_config}
export SUPERSET_CONFIG=${SUPERSET_CONFIG:-tests.integration_tests.superset_test_config}
export SUPERSET_TESTENV=true
echo "Superset config module: $SUPERSET_CONFIG"

Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/run.sh
Expand Up @@ -62,7 +62,7 @@ DB_NAME="test"
DB_USER="superset"
DB_PASSWORD="superset"
export SUPERSET__SQLALCHEMY_DATABASE_URI=${SUPERSET__SQLALCHEMY_DATABASE_URI:-postgresql+psycopg2://"${DB_USER}":"${DB_PASSWORD}"@localhost/"${DB_NAME}"}
export SUPERSET_CONFIG=${SUPERSET_CONFIG:-tests.superset_test_config}
export SUPERSET_CONFIG=${SUPERSET_CONFIG:-tests.integration_tests.superset_test_config}
RUN_INIT=1
RUN_RESET_DB=1
RUN_TESTS=1
Expand Down
File renamed without changes.
14 changes: 10 additions & 4 deletions tests/access_tests.py → tests/integration_tests/access_tests.py
Expand Up @@ -19,13 +19,19 @@
import json
import unittest
from unittest import mock
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
from tests.integration_tests.fixtures.birth_names_dashboard import (
load_birth_names_dashboard_with_slices,
)

import pytest
from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices
from tests.integration_tests.fixtures.world_bank_dashboard import (
load_world_bank_dashboard_with_slices,
)

from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.test_app import app # isort:skip
from tests.integration_tests.fixtures.energy_dashboard import (
load_energy_table_with_slice,
)
from tests.integration_tests.test_app import app # isort:skip
from superset import db, security_manager
from superset.connectors.connector_registry import ConnectorRegistry
from superset.connectors.druid.models import DruidDatasource
Expand Down
Expand Up @@ -45,9 +45,9 @@
AlertModelView,
AlertObservationModelView,
)
from tests.base_tests import SupersetTestCase
from tests.test_app import app
from tests.utils import read_fixture
from tests.integration_tests.base_tests import SupersetTestCase
from tests.integration_tests.test_app import app
from tests.integration_tests.utils import read_fixture

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Expand Down
File renamed without changes.
Expand Up @@ -22,12 +22,12 @@
import prison
from sqlalchemy.sql import func

import tests.test_app
import tests.integration_tests.test_app
from superset import db
from superset.models.annotations import Annotation, AnnotationLayer

from tests.base_tests import SupersetTestCase
from tests.annotation_layers.fixtures import (
from tests.integration_tests.base_tests import SupersetTestCase
from tests.integration_tests.annotation_layers.fixtures import (
create_annotation_layers,
get_end_dttm,
get_start_dttm,
Expand Down
Expand Up @@ -22,7 +22,7 @@
from superset import db
from superset.models.annotations import Annotation, AnnotationLayer

from tests.test_app import app
from tests.integration_tests.test_app import app


ANNOTATION_LAYERS_COUNT = 10
Expand Down
File renamed without changes.
Expand Up @@ -19,8 +19,8 @@
from unittest import mock

from superset.extensions import async_query_manager
from tests.base_tests import SupersetTestCase
from tests.test_app import app
from tests.integration_tests.base_tests import SupersetTestCase
from tests.integration_tests.test_app import app


class TestAsyncEventApi(SupersetTestCase):
Expand Down
Expand Up @@ -16,13 +16,15 @@
# under the License.
# isort:skip_file
import json
from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices
from tests.integration_tests.fixtures.world_bank_dashboard import (
load_world_bank_dashboard_with_slices,
)

import pytest
from flask_appbuilder.models.sqla.interface import SQLAInterface
import prison

import tests.test_app
import tests.integration_tests.test_app
from superset import db, security_manager
from superset.extensions import appbuilder
from superset.models.dashboard import Dashboard
Expand Down
Expand Up @@ -32,7 +32,7 @@
from sqlalchemy.orm import Session
from sqlalchemy.sql import func

from tests.test_app import app
from tests.integration_tests.test_app import app
from superset.sql_parse import CtasMethod
from superset import db, security_manager
from superset.connectors.base.models import BaseDatasource
Expand Down
Expand Up @@ -22,7 +22,9 @@
from superset import app, db
from superset.extensions import cache_manager
from superset.utils.core import QueryStatus
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
from tests.integration_tests.fixtures.birth_names_dashboard import (
load_birth_names_dashboard_with_slices,
)

from .base_tests import SupersetTestCase

Expand Down
File renamed without changes.
Expand Up @@ -18,11 +18,11 @@
"""Unit tests for Superset"""
from typing import Dict, Any

from tests.test_app import app # noqa
from tests.integration_tests.test_app import app # noqa

from superset.extensions import cache_manager, db
from superset.models.cache import CacheKey
from tests.base_tests import (
from tests.integration_tests.base_tests import (
SupersetTestCase,
post_assert_metric,
test_client,
Expand Down
Expand Up @@ -23,16 +23,18 @@
import time
import unittest.mock as mock
from typing import Optional
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
from tests.integration_tests.fixtures.birth_names_dashboard import (
load_birth_names_dashboard_with_slices,
)

import pytest

import flask
from flask import current_app

from tests.base_tests import login
from tests.conftest import CTAS_SCHEMA_NAME
from tests.test_app import app
from tests.integration_tests.base_tests import login
from tests.integration_tests.conftest import CTAS_SCHEMA_NAME
from tests.integration_tests.test_app import app
from superset import db, sql_lab
from superset.result_set import SupersetResultSet
from superset.db_engine_specs.base import BaseEngineSpec
Expand Down
File renamed without changes.
Expand Up @@ -23,10 +23,12 @@
from unittest import mock
from zipfile import is_zipfile, ZipFile

from tests.conftest import with_feature_flags
from tests.integration_tests.conftest import with_feature_flags
from superset.models.sql_lab import Query
from tests.insert_chart_mixin import InsertChartMixin
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
from tests.integration_tests.insert_chart_mixin import InsertChartMixin
from tests.integration_tests.fixtures.birth_names_dashboard import (
load_birth_names_dashboard_with_slices,
)

import humanize
import prison
Expand All @@ -35,8 +37,10 @@
from sqlalchemy import and_, or_
from sqlalchemy.sql import func

from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices
from tests.test_app import app
from tests.integration_tests.fixtures.world_bank_dashboard import (
load_world_bank_dashboard_with_slices,
)
from tests.integration_tests.test_app import app
from superset.charts.commands.data import ChartDataCommand
from superset.connectors.sqla.models import SqlaTable, TableColumn
from superset.errors import SupersetErrorType
Expand All @@ -55,21 +59,32 @@
)


from tests.base_api_tests import ApiOwnersTestCaseMixin
from tests.base_tests import SupersetTestCase, post_assert_metric, test_client
from tests.integration_tests.base_api_tests import ApiOwnersTestCaseMixin
from tests.integration_tests.base_tests import (
SupersetTestCase,
post_assert_metric,
test_client,
)

from tests.fixtures.importexport import (
from tests.integration_tests.fixtures.importexport import (
chart_config,
chart_metadata_config,
database_config,
dataset_config,
dataset_metadata_config,
)
from tests.fixtures.energy_dashboard import load_energy_table_with_slice
from tests.fixtures.query_context import get_query_context, ANNOTATION_LAYERS
from tests.fixtures.unicode_dashboard import load_unicode_dashboard_with_slice
from tests.annotation_layers.fixtures import create_annotation_layers
from tests.utils.get_dashboards import get_dashboards_ids
from tests.integration_tests.fixtures.energy_dashboard import (
load_energy_table_with_slice,
)
from tests.integration_tests.fixtures.query_context import (
get_query_context,
ANNOTATION_LAYERS,
)
from tests.integration_tests.fixtures.unicode_dashboard import (
load_unicode_dashboard_with_slice,
)
from tests.integration_tests.annotation_layers.fixtures import create_annotation_layers
from tests.integration_tests.utils.get_dashboards import get_dashboards_ids

CHART_DATA_URI = "api/v1/chart/data"
CHARTS_FIXTURE_COUNT = 10
Expand Down
Expand Up @@ -31,9 +31,11 @@
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 (
from tests.integration_tests.base_tests import SupersetTestCase
from tests.integration_tests.fixtures.energy_dashboard import (
load_energy_table_with_slice,
)
from tests.integration_tests.fixtures.importexport import (
chart_config,
chart_metadata_config,
database_config,
Expand Down
Expand Up @@ -19,11 +19,11 @@
from typing import Any, Dict, Tuple

from marshmallow import ValidationError
from tests.test_app import app
from tests.integration_tests.test_app import app
from superset.charts.schemas import ChartDataQueryContextSchema
from superset.common.query_context import QueryContext
from tests.base_tests import SupersetTestCase
from tests.fixtures.query_context import get_query_context
from tests.integration_tests.base_tests import SupersetTestCase
from tests.integration_tests.fixtures.query_context import get_query_context


class TestSchema(SupersetTestCase):
Expand Down
4 changes: 3 additions & 1 deletion tests/cli_tests.py → tests/integration_tests/cli_tests.py
Expand Up @@ -27,7 +27,9 @@

import superset.cli
from superset import app
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
from tests.integration_tests.fixtures.birth_names_dashboard import (
load_birth_names_dashboard_with_slices,
)


@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
Expand Down
Expand Up @@ -18,7 +18,7 @@

from superset.commands.exceptions import CommandInvalidError
from superset.commands.importers.v1.utils import is_valid_config
from tests.base_tests import SupersetTestCase
from tests.integration_tests.base_tests import SupersetTestCase


class TestCommandsExceptions(SupersetTestCase):
Expand Down
Expand Up @@ -19,8 +19,8 @@
import unittest
from typing import Any, Dict

from tests.base_tests import SupersetTestCase
from tests.test_app import app
from tests.integration_tests.base_tests import SupersetTestCase
from tests.integration_tests.test_app import app

from superset import db
from superset.connectors.sqla.models import SqlaTable
Expand Down

0 comments on commit 61e8f18

Please sign in to comment.