From b58ffb7b6a45a48289e3120e47db6bb415665df1 Mon Sep 17 00:00:00 2001 From: lakshmi2506 Date: Wed, 18 Oct 2023 11:31:47 +0530 Subject: [PATCH 1/6] no_plans_error --- cumulusci/tasks/metadeploy.py | 6 ++++- cumulusci/tasks/tests/test_metadeploy.py | 28 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cumulusci/tasks/metadeploy.py b/cumulusci/tasks/metadeploy.py index e55154422f..b207f46557 100644 --- a/cumulusci/tasks/metadeploy.py +++ b/cumulusci/tasks/metadeploy.py @@ -90,6 +90,11 @@ def _init_task(self): else: self.plan_configs = self.project_config.plans + if not self.plan_configs: + raise CumulusCIException( + "No plan found to publish in project configuration" + ) + self._load_labels() def _run_task(self): @@ -138,7 +143,6 @@ def _run_task(self): ) project_config.set_keychain(self.project_config.keychain) - # Create each plan for plan_name, plan_config in self.plan_configs.items(): self._add_plan_labels( plan_name=plan_name, diff --git a/cumulusci/tasks/tests/test_metadeploy.py b/cumulusci/tasks/tests/test_metadeploy.py index 785dba131e..5883d7c489 100644 --- a/cumulusci/tasks/tests/test_metadeploy.py +++ b/cumulusci/tasks/tests/test_metadeploy.py @@ -439,6 +439,14 @@ def test_find_product__not_found(self): ) project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" + project_config.config["plans"] = { + "install": { + "title": "Test Install", + "slug": "install", + "tier": "primary", + "steps": {1: {"flow": "install_prod"}}, + } + } project_config.keychain.set_service( "metadeploy", "test_alias", @@ -485,6 +493,23 @@ def test_init_task__named_plan(self): task._init_task() assert expected_plans == task.plan_configs + @responses.activate + def test_init_task_no_plan(self): + project_config = create_project_config() + project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" + project_config.keychain.set_service( + "metadeploy", + "test_alias", + ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}), + ) + task_config = TaskConfig({"options": {"tag": "release/1.0"}}) + task = Publish(project_config, task_config) + with pytest.raises( + CumulusCIException, + match="No plan found to publish in project configuration", + ): + task._init_task() + @responses.activate def test_find_or_create_plan_template__not_found(self): responses.add( @@ -540,6 +565,9 @@ def test_freeze_steps__skip(self): "tier": "primary", "steps": {1: {"task": "None"}}, } + project_config.config["plans"] = { + "Test Install": plan_config, + } task_config = TaskConfig({"options": {"tag": "release/1.0"}}) task = Publish(project_config, task_config) task._init_task() From 1f28522a615ee62756c6117764d93dbcb9835147 Mon Sep 17 00:00:00 2001 From: lakshmi2506 Date: Wed, 18 Oct 2023 11:51:03 +0530 Subject: [PATCH 2/6] no_plans_error --- cumulusci/tasks/metadeploy.py | 4 ++++ cumulusci/tasks/tests/test_metadeploy.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cumulusci/tasks/metadeploy.py b/cumulusci/tasks/metadeploy.py index b207f46557..de2a87a650 100644 --- a/cumulusci/tasks/metadeploy.py +++ b/cumulusci/tasks/metadeploy.py @@ -83,6 +83,10 @@ def _init_task(self): Path(self.labels_path).mkdir(parents=True, exist_ok=True) if plan_name := self.options.get("plan"): + if not self.project_config.lookup(f"plans__{plan_name}"): + raise TaskOptionsError( + f"Plan {plan_name} not found in project configuration" + ) plan_configs = { plan_name: self.project_config.lookup(f"plans__{plan_name}") } diff --git a/cumulusci/tasks/tests/test_metadeploy.py b/cumulusci/tasks/tests/test_metadeploy.py index 5883d7c489..71069aba24 100644 --- a/cumulusci/tasks/tests/test_metadeploy.py +++ b/cumulusci/tasks/tests/test_metadeploy.py @@ -510,6 +510,23 @@ def test_init_task_no_plan(self): ): task._init_task() + @responses.activate + def test_init_task_no_plan_name(self): + project_config = create_project_config() + project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" + project_config.keychain.set_service( + "metadeploy", + "test_alias", + ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}), + ) + task_config = TaskConfig({"options": {"tag": "release/1.0", "plan": "install"}}) + task = Publish(project_config, task_config) + with pytest.raises( + TaskOptionsError, + match="Plan install not found in project configuration", + ): + task._init_task() + @responses.activate def test_find_or_create_plan_template__not_found(self): responses.add( From 0e8dc928c6131be61ecec28195a3ed936648b967 Mon Sep 17 00:00:00 2001 From: lakshmi2506 Date: Wed, 18 Oct 2023 13:22:02 +0530 Subject: [PATCH 3/6] no_plans_error --- cumulusci/tasks/metadeploy.py | 5 ++--- cumulusci/tasks/tests/test_metadeploy.py | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cumulusci/tasks/metadeploy.py b/cumulusci/tasks/metadeploy.py index de2a87a650..e2cd3a021e 100644 --- a/cumulusci/tasks/metadeploy.py +++ b/cumulusci/tasks/metadeploy.py @@ -1,6 +1,7 @@ import contextlib import json import re +from os import error from pathlib import Path from typing import List, Optional, Union @@ -95,9 +96,7 @@ def _init_task(self): self.plan_configs = self.project_config.plans if not self.plan_configs: - raise CumulusCIException( - "No plan found to publish in project configuration" - ) + raise error("No plan found to publish in project configuration") self._load_labels() diff --git a/cumulusci/tasks/tests/test_metadeploy.py b/cumulusci/tasks/tests/test_metadeploy.py index 71069aba24..92f4ff94f7 100644 --- a/cumulusci/tasks/tests/test_metadeploy.py +++ b/cumulusci/tasks/tests/test_metadeploy.py @@ -4,6 +4,7 @@ import tempfile import zipfile from base64 import b64encode +from os import error from pathlib import Path import pytest @@ -505,7 +506,7 @@ def test_init_task_no_plan(self): task_config = TaskConfig({"options": {"tag": "release/1.0"}}) task = Publish(project_config, task_config) with pytest.raises( - CumulusCIException, + error, match="No plan found to publish in project configuration", ): task._init_task() From f4a1c10d952658ee99c957fe72d41d7a51fe6a70 Mon Sep 17 00:00:00 2001 From: lakshmi2506 Date: Wed, 18 Oct 2023 14:30:33 +0530 Subject: [PATCH 4/6] no_plans_error --- cumulusci/tasks/metadeploy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulusci/tasks/metadeploy.py b/cumulusci/tasks/metadeploy.py index e2cd3a021e..bdb9197927 100644 --- a/cumulusci/tasks/metadeploy.py +++ b/cumulusci/tasks/metadeploy.py @@ -84,7 +84,7 @@ def _init_task(self): Path(self.labels_path).mkdir(parents=True, exist_ok=True) if plan_name := self.options.get("plan"): - if not self.project_config.lookup(f"plans__{plan_name}"): + if self.project_config.lookup(f"plans__{plan_name}") is None: raise TaskOptionsError( f"Plan {plan_name} not found in project configuration" ) @@ -95,7 +95,7 @@ def _init_task(self): else: self.plan_configs = self.project_config.plans - if not self.plan_configs: + if self.plan_configs is None or len(self.plan_configs) == 0: raise error("No plan found to publish in project configuration") self._load_labels() From 4574e01e2ebd4ff024bb8e3aeb19730b8e7d1027 Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Wed, 18 Oct 2023 16:06:32 +0530 Subject: [PATCH 5/6] Added Comments --- cumulusci/tasks/metadeploy.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cumulusci/tasks/metadeploy.py b/cumulusci/tasks/metadeploy.py index bdb9197927..abde10dc6e 100644 --- a/cumulusci/tasks/metadeploy.py +++ b/cumulusci/tasks/metadeploy.py @@ -94,7 +94,7 @@ def _init_task(self): self.plan_configs = plan_configs else: self.plan_configs = self.project_config.plans - + # Handled exception for no plan if self.plan_configs is None or len(self.plan_configs) == 0: raise error("No plan found to publish in project configuration") @@ -115,7 +115,6 @@ def _run_task(self): raise CumulusCIException( f"No slug found in MetaDeploy for product {product} from {repo_url}" ) - if not self.dry_run: version = self._find_or_create_version(product) if self.labels_path and "slug" in product: From 39dd04bf1124b7448832ca6b7e54b6f2b65e5f01 Mon Sep 17 00:00:00 2001 From: lakshmi2506 Date: Tue, 24 Oct 2023 09:43:36 +0530 Subject: [PATCH 6/6] tests are parametorized --- cumulusci/tasks/metadeploy.py | 5 +-- cumulusci/tasks/tests/test_metadeploy.py | 42 +++++++++++------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/cumulusci/tasks/metadeploy.py b/cumulusci/tasks/metadeploy.py index abde10dc6e..53f87c3877 100644 --- a/cumulusci/tasks/metadeploy.py +++ b/cumulusci/tasks/metadeploy.py @@ -1,7 +1,6 @@ import contextlib import json import re -from os import error from pathlib import Path from typing import List, Optional, Union @@ -96,7 +95,9 @@ def _init_task(self): self.plan_configs = self.project_config.plans # Handled exception for no plan if self.plan_configs is None or len(self.plan_configs) == 0: - raise error("No plan found to publish in project configuration") + raise CumulusCIException( + "No plan found to publish in project configuration" + ) self._load_labels() diff --git a/cumulusci/tasks/tests/test_metadeploy.py b/cumulusci/tasks/tests/test_metadeploy.py index 92f4ff94f7..bd39b62a35 100644 --- a/cumulusci/tasks/tests/test_metadeploy.py +++ b/cumulusci/tasks/tests/test_metadeploy.py @@ -4,7 +4,6 @@ import tempfile import zipfile from base64 import b64encode -from os import error from pathlib import Path import pytest @@ -494,25 +493,22 @@ def test_init_task__named_plan(self): task._init_task() assert expected_plans == task.plan_configs - @responses.activate - def test_init_task_no_plan(self): - project_config = create_project_config() - project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" - project_config.keychain.set_service( - "metadeploy", - "test_alias", - ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}), - ) - task_config = TaskConfig({"options": {"tag": "release/1.0"}}) - task = Publish(project_config, task_config) - with pytest.raises( - error, - match="No plan found to publish in project configuration", - ): - task._init_task() - - @responses.activate - def test_init_task_no_plan_name(self): + @pytest.mark.parametrize( + "options, errortype,errormsg", + [ + ( + {"tag": "release/1.0"}, + CumulusCIException, + "No plan found to publish in project configuration", + ), + ( + {"tag": "release/1.0", "plan": "install"}, + TaskOptionsError, + "Plan install not found in project configuration", + ), + ], + ) + def test_init_task_no_plan(self, options, errortype, errormsg): project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" project_config.keychain.set_service( @@ -520,11 +516,11 @@ def test_init_task_no_plan_name(self): "test_alias", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}), ) - task_config = TaskConfig({"options": {"tag": "release/1.0", "plan": "install"}}) + task_config = TaskConfig({"options": options}) task = Publish(project_config, task_config) with pytest.raises( - TaskOptionsError, - match="Plan install not found in project configuration", + errortype, + match=errormsg, ): task._init_task()