Skip to content
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

Use python imports to identify fixtures (part 3/6) #5703

Merged
merged 5 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
* Refactor tests to use python imports to identify test fixtures. #5699 #5702 #5703
Contributed by @cognifloyd

Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from st2common.util import action_db as action_db_util
from st2common.exceptions.action import ParameterRenderingFailedException
from st2tests import ExecutionDbTestCase
from st2tests.fixtures.generic.fixture import PACK_NAME as FIXTURES_PACK
from st2tests.fixturesloader import FixturesLoader


Expand All @@ -45,8 +46,6 @@ def __init__(self, status=LIVEACTION_STATUS_SUCCEEDED, result=""):
self.result = result


FIXTURES_PACK = "generic"

TEST_MODELS = {
"actions": ["a1.yaml", "a2.yaml", "action_4_action_context_param.yaml"],
"runners": ["testrunner1.yaml"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from st2common.transport.liveaction import LiveActionPublisher
from st2common.transport.publishers import CUDPublisher

from st2tests.fixtures.generic.fixture import PACK_NAME as FIXTURES_PACK
from st2tests.fixtures.packs.action_chain_tests.fixture import (
PACK_NAME as TEST_PACK,
PACK_PATH as TEST_PACK_PATH,
Expand All @@ -50,8 +51,6 @@ def __init__(self, status=action_constants.LIVEACTION_STATUS_SUCCEEDED, result="
self.result = result


FIXTURES_PACK = "generic"

TEST_MODELS = {"actions": ["a1.yaml", "a2.yaml"], "runners": ["testrunner1.yaml"]}

MODELS = fixturesloader.FixturesLoader().load_models(
Expand Down
32 changes: 17 additions & 15 deletions contrib/runners/local_runner/tests/integration/test_localrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
from st2tests.base import CleanDbTestCase
from st2tests.base import blocking_eventlet_spawn
from st2tests.base import make_mock_stream_readline
from st2tests.fixtures.generic.fixture import PACK_NAME as GENERIC_PACK
from st2tests.fixtures.localrunner_pack.fixture import PACK_NAME as LOCALRUNNER_PACK

from local_runner import base as local_runner
from local_runner.local_shell_command_runner import LocalShellCommandRunner
Expand All @@ -60,7 +62,7 @@ def setUp(self):

def test_shell_command_action_basic(self):
models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]

Expand Down Expand Up @@ -94,7 +96,7 @@ def test_shell_command_action_basic(self):

def test_timeout(self):
models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]
# smaller timeout == faster tests.
Expand All @@ -109,7 +111,7 @@ def test_timeout(self):
)
def test_shutdown(self):
models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]
runner = self._get_runner(action_db, cmd="sleep 0.1")
Expand All @@ -119,7 +121,7 @@ def test_shutdown(self):

def test_common_st2_env_vars_are_available_to_the_action(self):
models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]

Expand All @@ -144,7 +146,7 @@ def test_sudo_and_env_variable_preservation(self):
# root / non-system user
# Note: This test will fail if SETENV option is not present in the sudoers file
models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]

Expand Down Expand Up @@ -188,7 +190,7 @@ def test_action_stdout_and_stderr_is_stored_in_the_db(self, mock_spawn, mock_pop
)

models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]

Expand Down Expand Up @@ -225,7 +227,7 @@ def test_action_stdout_and_stderr_is_stored_in_the_db_short_running_action(
# Verify that we correctly retrieve all the output and wait for stdout and stderr reading
# threads for short running actions.
models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]

Expand Down Expand Up @@ -298,7 +300,7 @@ def test_action_stdout_and_stderr_is_stored_in_the_db_short_running_action(
def test_shell_command_sudo_password_is_passed_to_sudo_binary(self):
# Verify that sudo password is correctly passed to sudo binary via stdin
models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]

Expand Down Expand Up @@ -356,7 +358,7 @@ def test_shell_command_sudo_password_is_passed_to_sudo_binary(self):
def test_shell_command_invalid_stdout_password(self):
# Simulate message printed to stderr by sudo when invalid sudo password is provided
models = self.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["local.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
)
action_db = models["actions"]["local.yaml"]

Expand Down Expand Up @@ -426,7 +428,7 @@ def setUp(self):

def test_script_with_parameters_parameter_serialization(self):
models = self.fixtures_loader.load_models(
fixtures_pack="generic",
fixtures_pack=GENERIC_PACK,
fixtures_dict={"actions": ["local_script_with_params.yaml"]},
)
action_db = models["actions"]["local_script_with_params.yaml"]
Expand Down Expand Up @@ -557,7 +559,7 @@ def test_action_stdout_and_stderr_is_stored_in_the_db(self, mock_spawn, mock_pop
)

