Skip to content

Use python imports to identify fixtures (part 5/6) #5705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Changed
* Move from udatetime to ciso8601 for date functionality ahead of supporting python3.9 #5692
Contributed by Amanda McGuinness (@amanda11 intive)

* Refactor tests to use python imports to identify test fixtures. #5699 #5702 #5703 #5704
* Refactor tests to use python imports to identify test fixtures. #5699 #5702 #5703 #5704 #5705
Contributed by @cognifloyd

Removed
Expand Down
Empty file added contrib/packs/tests/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions contrib/packs/tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2022 The StackStorm Authors.
#
# Licensed 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 os

FIXTURES_DIR = os.path.dirname(os.path.abspath(__file__))
7 changes: 4 additions & 3 deletions contrib/packs/tests/test_action_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

from pack_mgmt.download import DownloadGitRepoAction

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# this import allows pants to detect that the fixtures are used in this file
from .fixtures import FIXTURES_DIR

PACK_INDEX = {
"test": {
Expand Down Expand Up @@ -639,7 +640,7 @@ def test_run_pack_dowload_local_git_repo_detached_head_state(self):
side_effect=TypeError("detached head")
)

pack_path = os.path.join(BASE_DIR, "fixtures/stackstorm-test")
pack_path = os.path.join(FIXTURES_DIR, "stackstorm-test")

result = action.run(
packs=["file://%s" % (pack_path)], abs_repo_base=self.repo_base
Expand All @@ -665,7 +666,7 @@ def test_run_pack_download_local_directory(self):
)

# 2. Local pack which is not a git repository
pack_path = os.path.join(BASE_DIR, "fixtures/stackstorm-test4")
pack_path = os.path.join(FIXTURES_DIR, "stackstorm-test4")

result = action.run(
packs=["file://%s" % (pack_path)], abs_repo_base=self.repo_base
Expand Down
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions st2common/tests/fixtures/local_runner/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2022 The StackStorm Authors.
#
# Licensed 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 os

FIXTURE_DIR = os.path.abspath(os.path.dirname(__file__))
1 change: 1 addition & 0 deletions st2common/tests/integration/log_unicode_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from st2common import log as logging
from st2common.service_setup import setup as common_setup

# Do not use helpers from st2tests to calculate this (avoid extra imports).
FIXTURES_DIR = os.path.join(ST2TESTS_PATH, "st2tests/fixtures")
ST2_CONFIG_DEBUG_LL_PATH = os.path.join(
FIXTURES_DIR, "conf/st2.tests.api.debug_log_level.conf"
Expand Down
3 changes: 1 addition & 2 deletions st2common/tests/integration/test_rabbitmq_ssl_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@

from st2common.transport import utils as transport_utils

from st2tests.fixturesloader import get_fixtures_base_path
from st2tests.fixtures.ssl_certs.fixture import FIXTURE_PATH as CERTS_FIXTURES_PATH

__all__ = ["RabbitMQTLSListenerTestCase"]

CERTS_FIXTURES_PATH = os.path.join(get_fixtures_base_path(), "ssl_certs/")
ST2_CI = os.environ.get("ST2_CI", "false").lower() == "true"

NON_SSL_LISTENER_PORT = 5672
Expand Down
7 changes: 4 additions & 3 deletions st2common/tests/integration/test_register_content_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# import this so that pants can infer dependencies for the glob below
from st2tests.fixtures.packs.dummy_pack_1.fixture import PACK_PATH as DUMMY_PACK_1_PATH
from st2tests.fixtures.packs.dummy_pack_4.fixture import PACK_PATH as DUMMY_PACK_4_PATH
from st2tests.fixtures.packs.runners.fixture import FIXTURE_PATH as RUNNER_DIRS
from st2tests.fixtures.packs_1.dummy_pack_4.fixture import PACK_PATH as EMPTY_PACK_PATH


Expand All @@ -49,7 +50,7 @@ def setUp(self):

def test_register_from_pack_success(self):
pack_dir = DUMMY_PACK_1_PATH
runner_dirs = os.path.join(get_fixtures_packs_base_path(), "runners")
runner_dirs = RUNNER_DIRS

opts = [
"--register-pack=%s" % (pack_dir),
Expand All @@ -63,7 +64,7 @@ def test_register_from_pack_success(self):
def test_register_from_pack_fail_on_failure_pack_dir_doesnt_exist(self):
# No fail on failure flag, should succeed
pack_dir = "doesntexistblah"
runner_dirs = os.path.join(get_fixtures_packs_base_path(), "runners")
runner_dirs = RUNNER_DIRS

opts = [
"--register-pack=%s" % (pack_dir),
Expand All @@ -88,7 +89,7 @@ def test_register_from_pack_fail_on_failure_pack_dir_doesnt_exist(self):
def test_register_from_pack_action_metadata_fails_validation(self):
# No fail on failure flag, should succeed
pack_dir = DUMMY_PACK_4_PATH
runner_dirs = os.path.join(get_fixtures_packs_base_path(), "runners")
runner_dirs = RUNNER_DIRS

opts = [
"--register-pack=%s" % (pack_dir),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,34 @@
from eventlet.green import subprocess

from st2tests.base import IntegrationTestCase
from st2tests.fixturesloader import get_fixtures_base_path
from st2tests.fixtures.conf.fixture import FIXTURE_PATH as CONF_FIXTURES_PATH

__all__ = ["ServiceSetupLogLevelFilteringTestCase"]

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

FIXTURES_DIR = get_fixtures_base_path()

ST2_CONFIG_INFO_LL_PATH = os.path.join(
FIXTURES_DIR, "conf/st2.tests.api.info_log_level.conf"
CONF_FIXTURES_PATH, "st2.tests.api.info_log_level.conf"
)
ST2_CONFIG_INFO_LL_PATH = os.path.abspath(ST2_CONFIG_INFO_LL_PATH)

ST2_CONFIG_DEBUG_LL_PATH = os.path.join(
FIXTURES_DIR, "conf/st2.tests.api.debug_log_level.conf"
CONF_FIXTURES_PATH, "st2.tests.api.debug_log_level.conf"
)
ST2_CONFIG_DEBUG_LL_PATH = os.path.abspath(ST2_CONFIG_DEBUG_LL_PATH)

ST2_CONFIG_AUDIT_LL_PATH = os.path.join(
FIXTURES_DIR, "conf/st2.tests.api.audit_log_level.conf"
CONF_FIXTURES_PATH, "st2.tests.api.audit_log_level.conf"
)
ST2_CONFIG_AUDIT_LL_PATH = os.path.abspath(ST2_CONFIG_AUDIT_LL_PATH)

ST2_CONFIG_SYSTEM_DEBUG_PATH = os.path.join(
FIXTURES_DIR, "conf/st2.tests.api.system_debug_true.conf"
CONF_FIXTURES_PATH, "st2.tests.api.system_debug_true.conf"
)
ST2_CONFIG_SYSTEM_DEBUG_PATH = os.path.abspath(ST2_CONFIG_SYSTEM_DEBUG_PATH)

ST2_CONFIG_SYSTEM_LL_DEBUG_PATH = os.path.join(
FIXTURES_DIR, "conf/st2.tests.api.system_debug_true_logging_debug.conf"
CONF_FIXTURES_PATH, "st2.tests.api.system_debug_true_logging_debug.conf"
)

PYTHON_BINARY = sys.executable
Expand Down
4 changes: 1 addition & 3 deletions st2common/tests/unit/test_crypto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@
from st2common.util.crypto import cryptography_symmetric_encrypt
from st2common.util.crypto import cryptography_symmetric_decrypt

from st2tests.fixturesloader import get_fixtures_base_path
from st2tests.fixtures.keyczar_keys.fixture import FIXTURE_PATH as KEY_FIXTURES_PATH

__all__ = ["CryptoUtilsTestCase", "CryptoUtilsKeyczarCompatibilityTestCase"]

KEY_FIXTURES_PATH = os.path.join(get_fixtures_base_path(), "keyczar_keys/")


class CryptoUtilsTestCase(TestCase):
@classmethod
Expand Down
6 changes: 3 additions & 3 deletions st2common/tests/unit/test_shell_action_system_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

from local_runner.local_shell_script_runner import LocalShellScriptRunner

CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
FIXTURES_DIR = os.path.abspath(os.path.join(CURRENT_DIR, "../fixtures"))
from tests.fixtures.local_runner.fixture import FIXTURE_DIR as LOCAL_RUNNER_FIXTURE_DIR

LOGGED_USER_USERNAME = pwd.getpwuid(os.getuid())[0]

__all__ = ["ShellCommandActionTestCase", "ShellScriptActionTestCase"]
Expand Down Expand Up @@ -110,7 +110,7 @@ def setUp(self):
}

def _get_fixture(self, name):
path = os.path.join(FIXTURES_DIR, "local_runner", name)
path = os.path.join(LOCAL_RUNNER_FIXTURE_DIR, name)

with open(path, "r") as fp:
content = fp.read().strip()
Expand Down
5 changes: 4 additions & 1 deletion st2common/tests/unit/test_spec_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from st2common.util import spec_loader

# indicate to pants that this test uses this fixture.
from st2tests.fixtures.specs import __package__ as specs_fixture_package


class SpecLoaderTest(unittest2.TestCase):
def test_spec_loader(self):
Expand All @@ -31,6 +34,6 @@ def test_bad_spec_duplicate_keys(self):
yaml.constructor.ConstructorError,
'found duplicate key "swagger"',
spec_loader.load_spec,
"st2tests.fixtures.specs",
specs_fixture_package,
"openapi.yaml.j2",
)
Empty file.
18 changes: 18 additions & 0 deletions st2tests/st2tests/fixtures/conf/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2022 The StackStorm Authors.
#
# Licensed 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 os

# Warning: Do not import fixturesloader to avoid breaking
# st2common/tests/integration/log_unicode_data.py
FIXTURE_PATH = os.path.dirname(__file__)
Empty file.
16 changes: 16 additions & 0 deletions st2tests/st2tests/fixtures/keyczar_keys/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2022 The StackStorm Authors.
#
# Licensed 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.
from st2tests import fixturesloader

FIXTURE_NAME, FIXTURE_PATH = fixturesloader.get_fixture_name_and_path(__file__)
16 changes: 16 additions & 0 deletions st2tests/st2tests/fixtures/packs/runners/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2022 The StackStorm Authors.
#
# Licensed 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.
from st2tests import fixturesloader

FIXTURE_NAME, FIXTURE_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions st2tests/st2tests/fixtures/ssl_certs/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2022 The StackStorm Authors.
#
# Licensed 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.
from st2tests import fixturesloader

FIXTURE_NAME, FIXTURE_PATH = fixturesloader.get_fixture_name_and_path(__file__)