Repository: SFDO-Tooling/CumulusCI
Pull request #3656 (2023-09-20 09:45:43)

Add exception handling for minor release version comparison when uploading packages
Add exception handling for minor release version comparison when uploading packages


Patch:
diff --git a/cumulusci/tasks/salesforce/package_upload.py b/cumulusci/tasks/salesforce/package_upload.py
index f58029ee6..15c639293 100644
--- a/cumulusci/tasks/salesforce/package_upload.py
+++ b/cumulusci/tasks/salesforce/package_upload.py
@@ -89,7 +89,8 @@ class PackageUpload(BaseSalesforceApiTask):
                 ORDER BY
                 MajorVersion DESC,
                 MinorVersion DESC,
-                PatchVersion DESC
+                PatchVersion DESC,
+                ReleaseState DESC
                 LIMIT 1
                 """
             ),
@@ -111,7 +112,23 @@ class PackageUpload(BaseSalesforceApiTask):
         # 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":


Test patch:
diff --git a/cumulusci/tasks/salesforce/tests/test_PackageUpload.py b/cumulusci/tasks/salesforce/tests/test_PackageUpload.py
index c98a2e797..cceac1e68 100644
--- a/cumulusci/tasks/salesforce/tests/test_PackageUpload.py
+++ b/cumulusci/tasks/salesforce/tests/test_PackageUpload.py
@@ -178,26 +178,20 @@ class TestPackageUpload:
         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 @@ class TestPackageUpload:
         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 @@ class TestPackageUpload:
         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 = {