Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/feature_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ jobs:
unit_tests:
name: "Unit tests: ${{ matrix.os }}-${{ matrix.python-version }}"
runs-on: ${{ matrix.os }}
# FIXME: Remove when https://github.com/lxml/lxml/pull/356 is released upstream
continue-on-error: ${{ matrix.os == 'sfdc-windows-latest' && matrix.python-version == '3.11' }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, sfdc-ubuntu-latest, sfdc-windows-latest]
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand Down
12 changes: 8 additions & 4 deletions cumulusci/cli/tests/test_cci.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import io
import os
import shutil
import sys
import tempfile
from pathlib import Path
from unittest import mock
Expand Down Expand Up @@ -262,13 +263,16 @@ def test_cci_org_default__no_orgname(
assert "There is no default org" in stdout.getvalue()


DEPLOY_CLASS_PATH = f"cumulusci.tasks.salesforce.Deploy{'.Deploy' if sys.version_info >= (3, 11) else ''}"


@mock.patch("cumulusci.cli.cci.init_logger", mock.Mock())
@mock.patch("cumulusci.cli.cci.tee_stdout_stderr", mock.MagicMock())
@mock.patch("cumulusci.tasks.salesforce.Deploy.__call__", mock.Mock())
@mock.patch(f"{DEPLOY_CLASS_PATH}.__call__", mock.Mock())
@mock.patch("sys.exit", mock.Mock())
@mock.patch("cumulusci.cli.cci.get_tempfile_logger")
@mock.patch("cumulusci.cli.cci.CliRuntime")
@mock.patch("cumulusci.tasks.salesforce.Deploy.__init__")
@mock.patch(f"{DEPLOY_CLASS_PATH}.__init__")
def test_cci_run_task_options__with_dash(
Deploy,
CliRuntime,
Expand Down Expand Up @@ -296,11 +300,11 @@ def test_cci_run_task_options__with_dash(

@mock.patch("cumulusci.cli.cci.init_logger", mock.Mock())
@mock.patch("cumulusci.cli.cci.tee_stdout_stderr", mock.MagicMock())
@mock.patch("cumulusci.tasks.salesforce.Deploy.__call__", mock.Mock())
@mock.patch(f"{DEPLOY_CLASS_PATH}.__call__", mock.Mock())
@mock.patch("sys.exit", mock.Mock())
@mock.patch("cumulusci.cli.cci.get_tempfile_logger")
@mock.patch("cumulusci.cli.cci.CliRuntime")
@mock.patch("cumulusci.tasks.salesforce.Deploy.__init__")
@mock.patch(f"{DEPLOY_CLASS_PATH}.__init__")
def test_cci_run_task_options__old_style_with_dash(
Deploy,
CliRuntime,
Expand Down
12 changes: 6 additions & 6 deletions cumulusci/core/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def test_suggested_name(self):


class TestOrgConfig:
@mock.patch("cumulusci.core.config.OrgConfig.OAuth2Client")
@mock.patch("cumulusci.core.config.org_config.OrgConfig.OAuth2Client")
def test_refresh_oauth_token(self, OAuth2Client):
config = OrgConfig(
{
Expand All @@ -877,7 +877,7 @@ def test_refresh_oauth_token(self, OAuth2Client):
assert client_config.client_id == DEFAULT_CONNECTED_APP.client_id
refresh_token.assert_called_once_with(mock.sentinel.refresh_token)

@mock.patch("cumulusci.core.config.OrgConfig.OAuth2Client")
@mock.patch("cumulusci.core.config.org_config.OrgConfig.OAuth2Client")
def test_refresh_oauth_token__other_connected_app(self, OAuth2Client):
config = OrgConfig(
{
Expand Down Expand Up @@ -1143,7 +1143,7 @@ def test_get_community_info__fetch_if_not_in_cache(self):
info = config.get_community_info("Kōkua")
assert info["name"] == "Kōkua"

@mock.patch("cumulusci.core.config.OrgConfig._fetch_community_info")
@mock.patch("cumulusci.core.config.org_config.OrgConfig._fetch_community_info")
def test_community_info_force_refresh(self, mock_fetch):
"""Verify that the force_refresh parameter has an effect"""
mock_fetch.return_value = {"Kōkua": {"name": "Kōkua"}}
Expand All @@ -1159,7 +1159,7 @@ def test_community_info_force_refresh(self, mock_fetch):
config.get_community_info("Kōkua", force_refresh=True)
mock_fetch.assert_called()

@mock.patch("cumulusci.core.config.OrgConfig._fetch_community_info")
@mock.patch("cumulusci.core.config.org_config.OrgConfig._fetch_community_info")
def test_community_info_exception(self, mock_fetch):
"""Verify an exception is thrown when the community doesn't exist"""
config = OrgConfig({}, "test")
Expand Down Expand Up @@ -1259,7 +1259,7 @@ def test_community_info_exception(self, mock_fetch):
SalesforceError(None, None, None, None),
]

@mock.patch("cumulusci.core.config.OrgConfig.salesforce_client")
@mock.patch("cumulusci.core.config.org_config.OrgConfig.salesforce_client")
def test_installed_packages(self, sf):
config = OrgConfig({}, "test")
sf.restful.side_effect = self.MOCK_TOOLING_PACKAGE_RESULTS
Expand Down Expand Up @@ -1300,7 +1300,7 @@ def test_installed_packages(self, sf):
assert config.installed_packages == expected
sf.restful.assert_called()

@mock.patch("cumulusci.core.config.OrgConfig.salesforce_client")
@mock.patch("cumulusci.core.config.org_config.OrgConfig.salesforce_client")
def test_has_minimum_package_version(self, sf):
config = OrgConfig({}, "test")
sf.restful.side_effect = self.MOCK_TOOLING_PACKAGE_RESULTS
Expand Down
20 changes: 15 additions & 5 deletions cumulusci/core/config/tests/test_config_expensive.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ def test_get_access_token(self, Command):
sfdx = mock.Mock(return_value=sfdx_response)

config = ScratchOrgConfig({}, "test")
with mock.patch("cumulusci.core.config.OrgConfig.salesforce_client", sf):
with mock.patch(
"cumulusci.core.config.org_config.OrgConfig.salesforce_client", sf
):
with mock.patch("cumulusci.core.config.sfdx_org_config.sfdx", sfdx):
access_token = config.get_access_token(alias="dadvisor")
sfdx.assert_called_once_with(
Expand All @@ -392,7 +394,9 @@ def test_get_access_token__unknown_user(self, Command):

config = ScratchOrgConfig({}, "test")

with mock.patch("cumulusci.core.config.OrgConfig.salesforce_client", sf):
with mock.patch(
"cumulusci.core.config.org_config.OrgConfig.salesforce_client", sf
):
with pytest.raises(
SfdxOrgException,
match="Couldn't find a username for the specified user",
Expand All @@ -410,7 +414,9 @@ def test_get_access_token__multiple_users(self, Command):

config = ScratchOrgConfig({}, "test")

with mock.patch("cumulusci.core.config.OrgConfig.salesforce_client", sf):
with mock.patch(
"cumulusci.core.config.org_config.OrgConfig.salesforce_client", sf
):
with pytest.raises(
SfdxOrgException,
match="More than one user matched the search critiera.",
Expand All @@ -426,7 +432,9 @@ def test_get_access_token__no_access_token(self, Command):
sfdx = mock.Mock(return_value=sfdx_response)

config = ScratchOrgConfig({}, "test")
with mock.patch("cumulusci.core.config.OrgConfig.salesforce_client", sf):
with mock.patch(
"cumulusci.core.config.org_config.OrgConfig.salesforce_client", sf
):
with mock.patch("cumulusci.core.config.sfdx_org_config.sfdx", sfdx):
exception = (
"Unable to find access token for whatever@example.com\nblah blah..."
Expand Down Expand Up @@ -463,7 +471,9 @@ def test_user_id_from_org(self, Command):
"instance_url": "test_instance",
"access_token": "token",
}
with mock.patch("cumulusci.core.config.OrgConfig.salesforce_client", sf):
with mock.patch(
"cumulusci.core.config.org_config.OrgConfig.salesforce_client", sf
):
assert config.user_id == "test"

def test_username_from_sfdx_info(self, Command):
Expand Down
6 changes: 3 additions & 3 deletions cumulusci/tasks/apex/tests/test_apex_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


@patch(
"cumulusci.tasks.salesforce.BaseSalesforceTask._update_credentials",
"cumulusci.core.tasks.BaseSalesforceTask._update_credentials",
MagicMock(return_value=None),
)
class TestRunApexTests(MockLoggerMixin):
Expand Down Expand Up @@ -757,7 +757,7 @@ def test_run_task__no_tests(self):


@patch(
"cumulusci.tasks.salesforce.BaseSalesforceTask._update_credentials",
"cumulusci.core.tasks.BaseSalesforceTask._update_credentials",
MagicMock(return_value=None),
)
class TestAnonymousApexTask:
Expand Down Expand Up @@ -934,7 +934,7 @@ def test_run_anonymous_apex__gack(self):


@patch(
"cumulusci.tasks.salesforce.BaseSalesforceTask._update_credentials",
"cumulusci.core.tasks.BaseSalesforceTask._update_credentials",
MagicMock(return_value=None),
)
class TestRunBatchApex(MockLoggerMixin):
Expand Down
8 changes: 6 additions & 2 deletions cumulusci/tasks/bulkdata/tests/test_upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ def test_upsert_rest__faked(
relevant_debug_statement = look_for_operation_creation_debug_statement(
task.logger.debug.mock_calls
)
assert relevant_debug_statement == DataApi.REST, relevant_debug_statement
assert relevant_debug_statement == format(
DataApi.REST
), relevant_debug_statement

def _mock_bulk(self, domain):
responses.add(
Expand Down Expand Up @@ -419,7 +421,9 @@ def test_upsert__fake_bulk(self, create_task, cumulusci_test_repo_root, org_conf
relevant_debug_statement = look_for_operation_creation_debug_statement(
task.logger.debug.mock_calls
)
assert relevant_debug_statement == DataApi.BULK, relevant_debug_statement
assert relevant_debug_statement in format(
DataApi.BULK
), relevant_debug_statement

def _test_two_upserts_and_check_results__complex(
self, api, create_task, cumulusci_test_repo_root, sf
Expand Down
4 changes: 1 addition & 3 deletions cumulusci/tasks/salesforce/tests/test_base_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def setup_method(self):
self.org_config = OrgConfig({}, "test", keychain=self.project_config.keychain)

def test_run_task(self):
with mock.patch(
"cumulusci.tasks.salesforce.BaseSalesforceTask._update_credentials"
):
with mock.patch("cumulusci.core.tasks.BaseSalesforceTask._update_credentials"):
task = BaseSalesforceTask(
self.project_config, self.task_config, self.org_config
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ def test_create_network_member_group__parent_not_found_in_query(self):

task.sf = Mock()

insert_response = Mock()
task.sf.NetworkMemberGroup.create = Mock(insert_response)
task.sf.NetworkMemberGroup.create = Mock()

# Execute the test.
with pytest.raises(CumulusCIException) as context:
Expand Down Expand Up @@ -278,9 +277,7 @@ def test_create_network_member_group__parent_already_exists(self):
task.sf = Mock()
task.sf.NetworkMemberGroup = Mock()

insert_response = Mock()
insert_response.get = Mock()
task.sf.NetworkMemberGroup.create = Mock(insert_response)
task.sf.NetworkMemberGroup.create = Mock()

# Execute the test.
task._create_network_member_group(sobject_type, parent_name, parent_id)
Expand Down
15 changes: 12 additions & 3 deletions cumulusci/tasks/salesforce/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from tempfile import TemporaryDirectory
from unittest import mock

from cumulusci.core.config import OrgConfig, TaskConfig
from cumulusci.core.config import TaskConfig
from cumulusci.core.config.org_config import OrgConfig
from cumulusci.tests.util import DummyKeychain, create_project_config


Expand All @@ -27,16 +28,24 @@ def create_task(task_class, options=None, project_config=None, org_config=None):
options = {}
task_config = TaskConfig({"options": options})
with mock.patch(
"cumulusci.tasks.salesforce.BaseSalesforceTask._get_client_name",
"cumulusci.core.tasks.BaseSalesforceTask._get_client_name",
return_value="ccitests",
):
return task_class(project_config, task_config, org_config)


def patch_dir(patch_path, file_path):
def return_file_path(*args, **kwargs):
"""
Python 3.11 removed pathlib._Accessor. This replaced a call to
os.getcwd() with Path.cwd() in Path.absolute(). This means we can have 0
or 1 arguments.
"""
return file_path

directory = Path(file_path)
directory.mkdir(parents=True, exist_ok=True)
patch = mock.patch(patch_path, lambda: file_path)
patch = mock.patch(patch_path, return_file_path)
patch.start()
return patch

Expand Down
2 changes: 1 addition & 1 deletion cumulusci/tasks/tests/test_salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@patch(
"cumulusci.tasks.salesforce.BaseSalesforceTask._update_credentials",
"cumulusci.core.tasks.BaseSalesforceTask._update_credentials",
MagicMock(return_value=None),
)
class TestSalesforceToolingTask:
Expand Down
2 changes: 1 addition & 1 deletion cumulusci/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def _init_task():
task.sf = salesforce_client

with mock.patch(
"cumulusci.core.config.OrgConfig.is_person_accounts_enabled",
"cumulusci.core.config.org_config.OrgConfig.is_person_accounts_enabled",
lambda: is_person_accounts_enabled,
), mock.patch.object(task, "_init_task", _init_task):
yield
Expand Down