models = self.fixtures_loader.load_models(
fixtures_pack="generic",
fixtures_pack=GENERIC_PACK,
fixtures_dict={"actions": ["local_script_with_params.yaml"]},
)
action_db = models["actions"]["local_script_with_params.yaml"]
Expand Down Expand Up @@ -604,12 +606,12 @@ def test_action_stdout_and_stderr_is_stored_in_the_db(self, mock_spawn, mock_pop

def test_shell_script_action(self):
models = self.fixtures_loader.load_models(
fixtures_pack="localrunner_pack",
fixtures_pack=LOCALRUNNER_PACK,
fixtures_dict={"actions": ["text_gen.yml"]},
)
action_db = models["actions"]["text_gen.yml"]
entry_point = self.fixtures_loader.get_fixture_file_path_abs(
"localrunner_pack", "actions", "text_gen.py"
LOCALRUNNER_PACK, "actions", "text_gen.py"
)
runner = self._get_runner(action_db, entry_point=entry_point)
runner.pre_run()
Expand All @@ -620,12 +622,12 @@ def test_shell_script_action(self):

def test_large_stdout(self):
models = self.fixtures_loader.load_models(
fixtures_pack="localrunner_pack",
fixtures_pack=LOCALRUNNER_PACK,
fixtures_dict={"actions": ["text_gen.yml"]},
)
action_db = models["actions"]["text_gen.yml"]
entry_point = self.fixtures_loader.get_fixture_file_path_abs(
"localrunner_pack", "actions", "text_gen.py"
LOCALRUNNER_PACK, "actions", "text_gen.py"
)
runner = self._get_runner(action_db, entry_point=entry_point)
runner.pre_run()
Expand Down
3 changes: 2 additions & 1 deletion contrib/runners/noop_runner/tests/unit/test_nooprunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from unittest2 import TestCase
from st2common.constants import action as action_constants
from st2tests.fixtures.generic.fixture import PACK_NAME as GENERIC_PACK
from st2tests.fixturesloader import FixturesLoader
from noop_runner import noop_runner

Expand All @@ -34,7 +35,7 @@ class TestNoopRunner(TestCase):

def test_noop_command_executes(self):
models = TestNoopRunner.fixtures_loader.load_models(
fixtures_pack="generic", fixtures_dict={"actions": ["noop.yaml"]}
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["noop.yaml"]}
)

action_db = models["actions"]["noop.yaml"]
Expand Down
2 changes: 1 addition & 1 deletion st2actions/tests/unit/policies/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
from st2common.bootstrap import runnersregistrar as runners_registrar
from st2tests.base import DbTestCase
from st2tests.base import CleanDbTestCase
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader


__all__ = ["SchedulerPoliciesTestCase", "NotifierPoliciesTestCase"]


