Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for url file scheme dependencies #3706

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ For example:
* Gustavo Tandeciarz (dcinzona)
* Chandler Anderson (zenibako)
* Ben French (BenjaminFrench)
* Mathieu Marcoux (mathieumarcoux)
48 changes: 48 additions & 0 deletions cumulusci/core/dependencies/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,44 @@ def test_install(self, api_deploy_mock, zip_builder_mock, download_mock):

api_deploy_mock.return_value.assert_called_once()

@mock.patch("cumulusci.core.dependencies.dependencies.download_extract_zip")
@mock.patch("cumulusci.core.dependencies.dependencies.MetadataPackageZipBuilder")
@mock.patch("cumulusci.core.dependencies.dependencies.ApiDeploy")
def test_zip_url_file_scheme(
self, api_deploy_mock, zip_builder_mock, download_mock
):
d = UnmanagedZipURLDependency(zip_url="file://foo.zip")

zf = ZipFile(io.BytesIO(), "w")
zf.writestr("src/package.xml", "test")
download_mock.return_value = zf

context = mock.Mock()
org = mock.Mock()
d.install(context, org)

download_mock.assert_called_once_with(d.zip_url)

zip_builder_mock.from_zipfile.assert_called_once_with(
mock.ANY,
options={
"unmanaged": True,
"namespace_inject": None,
"namespace_strip": None,
},
path=None,
context=mock.ANY,
)
api_deploy_mock.assert_called_once_with(
mock.ANY, # The context object is checked below
zip_builder_mock.from_zipfile.return_value.as_base64.return_value,
)
mock_task = api_deploy_mock.call_args_list[0][0][0]
assert mock_task.org_config == org
assert mock_task.project_config == context

api_deploy_mock.return_value.assert_called_once()

def test_get_unmanaged(self):
org = mock.Mock()
org.installed_packages = {"foo": "1.0"}
Expand All @@ -743,6 +781,12 @@ def test_get_unmanaged(self):
)._get_unmanaged(org)
is True
)
assert (
UnmanagedZipURLDependency(
zip_url="file://foo.zip", unmanaged=True
)._get_unmanaged(org)
is True
)
assert (
UnmanagedZipURLDependency(
zip_url="http://foo.com", namespace_inject="foo"
Expand All @@ -761,6 +805,10 @@ def test_name(self):
UnmanagedZipURLDependency(zip_url="http://foo.com", subfolder="bar").name
== "Deploy http://foo.com /bar"
)
assert (
UnmanagedZipURLDependency(zip_url="file://foo.zip").name
== "Deploy file://foo.zip "
)

@mock.patch("cumulusci.core.dependencies.dependencies.MetadataPackageZipBuilder")
@mock.patch("cumulusci.core.dependencies.dependencies.download_extract_zip")
Expand Down
7 changes: 5 additions & 2 deletions cumulusci/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ def remove_xml_element_directory(name, directory, file_pattern, logger=None):
def download_extract_zip(url, target=None, subfolder=None, headers=None):
if not headers:
headers = {}
resp = requests.get(url, headers=headers)
zip_content = io.BytesIO(resp.content)
if url.startswith("file://"):
zip_content = url[7:]
else:
resp = requests.get(url, headers=headers)
zip_content = io.BytesIO(resp.content)
zip_file = zipfile.ZipFile(zip_content)
if subfolder:
zip_file = zip_subfolder(zip_file, subfolder)
Expand Down