Skip to content

Commit

Permalink
Merge branch 'main' into feature/Not_found_error
Browse files Browse the repository at this point in the history
  • Loading branch information
jofsky authored Sep 28, 2023
2 parents c83cc9d + 2aeceef commit 26309e3
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 27 deletions.
23 changes: 18 additions & 5 deletions cumulusci/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,26 @@ def _init_options(self, kwargs):
self.options.update(kwargs)

# Handle dynamic lookup of project_config values via $project_config.attr
for option, value in self.options.items():
if isinstance(value, str):
value = PROJECT_CONFIG_RE.sub(
def process_options(option):
if isinstance(option, str):
return PROJECT_CONFIG_RE.sub(
lambda match: str(self.project_config.lookup(match.group(1), None)),
value,
option,
)
self.options[option] = value
elif isinstance(option, dict):
processed_dict = {}
for key, value in option.items():
processed_dict[key] = process_options(value)
return processed_dict
elif isinstance(option, list):
processed_list = []
for item in option:
processed_list.append(process_options(item))
return processed_list
else:
return option

self.options = process_options(self.options)

if self.Options:
try:
Expand Down
16 changes: 16 additions & 0 deletions cumulusci/core/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ def test_init_options__project_config_substitution(self):
task = BaseTask(self.project_config, self.task_config, self.org_config)
assert task.options["test_option"] == "baz"

# For variable substitution in nested structures
def test_init_options__project_config_substitution_nested(self):
self.project_config.config["foo"] = {"bar": "baz", "fighters": "pretender"}
self.project_config.config["vulf"] = {"peck": "DeanTown"}
self.task_config.config["options"] = {
"test_option": "$project_config.foo__bar",
"songs": [
{"foo_fighters": "$project_config.foo__fighters"},
{"vulfpeck": "$project_config.vulf__peck"},
],
}
task = BaseTask(self.project_config, self.task_config, self.org_config)
assert task.options["test_option"] == "baz"
assert task.options["songs"][0]["foo_fighters"] == "pretender"
assert task.options["songs"][1]["vulfpeck"] == "DeanTown"

def test_init_options__not_shared(self):
self.project_config.config["foo"] = {"bar": "baz"}
self.task_config.config["options"] = {}
Expand Down
21 changes: 19 additions & 2 deletions cumulusci/tasks/salesforce/package_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def _validate_versions(self):
ORDER BY
MajorVersion DESC,
MinorVersion DESC,
PatchVersion DESC
PatchVersion DESC,
ReleaseState DESC
LIMIT 1
"""
),
Expand All @@ -111,7 +112,23 @@ def _validate_versions(self):
# Updates minor version when not passed in remaining cases.
if self.options["major_version"] == str(version["MajorVersion"]):
if "minor_version" in self.options:
if int(self.options["minor_version"]) <= version["MinorVersion"]:
try:
if int(self.options["minor_version"]) < version["MinorVersion"]:
raise TaskOptionsError("Minor Version not valid.")
elif (
int(self.options["minor_version"]) == version["MinorVersion"]
and version["ReleaseState"] == "Released"
):
raise TaskOptionsError("Minor Version not valid.")
else:
if (
int(self.options["minor_version"]) > version["MinorVersion"]
and version["ReleaseState"] == "Beta"
):
raise TaskOptionsError(
"Latest Minor Version is Beta so minor version cannot be greater than that."
)
except ValueError:
raise TaskOptionsError("Minor Version not valid.")
else:
if version["ReleaseState"] == "Beta":
Expand Down
55 changes: 35 additions & 20 deletions cumulusci/tasks/salesforce/tests/test_PackageUpload.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,26 +178,20 @@ def test_positive_validate_versions(self, actual_options, expected_options):
assert task.options["major_version"] == expected_options["major_version"]
assert task.options["minor_version"] == expected_options["minor_version"]

def test_positive_validate_versions_for_beta(self):
actual_options = {
"name": "Test Release",
"production": False,
"description": "Test Description",
"password": "secret",
"post_install_url": "post.install.url",
"release_notes_url": "release.notes.url",
"major_version": "1",
}
expected_options = {
"name": "Test Release",
"production": False,
"description": "Test Description",
"password": "secret",
"post_install_url": "post.install.url",
"release_notes_url": "release.notes.url",
"major_version": "1",
"minor_version": "1",
}
test_positive_options_beta = [
generate_valid_version_options("1", None, "1", "1"),
generate_valid_version_options("1", "1", "1", "1"),
generate_valid_version_options(None, "1", "1", "1"),
generate_valid_version_options(None, None, "1", "1"),
]

@pytest.mark.parametrize(
"actual_options,expected_options", test_positive_options_beta
)
def test_positive_validate_versions_for_beta(
self, actual_options, expected_options
):

task = create_task(PackageUpload, actual_options)
task._get_one_record = mock.Mock(
return_value={
Expand Down Expand Up @@ -225,6 +219,7 @@ def test_positive_validate_versions_for_beta(self):
generate_valid_version_options("1", "0", None, None, True),
generate_valid_version_options(None, "1", None, None, True),
generate_valid_version_options("ab", 0, None, None, True),
generate_valid_version_options("1", "ab", None, None, True),
]

@pytest.mark.parametrize("actual_options", test_negative_options)
Expand All @@ -242,6 +237,26 @@ def test_negative_validate_versions(self, actual_options):
with pytest.raises(TaskOptionsError):
task._validate_versions()

test_negative_options_beta = [
generate_valid_version_options("1", "2", None, None, True),
generate_valid_version_options(None, "2", None, None, True),
]

@pytest.mark.parametrize("actual_options", test_negative_options_beta)
def test_negative_validate_versions_beta(self, actual_options):
"""Running Negative Tests for tests_validate_versions"""
task = create_task(PackageUpload, actual_options)
task._get_one_record = mock.Mock(
return_value={
"MajorVersion": 1,
"MinorVersion": 1,
"PatchVersion": 0,
"ReleaseState": "Beta",
}
)
with pytest.raises(TaskOptionsError):
task._validate_versions()

def test_set_package_info(self):
expected_package_id = "12345"
options = {
Expand Down

0 comments on commit 26309e3

Please sign in to comment.