Skip to content

Commit

Permalink
made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-balachander committed Dec 27, 2023
1 parent c6fb60f commit 3f0a8ef
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
4 changes: 3 additions & 1 deletion cumulusci/tasks/salesforce/retrieve_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def _run_task(self):
)

# zip_result.extractall('./unpackaged')

self.existing_profiles.remove(
"Admin"
) if "Admin" in self.existing_profiles else None
self.logger.info(
f"Profiles {', '.join(self.existing_profiles)} unzipped into folder '{self.extract_dir}'"
)
Expand Down
29 changes: 19 additions & 10 deletions cumulusci/tasks/salesforce/sourcetracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import time
from collections import defaultdict

from cumulusci.core.config import ScratchOrgConfig, TaskConfig
from cumulusci.core.config import BaseProjectConfig, ScratchOrgConfig, TaskConfig
from cumulusci.core.exceptions import ProjectConfigNotFound
from cumulusci.core.sfdx import sfdx
from cumulusci.core.utils import process_bool_arg, process_list_arg
from cumulusci.tasks.metadata.package import PackageXmlGenerator
Expand Down Expand Up @@ -168,7 +169,7 @@ def _reset_sfdx_snapshot(self):
+ " Defaults to project__package__api_version"
)
}
retrieve_changes_task_options["ret_profile"] = {
retrieve_changes_task_options["retrieve_complete_profile"] = {
"description": (
"If set to True, will use RetrieveProfile to retrieve"
+ " the complete profile. Default is set to False"
Expand Down Expand Up @@ -217,13 +218,13 @@ def separate_profiles(components):
def retrieve_components(
components,
org_config,
project_config,
target: str,
md_format: bool,
extra_package_xml_opts: dict,
namespace_tokenize: str,
api_version: str,
ret_profile: bool = False,
project_config: BaseProjectConfig = None,
retrieve_complete_profile: bool = False,
):
"""Retrieve specified components from an org into a target folder.
Expand All @@ -238,6 +239,14 @@ def retrieve_components(

target = os.path.realpath(target)
profiles = []

# If retrieve_complete_profile and project_config is None, raise error
# This is because project_config is only required if retrieve_complete_profile is True
if retrieve_complete_profile and project_config is None:
raise ProjectConfigNotFound(
"Kindly provide project_config as part of retrieve_components"
)

with contextlib.ExitStack() as stack:
if md_format:
# Create target if it doesn't exist
Expand Down Expand Up @@ -270,9 +279,9 @@ def retrieve_components(
check_return=True,
)

# If ret_profile is True, separate the profiles from
# If retrieve_complete_profile is True, separate the profiles from
# components to retrieve complete profile
if ret_profile:
if retrieve_complete_profile:
components, profiles = separate_profiles(components)

if components:
Expand Down Expand Up @@ -347,8 +356,8 @@ class RetrieveChanges(ListChanges, BaseSalesforceApiTask):
def _init_options(self, kwargs):
super(RetrieveChanges, self)._init_options(kwargs)
self.options["snapshot"] = process_bool_arg(kwargs.get("snapshot", True))
self.options["ret_profile"] = process_bool_arg(
self.options.get("ret_profile", False)
self.options["retrieve_complete_profile"] = process_bool_arg(
self.options.get("retrieve_complete_profile", False)
)

# Check which directories are configured as dx packages
Expand Down Expand Up @@ -410,13 +419,13 @@ def _run_task(self):
retrieve_components(
filtered,
self.org_config,
self.project_config,
target,
md_format=self.md_format,
namespace_tokenize=self.options.get("namespace_tokenize"),
api_version=self.options["api_version"],
extra_package_xml_opts=package_xml_opts,
ret_profile=self.options["ret_profile"],
project_config=self.project_config,
retrieve_complete_profile=self.options["retrieve_complete_profile"],
)

if self.options["snapshot"]:
Expand Down
35 changes: 34 additions & 1 deletion cumulusci/tasks/salesforce/tests/test_sourcetracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import pathlib
from unittest import mock

import pytest

from cumulusci.core.config import OrgConfig
from cumulusci.core.exceptions import ProjectConfigNotFound
from cumulusci.tasks.salesforce.retrieve_profile import RetrieveProfile
from cumulusci.tasks.salesforce.sourcetracking import (
KNOWN_BAD_MD_TYPES,
ListChanges,
RetrieveChanges,
SnapshotChanges,
_write_manifest,
retrieve_components,
)
from cumulusci.tests.util import create_project_config
from cumulusci.utils import temporary_dir
Expand Down Expand Up @@ -153,7 +157,11 @@ def test_run_task(self, sfdx, create_task_fixture):
with temporary_dir():
task = create_task_fixture(
RetrieveChanges,
{"include": "Test", "namespace_tokenize": "ns", "ret_profile": True},
{
"include": "Test",
"namespace_tokenize": "ns",
"retrieve_complete_profile": True,
},
)
task._init_task()
task.tooling = mock.Mock()
Expand Down Expand Up @@ -265,3 +273,28 @@ def test_write_manifest__bad_md_types():
assert "<name>Report</name>" in package_xml
for name in bad_md_types:
assert f"<name>{name}</name>" not in package_xml


def test_retrieve_components_project_config_not_found():
components = mock.Mock()
org_config = mock.Mock()
target = "force-app/"
md_format = False
extra_package_xml_opts = {"sample": "dict"}
namespace_tokenize = "sample"
api_version = "58.0"
expected_error_message = (
"Kindly provide project_config as part of retrieve_components"
)
with pytest.raises(ProjectConfigNotFound) as e:
retrieve_components(
components=components,
org_config=org_config,
target=target,
md_format=md_format,
extra_package_xml_opts=extra_package_xml_opts,
namespace_tokenize=namespace_tokenize,
api_version=api_version,
retrieve_complete_profile=True,
)
assert expected_error_message == e.value.message

0 comments on commit 3f0a8ef

Please sign in to comment.