PACK = "generic"
TEST_FIXTURES_1 = {
"actions": ["action1.yaml"],
"policies": [
Expand Down
2 changes: 1 addition & 1 deletion st2actions/tests/unit/policies/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from st2tests import DbTestCase, EventletTestCase
from st2tests import ExecutionDbTestCase
import st2tests.config as tests_config
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader
from st2tests.mocks.execution import MockExecutionPublisher
from st2tests.mocks.liveaction import MockLiveActionPublisherSchedulingQueueOnly
Expand All @@ -49,7 +50,6 @@

__all__ = ["ConcurrencyPolicyTestCase"]

PACK = "generic"
TEST_FIXTURES = {
"actions": ["action1.yaml", "action2.yaml"],
"policies": ["policy_1.yaml", "policy_5.yaml"],
Expand Down
2 changes: 1 addition & 1 deletion st2actions/tests/unit/policies/test_concurrency_by_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from st2common.bootstrap import runnersregistrar as runners_registrar
from st2tests import ExecutionDbTestCase, EventletTestCase
import st2tests.config as tests_config
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader
from st2tests.mocks.execution import MockExecutionPublisher
from st2tests.mocks.liveaction import MockLiveActionPublisherSchedulingQueueOnly
Expand All @@ -46,7 +47,6 @@

__all__ = ["ConcurrencyByAttributePolicyTestCase"]

PACK = "generic"
TEST_FIXTURES = {
"actions": ["action1.yaml", "action2.yaml"],
"policies": ["policy_3.yaml", "policy_7.yaml"],
Expand Down
2 changes: 1 addition & 1 deletion st2actions/tests/unit/policies/test_retry_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
from st2actions.policies.retry import ExecutionRetryPolicyApplicator
from st2tests.base import DbTestCase
from st2tests.base import CleanDbTestCase
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader

__all__ = ["RetryPolicyTestCase"]

PACK = "generic"
TEST_FIXTURES = {"actions": ["action1.yaml"], "policies": ["policy_4.yaml"]}


Expand Down
25 changes: 13 additions & 12 deletions st2actions/tests/unit/test_actions_registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

from __future__ import absolute_import

import os

import six
import jsonschema
import mock
Expand All @@ -28,8 +26,11 @@
from st2common.models.db.runner import RunnerTypeDB

import st2tests.base as tests_base
from st2tests.fixtures.generic.fixture import (
PACK_NAME as GENERIC_PACK,
PACK_PATH as GENERIC_PACK_PATH,
)
import st2tests.fixturesloader as fixtures_loader
from st2tests.fixturesloader import get_fixtures_base_path

MOCK_RUNNER_TYPE_DB = RunnerTypeDB(name="run-local", runner_module="st2.runners.local")

Expand All @@ -38,7 +39,7 @@
# base paths directory. This will never happen outside the context of test fixtures.
@mock.patch(
"st2common.content.utils.get_pack_base_path",
mock.Mock(return_value=os.path.join(get_fixtures_base_path(), "generic")),
mock.Mock(return_value=GENERIC_PACK_PATH),
)
class ActionsRegistrarTest(tests_base.DbTestCase):
@mock.patch.object(
Expand Down Expand Up @@ -85,7 +86,7 @@ def test_pack_name_missing(self):
registrar = actions_registrar.ActionsRegistrar()
loader = fixtures_loader.FixturesLoader()
action_file = loader.get_fixture_file_path_abs(
"generic", "actions", "action_3_pack_missing.yaml"
GENERIC_PACK, "actions", "action_3_pack_missing.yaml"
)
registrar._register_action("dummy", action_file)
action_name = None
Expand All @@ -109,7 +110,7 @@ def test_register_action_with_no_params(self):
registrar = actions_registrar.ActionsRegistrar()
loader = fixtures_loader.FixturesLoader()
action_file = loader.get_fixture_file_path_abs(
"generic", "actions", "action-with-no-parameters.yaml"
GENERIC_PACK, "actions", "action-with-no-parameters.yaml"
)

self.assertEqual(registrar._register_action("dummy", action_file), False)
Expand All @@ -126,7 +127,7 @@ def test_register_action_invalid_parameter_type_attribute(self):
registrar = actions_registrar.ActionsRegistrar()
loader = fixtures_loader.FixturesLoader()
action_file = loader.get_fixture_file_path_abs(
"generic", "actions", "action_invalid_param_type.yaml"
GENERIC_PACK, "actions", "action_invalid_param_type.yaml"
)

expected_msg = "'list' is not valid under any of the given schema"
Expand All @@ -150,7 +151,7 @@ def test_register_action_invalid_parameter_name(self):
registrar = actions_registrar.ActionsRegistrar()
loader = fixtures_loader.FixturesLoader()
action_file = loader.get_fixture_file_path_abs(
"generic", "actions", "action_invalid_parameter_name.yaml"
GENERIC_PACK, "actions", "action_invalid_parameter_name.yaml"
)

expected_msg = (
Expand All @@ -161,7 +162,7 @@ def test_register_action_invalid_parameter_name(self):
jsonschema.ValidationError,
expected_msg,
registrar._register_action,
"generic",
GENERIC_PACK,
action_file,
)

Expand All @@ -177,10 +178,10 @@ def test_invalid_params_schema(self):
registrar = actions_registrar.ActionsRegistrar()
loader = fixtures_loader.FixturesLoader()
action_file = loader.get_fixture_file_path_abs(
"generic", "actions", "action-invalid-schema-params.yaml"
GENERIC_PACK, "actions", "action-invalid-schema-params.yaml"
)
try:
registrar._register_action("generic", action_file)
registrar._register_action(GENERIC_PACK, action_file)
self.fail("Invalid action schema. Should have failed.")
except jsonschema.ValidationError:
pass
Expand All @@ -197,7 +198,7 @@ def test_action_update(self):
registrar = actions_registrar.ActionsRegistrar()
loader = fixtures_loader.FixturesLoader()
action_file = loader.get_fixture_file_path_abs(
"generic", "actions", "action1.yaml"
GENERIC_PACK, "actions", "action1.yaml"
)
registrar._register_action("wolfpack", action_file)
# try registering again. this should not throw errors.
Expand Down
2 changes: 1 addition & 1 deletion st2actions/tests/unit/test_execution_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from st2common.transport.liveaction import LiveActionPublisher
from st2common.transport.publishers import CUDPublisher
from st2tests import ExecutionDbTestCase
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader
from st2tests.mocks.execution import MockExecutionPublisher
from st2tests.mocks.liveaction import MockLiveActionPublisher
Expand All @@ -47,7 +48,6 @@

TEST_FIXTURES = {"actions": ["action1.yaml"]}

PACK = "generic"
LOADER = FixturesLoader()
FIXTURES = LOADER.load_fixtures(fixtures_pack=PACK, fixtures_dict=TEST_FIXTURES)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@

from remote_runner.remote_script_runner import ParamikoRemoteScriptRunner

from st2tests.fixtures.generic.fixture import PACK_NAME as FIXTURES_PACK
from st2tests.fixturesloader import FixturesLoader

__all__ = ["ParamikoScriptRunnerTestCase"]

FIXTURES_PACK = "generic"
TEST_MODELS = {"actions": ["a1.yaml"]}

MODELS = FixturesLoader().load_models(
Expand Down
Loading