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

Removed
Expand Down
34 changes: 16 additions & 18 deletions contrib/runners/python_runner/tests/unit/test_pythonrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
from st2tests.base import CleanDbTestCase
from st2tests.base import blocking_eventlet_spawn
from st2tests.base import make_mock_stream_readline
from st2tests.fixtures.packs.dummy_pack_9.fixture import PACK_PATH as DUMMY_PACK_9_PATH
from st2tests.fixtures.packs.test_content_version_fixture.fixture import (
PACK_NAME as TEST_CONTENT_VERSION,
PACK_PATH as TEST_CONTENT_VERSION_PATH,
)
from st2tests.fixturesloader import assert_submodules_are_checked_out
import st2tests.base as tests_base

Expand All @@ -58,25 +63,18 @@
PATHS_ACTION_PATH = os.path.join(
tests_base.get_resources_path(), "packs", "pythonactions/actions/python_paths.py"
)
ACTION_1_PATH = os.path.join(
tests_base.get_fixtures_path(),
"packs/dummy_pack_9/actions/list_repos_doesnt_exist.py",
)
ACTION_2_PATH = os.path.join(
tests_base.get_fixtures_path(), "packs/dummy_pack_9/actions/invalid_syntax.py"
)
ACTION_1_PATH = os.path.join(DUMMY_PACK_9_PATH, "actions/list_repos_doesnt_exist.py")
ACTION_2_PATH = os.path.join(DUMMY_PACK_9_PATH, "actions/invalid_syntax.py")
NON_SIMPLE_TYPE_ACTION = os.path.join(
tests_base.get_resources_path(), "packs", "pythonactions/actions/non_simple_type.py"
)
PRINT_VERSION_ACTION = os.path.join(
tests_base.get_fixtures_path(),
"packs",
"test_content_version/actions/print_version.py",
TEST_CONTENT_VERSION_PATH,
"actions/print_version.py",
)
PRINT_VERSION_LOCAL_MODULE_ACTION = os.path.join(
tests_base.get_fixtures_path(),
"packs",
"test_content_version/actions/print_version_local_import.py",
TEST_CONTENT_VERSION_PATH,
"actions/print_version_local_import.py",
)

