Skip to content

Commit

Permalink
Close all test zip files (#3494)
Browse files Browse the repository at this point in the history
Co-authored-by: James Estevez <[email protected]>
  • Loading branch information
Paul Prescod and jstvz authored Jan 20, 2023
1 parent e0fbbc5 commit f0a9703
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions cumulusci/salesforce_api/tests/test_package_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def test_builder(self, task_context):
"objects/CustomObject__c",
"objects/does-not-exist-in-schema/some.file",
}
zf.close()

def test_add_files_to_package(self, task_context):
with temporary_dir() as path:
Expand Down
1 change: 1 addition & 0 deletions cumulusci/tasks/salesforce/tests/test_CreatePackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ def test_get_package_zip(self):
zf = zipfile.ZipFile(io.BytesIO(base64.b64decode(package_zip)), "r")
package_xml = zf.read("package.xml")
assert b"<fullName>TestPackage</fullName>" in package_xml
zf.close()
4 changes: 4 additions & 0 deletions cumulusci/tasks/salesforce/tests/test_Deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_get_api(self):
api = task._get_api()
zf = zipfile.ZipFile(io.BytesIO(base64.b64decode(api.package_zip)), "r")
assert "package.xml" in zf.namelist()
zf.close()

def test_get_api__managed(self):
with temporary_dir() as path:
Expand All @@ -43,6 +44,7 @@ def test_get_api__managed(self):
api = task._get_api()
zf = zipfile.ZipFile(io.BytesIO(base64.b64decode(api.package_zip)), "r")
assert "package.xml" in zf.namelist()
zf.close()

def test_get_api__additional_options(self):
with temporary_dir() as path:
Expand Down Expand Up @@ -76,6 +78,7 @@ def test_get_api__skip_clean_meta_xml(self):
api = task._get_api()
zf = zipfile.ZipFile(io.BytesIO(base64.b64decode(api.package_zip)), "r")
assert "package.xml" in zf.namelist()
zf.close()

def test_get_api__static_resources(self):
with temporary_dir() as path:
Expand Down Expand Up @@ -115,6 +118,7 @@ def test_get_api__static_resources(self):
package_xml = zf.read("package.xml").decode()
assert "<name>StaticResource</name>" in package_xml
assert "<members>TestBundle</members>" in package_xml
zf.close()

def test_get_api__missing_path(self):
task = create_task(
Expand Down
1 change: 1 addition & 0 deletions cumulusci/tasks/salesforce/tests/test_RetrievePackaged.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ def test_run_task(self):
task.api_class = mock.Mock(return_value=mock.Mock(return_value=zf))
task()
assert os.path.exists(os.path.join(path, "testfile"))
zf.close()
1 change: 1 addition & 0 deletions cumulusci/tasks/salesforce/tests/test_UninstallPackaged.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_get_destructive_changes(self, ApiRetrievePackaged):
</Package>"""
== result
)
zf.close()

@responses.activate
def test_error_handling(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_get_destructive_changes(self):
</Package>"""
== result
)
zf.close()

def test_get_destructive_changes__no_package_xml(self):
project_config = create_project_config()
Expand Down
1 change: 1 addition & 0 deletions cumulusci/tasks/salesforce/tests/test_base_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_process_namespace(self):
zf = zipfile.ZipFile(io.BytesIO(), "w")
result = task._process_namespace(zf)
assert isinstance(result, zipfile.ZipFile)
zf.close()


class TestBaseUninstallMetadata:
Expand Down
4 changes: 4 additions & 0 deletions cumulusci/tasks/salesforce/tests/test_org_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_run_task__json_only(self):
</nestedList>
</OtherSettings>"""
)
zf.close()

def test_run_task__json_only__with_org_settings(self):
with temporary_dir() as d:
Expand Down Expand Up @@ -137,6 +138,7 @@ def test_run_task__json_only__with_org_settings(self):
<version>48.0</version>
</Package>"""
)
zf.close()

def test_run_task__settings_only(self):
settings = {
Expand Down Expand Up @@ -187,6 +189,7 @@ def test_run_task__settings_only(self):
</nested>
</OtherSettings>"""
)
zf.close()

def test_run_task__json_and_settings(self):
with temporary_dir() as d:
Expand Down Expand Up @@ -251,6 +254,7 @@ def test_run_task__json_and_settings(self):
</nested>
</OtherSettings>"""
)
zf.close()

def test_run_task__no_settings(self):
with temporary_dir() as d:
Expand Down
1 change: 1 addition & 0 deletions cumulusci/tasks/tests/test_create_package_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def test_run_task(
assert task.return_values["dependencies"] == [
{"version_id": "04t000000000009AAA"}
]
zf.close()

@responses.activate
def test_get_or_create_package__namespaced_existing(
Expand Down
4 changes: 4 additions & 0 deletions cumulusci/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ def process(name, content):
result = zf.read("test")
# assert contents were untouched
assert contents == result
zf.close()

def test_inject_namespace__managed(self):
logger = mock.Mock()
Expand Down Expand Up @@ -521,6 +522,7 @@ def test_zip_clean_metaxml(self):
result = zf.read("classes/test-meta.xml")
assert b"packageVersions" not in result
assert "other/test-meta.xml" in zf.namelist()
zf.close()

def test_zip_clean_metaxml__skips_binary(self):
logger = mock.Mock()
Expand All @@ -531,13 +533,15 @@ def test_zip_clean_metaxml__skips_binary(self):

zf = utils.zip_clean_metaxml(zf, logger=logger)
assert "classes/test-meta.xml" in zf.namelist()
zf.close()

def test_zip_clean_metaxml__handles_nonascii(self):
zf = zipfile.ZipFile(io.BytesIO(), "w")
zf.writestr("classes/test-meta.xml", b"<root>\xc3\xb1</root>")

zf = utils.zip_clean_metaxml(zf)
assert b"<root>\xc3\xb1</root>" == zf.read("classes/test-meta.xml")
zf.close()

def test_doc_task_not_inherited(self):
task_config = TaskConfig(
Expand Down

0 comments on commit f0a9703

Please sign in to comment.