|
| 1 | +import base64 |
1 | 2 | import io |
2 | 3 | import json |
3 | 4 | import os |
@@ -181,6 +182,22 @@ def test_validate_uninstall_script(self): |
181 | 182 | package_type=PackageTypeEnum.unlocked, uninstall_script="Uninstall" |
182 | 183 | ) # type: ignore |
183 | 184 |
|
| 185 | + def test_unpackaged_metadata_path__missing(self, project_config, org_config): |
| 186 | + with pytest.raises(TaskOptionsError, match="unpackaged_metadata_path"): |
| 187 | + CreatePackageVersion( |
| 188 | + project_config, |
| 189 | + TaskConfig( |
| 190 | + { |
| 191 | + "options": { |
| 192 | + "package_type": "Managed", |
| 193 | + "package_name": "Test Package", |
| 194 | + "unpackaged_metadata_path": "/nonexistent/path", |
| 195 | + } |
| 196 | + } |
| 197 | + ), |
| 198 | + org_config, |
| 199 | + ) |
| 200 | + |
184 | 201 |
|
185 | 202 | class TestCreatePackageVersion: |
186 | 203 | devhub_base_url = ( |
@@ -831,3 +848,88 @@ def test_prepare_cci_dependencies(self, task): |
831 | 848 | assert task._prepare_cci_dependencies( |
832 | 849 | {"ids": [{"subscriberPackageVersionId": "04t000000000000"}]} |
833 | 850 | ) == [{"version_id": "04t000000000000"}] |
| 851 | + |
| 852 | + @responses.activate |
| 853 | + def test_create_version_request__with_unpackaged_metadata(self, get_task, tmp_path): |
| 854 | + """unpackaged-metadata.zip and unpackagedMetadata descriptor key are included.""" |
| 855 | + unpackaged_path = tmp_path / "unpackaged_metadata" |
| 856 | + unpackaged_path.mkdir() |
| 857 | + (unpackaged_path / "package.xml").write_text( |
| 858 | + '<?xml version="1.0" encoding="utf-8"?>' |
| 859 | + '<Package xmlns="http://soap.sforce.com/2006/04/metadata"></Package>' |
| 860 | + ) |
| 861 | + |
| 862 | + task = get_task( |
| 863 | + { |
| 864 | + "package_type": "Managed", |
| 865 | + "package_name": "Test Package", |
| 866 | + "unpackaged_metadata_path": str(unpackaged_path), |
| 867 | + } |
| 868 | + ) |
| 869 | + |
| 870 | + responses.add( # query for existing Package2VersionCreateRequest |
| 871 | + "GET", |
| 872 | + f"{self.devhub_base_url}/tooling/query/", |
| 873 | + json={"size": 0, "records": []}, |
| 874 | + ) |
| 875 | + responses.add( # query for base version number |
| 876 | + "GET", |
| 877 | + f"{self.devhub_base_url}/tooling/query/", |
| 878 | + json={"size": 0, "records": []}, |
| 879 | + ) |
| 880 | + responses.add( # create Package2VersionCreateRequest |
| 881 | + "POST", |
| 882 | + f"{self.devhub_base_url}/tooling/sobjects/Package2VersionCreateRequest/", |
| 883 | + json={"id": "08c000000000001AAA"}, |
| 884 | + ) |
| 885 | + |
| 886 | + with mock.patch.object(task, "_get_dependencies", return_value=[]): |
| 887 | + result = task._create_version_request( |
| 888 | + "0Ho6g000000fy4ZCAQ", |
| 889 | + task.package_config, |
| 890 | + BasePackageZipBuilder(), |
| 891 | + ) |
| 892 | + assert result == "08c000000000001AAA" |
| 893 | + |
| 894 | + post_body = json.loads(responses.calls[-1].request.body) |
| 895 | + version_info_zip = zipfile.ZipFile( |
| 896 | + io.BytesIO(base64.b64decode(post_body["VersionInfo"])) |
| 897 | + ) |
| 898 | + assert "unpackaged-metadata.zip" in version_info_zip.namelist() |
| 899 | + descriptor = json.loads(version_info_zip.read("package2-descriptor.json")) |
| 900 | + assert descriptor["unpackagedMetadata"] == {"path": "unpackaged-metadata.zip"} |
| 901 | + |
| 902 | + @responses.activate |
| 903 | + def test_create_version_request__without_unpackaged_metadata(self, task): |
| 904 | + """unpackaged-metadata.zip is absent when the option is not set.""" |
| 905 | + responses.add( |
| 906 | + "GET", |
| 907 | + f"{self.devhub_base_url}/tooling/query/", |
| 908 | + json={"size": 0, "records": []}, |
| 909 | + ) |
| 910 | + responses.add( |
| 911 | + "GET", |
| 912 | + f"{self.devhub_base_url}/tooling/query/", |
| 913 | + json={"size": 0, "records": []}, |
| 914 | + ) |
| 915 | + responses.add( |
| 916 | + "POST", |
| 917 | + f"{self.devhub_base_url}/tooling/sobjects/Package2VersionCreateRequest/", |
| 918 | + json={"id": "08c000000000001AAA"}, |
| 919 | + ) |
| 920 | + |
| 921 | + with mock.patch.object(task, "_get_dependencies", return_value=[]): |
| 922 | + result = task._create_version_request( |
| 923 | + "0Ho6g000000fy4ZCAQ", |
| 924 | + task.package_config, |
| 925 | + BasePackageZipBuilder(), |
| 926 | + ) |
| 927 | + assert result == "08c000000000001AAA" |
| 928 | + |
| 929 | + post_body = json.loads(responses.calls[-1].request.body) |
| 930 | + version_info_zip = zipfile.ZipFile( |
| 931 | + io.BytesIO(base64.b64decode(post_body["VersionInfo"])) |
| 932 | + ) |
| 933 | + assert "unpackaged-metadata.zip" not in version_info_zip.namelist() |
| 934 | + descriptor = json.loads(version_info_zip.read("package2-descriptor.json")) |
| 935 | + assert "unpackagedMetadata" not in descriptor |
0 commit comments