78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
"""服务端分发产物生成测试。"""
|
|
import plistlib
|
|
from unittest.mock import patch
|
|
|
|
from backend.services.distribution import (
|
|
_write_distribution_files,
|
|
_write_download_page,
|
|
_write_manifest,
|
|
publish_ipa,
|
|
)
|
|
|
|
|
|
def test_distribution_files_use_current_service_config(tmp_path):
|
|
ipa = tmp_path / "source.ipa"
|
|
ipa.write_bytes(b"ipa")
|
|
config = {
|
|
"APPID": "100", "VERSION": "2.0.0", "APPID_NAME": "Test App",
|
|
"BUNDLE_ID": "com.example.test",
|
|
}
|
|
ipa_file, manifest, html = _write_distribution_files(config, ipa, tmp_path / "distribution")
|
|
_write_manifest(config, manifest, "https://files.example.com/app.ipa")
|
|
_write_download_page(config, html, "https://files.example.com/app.plist")
|
|
|
|
with manifest.open("rb") as f:
|
|
plist = plistlib.load(f)
|
|
assert ipa_file.read_bytes() == b"ipa"
|
|
assert plist["items"][0]["metadata"]["bundle-identifier"] == "com.example.test"
|
|
assert "itms-services://" in html.read_text(encoding="utf-8")
|
|
|
|
|
|
def test_app_store_distribution_uploads_only_ipa(tmp_path):
|
|
ipa = tmp_path / "source.ipa"
|
|
ipa.write_bytes(b"app-store-ipa")
|
|
config = {
|
|
"APPID": "100",
|
|
"VERSION": "2.0.0",
|
|
"BUILD_TYPE": "App_Store",
|
|
"OSS_FLODER": "readoor",
|
|
"_upload_config": {"mode": "oss", "oss": {}},
|
|
}
|
|
|
|
with patch(
|
|
"backend.services.distribution._upload_oss",
|
|
return_value={".ipa": "https://files.example.com/readoor/iOS/100_2_0_0.ipa"},
|
|
) as upload:
|
|
download_url, qr_path = publish_ipa(config, ipa, tmp_path / "build")
|
|
|
|
uploaded_files = upload.call_args.args[1]
|
|
assert len(uploaded_files) == 1
|
|
assert uploaded_files[0][0].suffix == ".ipa"
|
|
assert download_url.endswith("100_2_0_0.ipa")
|
|
assert qr_path == ""
|
|
|
|
|
|
def test_adhoc_distribution_uploads_qrcode(tmp_path):
|
|
ipa = tmp_path / "source.ipa"
|
|
ipa.write_bytes(b"ad-hoc-ipa")
|
|
config = {
|
|
"APPID": "100",
|
|
"VERSION": "2.0.0",
|
|
"BUILD_TYPE": "Ad_Hoc",
|
|
"OSS_FLODER": "readoor",
|
|
"_upload_config": {"mode": "oss", "oss": {}},
|
|
}
|
|
|
|
def upload_files(_upload_config, files):
|
|
local_path, remote_path = files[0]
|
|
return {local_path.suffix: f"https://files.example.com/{remote_path}"}
|
|
|
|
with patch("backend.services.distribution._upload_oss", side_effect=upload_files) as upload:
|
|
download_url, qr_url = publish_ipa(config, ipa, tmp_path / "build")
|
|
|
|
assert download_url.endswith("100_2_0_0.html")
|
|
assert qr_url.endswith("100_2_0_0.png")
|
|
assert [call.args[1][0][0].suffix for call in upload.call_args_list] == [
|
|
".ipa", ".plist", ".html", ".png",
|
|
]
|