PRINT_CONFIG_ITEM_ACTION = os.path.join(
Expand Down Expand Up @@ -894,7 +892,7 @@ def test_content_version_success(self, mock_get_sandbox_virtualenv_path):
mock_get_sandbox_virtualenv_path.return_value = None

# 1. valid version - 0.2.0
runner = self._get_mock_runner_obj(pack="test_content_version", sandbox=False)
runner = self._get_mock_runner_obj(pack=TEST_CONTENT_VERSION, sandbox=False)
runner.entry_point = PRINT_VERSION_ACTION
runner.runner_parameters = {"content_version": "v0.2.0"}
runner.pre_run()
Expand All @@ -906,7 +904,7 @@ def test_content_version_success(self, mock_get_sandbox_virtualenv_path):
self.assertEqual(output["stdout"].strip(), "v0.2.0")

# 2. valid version - 0.23.0
runner = self._get_mock_runner_obj(pack="test_content_version", sandbox=False)
runner = self._get_mock_runner_obj(pack=TEST_CONTENT_VERSION, sandbox=False)
runner.entry_point = PRINT_VERSION_ACTION
runner.runner_parameters = {"content_version": "v0.3.0"}
runner.pre_run()
Expand All @@ -918,7 +916,7 @@ def test_content_version_success(self, mock_get_sandbox_virtualenv_path):
self.assertEqual(output["stdout"].strip(), "v0.3.0")

# 3. invalid version = 0.30.0
runner = self._get_mock_runner_obj(pack="test_content_version", sandbox=False)
runner = self._get_mock_runner_obj(pack=TEST_CONTENT_VERSION, sandbox=False)
runner.entry_point = PRINT_VERSION_ACTION
runner.runner_parameters = {"content_version": "v0.30.0"}

Expand All @@ -942,7 +940,7 @@ def test_content_version_contains_common_libs_config_enabled(
mock_process.communicate.return_value = ("", "")
mock_popen.return_value = mock_process

runner = self._get_mock_runner_obj(pack="test_content_version", sandbox=False)
runner = self._get_mock_runner_obj(pack=TEST_CONTENT_VERSION, sandbox=False)
runner._enable_common_pack_libs = True
runner.auth_token = mock.Mock()
runner.auth_token.token = "ponies"
Expand All @@ -964,7 +962,7 @@ def test_content_version_success_local_modules_work_fine(
# Verify that local module import correctly use git worktree directory
mock_get_sandbox_virtualenv_path.return_value = None

runner = self._get_mock_runner_obj(pack="test_content_version", sandbox=False)
runner = self._get_mock_runner_obj(pack=TEST_CONTENT_VERSION, sandbox=False)
runner.entry_point = PRINT_VERSION_LOCAL_MODULE_ACTION
runner.runner_parameters = {"content_version": "v0.2.0"}
runner.pre_run()
Expand Down
2 changes: 1 addition & 1 deletion st2api/tests/unit/controllers/v1/test_packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
PACK_PATH as DUMMY_PACK_1_PATH,
)
from st2tests.fixtures.packs.dummy_pack_10.fixture import (
PACK_NAME as DUMMY_PACK_10,
PACK_DIR_NAME as DUMMY_PACK_10,
PACK_PATH as DUMMY_PACK_10_PATH,
)
from st2tests.fixtures.packs.dummy_pack_15.fixture import (
Expand Down
4 changes: 2 additions & 2 deletions st2api/tests/unit/controllers/v1/test_packs_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def test_get_pack_files_and_pack_file_ref_doesnt_equal_pack_name(self):
# Ref is not equal to the name, controller should still work
resp = self.app.get("/v1/packs/views/files/dummy_pack_16")
self.assertEqual(resp.status_int, http_client.OK)
self.assertEqual(len(resp.json), 1)
self.assertEqual(resp.json[0]["file_path"], "pack.yaml")
self.assertEqual(len(resp.json), 3)
self.assertIn("pack.yaml", [f["file_path"] for f in resp.json])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pack in question only had pack.yaml before this PR. I added fixture.py and __init__.py, so the file count goes up to 3.
And, since there is more than one file, we can't just assume that the resp.json[0] is the pack.yaml file. But is it [1] or [2]? It's hard to say because the order might depend on the the filesystem. I tried resp.json[2] which on GHA was not pack.yaml, so they are not sorted alphabetically. To avoid a flaky test relying on a particular sort, I made a list of the files with [f["file_path"] for f in resp.json], and just assert that pack.yaml is in it.


resp = self.app.get("/v1/packs/views/file/dummy_pack_16/pack.yaml")
self.assertEqual(resp.status_int, http_client.OK)
Expand Down
7 changes: 4 additions & 3 deletions st2common/tests/unit/services/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@
from st2common.transport import liveaction as lv_ac_xport
from st2common.transport import publishers
from st2tests.fixtures.packs.core.fixture import PACK_PATH as CORE_PACK_PATH
from st2tests.fixtures.packs.dummy_pack_7.fixture import (
PACK_DIR_NAME as PACK_7,
PACK_PATH as PACK_7_PATH,
)
from st2tests.fixtures.packs.orquesta_tests.fixture import PACK_PATH as TEST_PACK_PATH
from st2tests.mocks import liveaction as mock_lv_ac_xport


PACK_7 = "dummy_pack_7"
PACK_7_PATH = st2tests.fixturesloader.get_fixtures_packs_base_path() + "/" + PACK_7

PACKS = [TEST_PACK_PATH, PACK_7_PATH, CORE_PACK_PATH]


Expand Down
2 changes: 1 addition & 1 deletion st2common/tests/unit/test_config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from st2tests.fixtures.packs.dummy_pack_1.fixture import PACK_NAME as DUMMY_PACK_1
from st2tests.fixtures.packs.dummy_pack_4.fixture import PACK_NAME as DUMMY_PACK_4
from st2tests.fixtures.packs.dummy_pack_5.fixture import PACK_NAME as DUMMY_PACK_5
from st2tests.fixtures.packs.dummy_pack_17.fixture import PACK_NAME as DUMMY_PACK_17
from st2tests.fixtures.packs.dummy_pack_17.fixture import PACK_DIR_NAME as DUMMY_PACK_17
from st2tests.fixtures.packs.dummy_pack_schema_with_additional_items_1.fixture import (
PACK_NAME as DUMMY_PACK_SCHEMA_WITH_ADDITIONAL_ITEMS_1,
)
Expand Down
9 changes: 6 additions & 3 deletions st2common/tests/unit/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from st2common.util.config_parser import ContentPackConfigParser
import st2tests.config as tests_config
from st2tests.fixtures.packs.dummy_pack_1.fixture import PACK_NAME as DUMMY_PACK_1
from st2tests.fixtures.packs.dummy_pack_2.fixture import PACK_NAME as DUMMY_PACK_2
from st2tests.fixtures.packs.dummy_pack_18.fixture import PACK_DIR_NAME as DUMMY_PACK_18


class ContentPackConfigParserTestCase(TestCase):
Expand All @@ -32,22 +35,22 @@ def test_get_config_inexistent_pack(self):
self.assertEqual(config, None)

def test_get_config_no_config(self):
pack_name = "dummy_pack_1"
pack_name = DUMMY_PACK_1
parser = ContentPackConfigParser(pack_name=pack_name)

config = parser.get_config()
self.assertEqual(config, None)

def test_get_config_existing_config(self):
pack_name = "dummy_pack_2"
pack_name = DUMMY_PACK_2
parser = ContentPackConfigParser(pack_name=pack_name)

config = parser.get_config()
self.assertEqual(config.config["section1"]["key1"], "value1")
self.assertEqual(config.config["section2"]["key10"], "value10")

def test_get_config_for_unicode_char(self):
pack_name = "dummy_pack_18"
pack_name = DUMMY_PACK_18
parser = ContentPackConfigParser(pack_name=pack_name)
config = parser.get_config()
self.assertEqual(config.config["section1"]["key1"], "测试")
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@
# limitations under the License.

from __future__ import absolute_import
import os

import mock

from st2tests.base import BaseActionAliasTestCase
from st2tests.fixturesloader import get_fixtures_base_path
from st2tests.fixtures.packs.pack_dir_name_doesnt_match_ref.fixture import (
PACK_NAME as PACK_NAME_NOT_THE_SAME_AS_DIR_NAME,
PACK_PATH as PACK_PATH_1,
)
from st2common.exceptions.content import ParseException
from st2common.models.db.actionalias import ActionAliasDB

__all__ = ["PackActionAliasUnitTestUtils"]

PACK_PATH_1 = os.path.join(
get_fixtures_base_path(), "packs/pack_dir_name_doesnt_match_ref"
)


class PackActionAliasUnitTestUtils(BaseActionAliasTestCase):
action_alias_name = "mock"
Expand Down Expand Up @@ -119,7 +117,7 @@ def test_base_class_works_when_pack_directory_name_doesnt_match_pack_name(self):

action_alias_db = self._get_action_alias_db_by_name(name="alias1")
self.assertEqual(action_alias_db.name, "alias1")
self.assertEqual(action_alias_db.pack, "pack_name_not_the_same_as_dir_name")
self.assertEqual(action_alias_db.pack, PACK_NAME_NOT_THE_SAME_AS_DIR_NAME)

# Note: We mock the original method to make testing of all the edge cases easier
def _get_action_alias_db_by_name(self, name):
Expand Down
23 changes: 13 additions & 10 deletions st2common/tests/unit/test_resource_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 mock
from jsonschema import ValidationError
Expand All @@ -27,7 +25,6 @@
from st2common.persistence.pack import ConfigSchema

from st2tests.base import CleanDbTestCase
from st2tests.fixturesloader import get_fixtures_base_path
from st2tests.fixtures.packs.dummy_pack_1.fixture import (
PACK_NAME as DUMMY_PACK_1,
PACK_PATH as PACK_PATH_1,
Expand All @@ -36,7 +33,16 @@
PACK_NAME as DUMMY_PACK_6,
PACK_PATH as PACK_PATH_6,
)
from st2tests.fixtures.packs.dummy_pack_7.fixture import (
PACK_NAME as DUMMY_PACK_7_NAME,
PACK_PATH as PACK_PATH_7,
)
from st2tests.fixtures.packs.dummy_pack_8.fixture import PACK_PATH as PACK_PATH_8
from st2tests.fixtures.packs.dummy_pack_9.fixture import (
PACK_DIR_NAME as DUMMY_PACK_9,
PACK_NAME as DUMMY_PACK_9_DEPS,
PACK_PATH as PACK_PATH_9,
)
from st2tests.fixtures.packs.dummy_pack_10.fixture import PACK_PATH as PACK_PATH_10
from st2tests.fixtures.packs.dummy_pack_13.fixture import PACK_PATH as PACK_PATH_13
from st2tests.fixtures.packs.dummy_pack_14.fixture import PACK_PATH as PACK_PATH_14
Expand Down Expand Up @@ -64,9 +70,6 @@

__all__ = ["ResourceRegistrarTestCase"]

PACK_PATH_7 = os.path.join(get_fixtures_base_path(), "packs/dummy_pack_7")
PACK_PATH_9 = os.path.join(get_fixtures_base_path(), "packs/dummy_pack_9")


class ResourceRegistrarTestCase(CleanDbTestCase):
def test_register_packs(self):
Expand Down Expand Up @@ -156,8 +159,8 @@ def test_register_pack_pack_ref(self):
# "ref" is not provided, but "name" is
registrar._register_pack_db(pack_name=None, pack_dir=PACK_PATH_7)

pack_db = Pack.get_by_name("dummy_pack_7_name")
self.assertEqual(pack_db.ref, "dummy_pack_7_name")
pack_db = Pack.get_by_name(DUMMY_PACK_7_NAME)
self.assertEqual(pack_db.ref, DUMMY_PACK_7_NAME)

# "ref" is not provided and "name" contains invalid characters
expected_msg = "contains invalid characters"
Expand Down Expand Up @@ -214,12 +217,12 @@ def test_register_pack_pack_stackstorm_version_and_future_parameters(self):

registrar = ResourceRegistrar(use_pack_cache=False)
registrar._pack_loader.get_packs = mock.Mock()
registrar._pack_loader.get_packs.return_value = {"dummy_pack_9": PACK_PATH_9}
registrar._pack_loader.get_packs.return_value = {DUMMY_PACK_9: PACK_PATH_9}
packs_base_paths = content_utils.get_packs_base_paths()
registrar.register_packs(base_dirs=packs_base_paths)

# Dependencies, stackstorm_version and future values
pack_db = Pack.get_by_name("dummy_pack_9_deps")
pack_db = Pack.get_by_name(DUMMY_PACK_9_DEPS)
self.assertEqual(pack_db.dependencies, ["core=0.2.0"])
self.assertEqual(pack_db.stackstorm_version, ">=1.6.0, <2.2.0")
self.assertEqual(pack_db.system, {"centos": {"foo": ">= 1.0"}})
Expand Down
3 changes: 2 additions & 1 deletion st2tests/st2tests/fixtures/packs/dummy_pack_10/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.
from st2tests import fixturesloader

PACK_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
PACK_NAME = "dummy_pack_10_wrong_deps"
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name : dummy_pack_10_wrong_deps

3 changes: 2 additions & 1 deletion st2tests/st2tests/fixtures/packs/dummy_pack_14/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.
from st2tests import fixturesloader

PACK_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
PACK_NAME = "dummy pack 14"
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty file.
16 changes: 16 additions & 0 deletions st2tests/st2tests/fixtures/packs/dummy_pack_16/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

PACK_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one did not need special vars. Instead, it needed special handling in one of the tests that counted the number of files in the pack.

3 changes: 2 additions & 1 deletion st2tests/st2tests/fixtures/packs/dummy_pack_17/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.
from st2tests import fixturesloader

PACK_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
PACK_NAME = "Dummy Pack 17"
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
3 changes: 2 additions & 1 deletion st2tests/st2tests/fixtures/packs/dummy_pack_18/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.
from st2tests import fixturesloader

PACK_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
PACK_NAME = "Dummy Pack 18"
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty file.
17 changes: 17 additions & 0 deletions st2tests/st2tests/fixtures/packs/dummy_pack_7/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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

PACK_NAME = "dummy_pack_7_name"
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 changes: 2 additions & 1 deletion st2tests/st2tests/fixtures/packs/dummy_pack_8/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.
from st2tests import fixturesloader

PACK_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
PACK_NAME = "Dummy Pack 8 Invalid Name"
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name : Dummy Pack 8 Invalid Name

Empty file.
17 changes: 17 additions & 0 deletions st2tests/st2tests/fixtures/packs/dummy_pack_9/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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

PACK_NAME = "dummy_pack_9_deps"
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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

PACK_NAME = "pack_name_not_the_same_as_dir_name"
PACK_DIR_NAME, PACK_PATH = fixturesloader.get_fixture_name_and_path(__file__)
Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref: pack_name_not_the_same_as_dir_name
name: pack_name_not_the_same_as_dir_name

Loading