From 2aeceef1d4c5b05fc5344faa8f07426db71bdf26 Mon Sep 17 00:00:00 2001 From: Naman Jain Date: Fri, 29 Sep 2023 02:49:10 +0530 Subject: [PATCH] Exceptions Handled (#3656) --- cumulusci/tasks/salesforce/package_upload.py | 21 ++++++- .../salesforce/tests/test_PackageUpload.py | 55 ++++++++++++------- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/cumulusci/tasks/salesforce/package_upload.py b/cumulusci/tasks/salesforce/package_upload.py index f58029ee68..15c6392938 100644 --- a/cumulusci/tasks/salesforce/package_upload.py +++ b/cumulusci/tasks/salesforce/package_upload.py @@ -89,7 +89,8 @@ def _validate_versions(self): ORDER BY MajorVersion DESC, MinorVersion DESC, - PatchVersion DESC + PatchVersion DESC, + ReleaseState DESC LIMIT 1 """ ), @@ -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": diff --git a/cumulusci/tasks/salesforce/tests/test_PackageUpload.py b/cumulusci/tasks/salesforce/tests/test_PackageUpload.py index c98a2e7970..cceac1e68f 100644 --- a/cumulusci/tasks/salesforce/tests/test_PackageUpload.py +++ b/cumulusci/tasks/salesforce/tests/test_PackageUpload.py @@ -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={ @@ -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) @@ -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 = {