Skip to content

Commit

Permalink
updated list_components
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmi2506 committed Jan 22, 2024
1 parent 78ab6ab commit 1bebb37
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 54 deletions.
23 changes: 7 additions & 16 deletions cumulusci/tasks/salesforce/nonsourcetracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
import sarge

from cumulusci.core.config import TaskConfig
from cumulusci.core.exceptions import (
CumulusCIException,
SfdxOrgException,
TaskOptionsError,
)
from cumulusci.core.exceptions import CumulusCIException, SfdxOrgException
from cumulusci.core.sfdx import sfdx
from cumulusci.core.utils import process_list_arg
from cumulusci.tasks.salesforce import (
Expand Down Expand Up @@ -111,17 +107,13 @@ def _get_components(self):
task_config = TaskConfig(
{"options": {"api_version": self.options["api_version"]}}
)
metadata_types = ListNonSourceTrackable(
org_config=self.org_config,
project_config=self.project_config,
task_config=task_config,
)._run_task()
if not self.options["metadata_types"]:
metadata_types = ListNonSourceTrackable(
org_config=self.org_config,
project_config=self.project_config,
task_config=task_config,
)._run_task()
self.options["metadata_types"] = metadata_types
else:
for md_type in self.options["metadata_types"]:
if md_type not in metadata_types:
raise TaskOptionsError(f"Invalid metadata type: {md_type}")
list_components = []
for md_type in self.options["metadata_types"]:
p: sarge.Command = sfdx(
Expand All @@ -137,8 +129,7 @@ def _get_components(self):
],
env={"SFDX_INSTANCE_URL": self.org_config.instance_url},
)
stdout = p.stdout_text.read()
stderr = p.stderr_text.read()
stdout, stderr = p.stdout_text.read(), p.stderr_text.read()

if p.returncode:
message = f"\nstderr:\n{nl.join(stderr)}"
Expand Down
77 changes: 39 additions & 38 deletions cumulusci/tasks/salesforce/tests/test_nonsourcetracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import pytest
import responses

from cumulusci.core.exceptions import (
CumulusCIException,
SfdxOrgException,
TaskOptionsError,
)
from cumulusci.core.exceptions import CumulusCIException, SfdxOrgException
from cumulusci.tasks.salesforce import DescribeMetadataTypes
from cumulusci.tasks.salesforce.nonsourcetracking import (
ListComponents,
Expand Down Expand Up @@ -127,7 +123,9 @@ def test_check_sfdx_output(self, cmd, create_task_fixture, return_code, result):
"options",
[
{"api_version": 44.0, "metadata_types": "FlowDefinition"},
{"api_version": 44.0, "metadata_types": "Index"},
{
"api_version": 44.0,
},
],
)
def test_check_sfdx_result(self, cmd, create_task_fixture, options):
Expand Down Expand Up @@ -170,42 +168,45 @@ def test_check_sfdx_result(self, cmd, create_task_fixture, options):
)
messages = []
task._init_task()
with mock.patch.object(
ListNonSourceTrackable,
"_run_task",
return_value=["FlowDefinition", "SharingRules"],
):

if task.options["metadata_types"] == ["Index"]:
with pytest.raises(TaskOptionsError):
task._run_task()
else:
task.logger = mock.Mock()
task.logger.info = messages.append
components = task._run_task()
task.logger = mock.Mock()
task.logger.info = messages.append
if "metadata_types" in options:
components = task._run_task()
assert cmd.call_count == 1
assert (
"sfdx force:mdapi:listmetadata -a 44.0 -m FlowDefinition --json"
in cmd.call_args[0][0]
)
assert components == [
{
"MemberType": "FlowDefinition",
"MemberName": "alpha",
"lastModifiedByName": "User User",
"lastModifiedDate": "2024-01-02T06:50:07.000Z",
},
{
"MemberType": "FlowDefinition",
"MemberName": "beta",
"lastModifiedByName": "User User",
"lastModifiedDate": "2024-01-02T06:50:07.000Z",
},
]
assert (
"Found 2 non source trackable components in the org for the given types."
in messages
)
else:
with mock.patch.object(
ListNonSourceTrackable,
"_run_task",
return_value=["Index"],
):
task._run_task()
assert cmd.call_count == 1
assert (
"sfdx force:mdapi:listmetadata -a 44.0 -m FlowDefinition --json"
"sfdx force:mdapi:listmetadata -a 44.0 -m Index --json"
in cmd.call_args[0][0]
)
assert components == [
{
"MemberType": "FlowDefinition",
"MemberName": "alpha",
"lastModifiedByName": "User User",
"lastModifiedDate": "2024-01-02T06:50:07.000Z",
},
{
"MemberType": "FlowDefinition",
"MemberName": "beta",
"lastModifiedByName": "User User",
"lastModifiedDate": "2024-01-02T06:50:07.000Z",
},
]
assert (
"Found 2 non source trackable components in the org for the given types."
in messages
)


@mock.patch("cumulusci.tasks.salesforce.sourcetracking.sfdx")
Expand Down

0 comments on commit 1bebb37

Please sign in to comment.