Skip to content

Commit

Permalink
Exceptions Handled (#3656)
Browse files Browse the repository at this point in the history
  • Loading branch information
jain-naman-sf authored Sep 28, 2023
1 parent dda6937 commit 2aeceef
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
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 2aeceef

Please sign in to comment.