iOSBuildServer/tests/test_project_patcher.py

55 lines
2.5 KiB
Python

"""服务端工程配置替换测试。"""
import plistlib
from backend.services.project_patcher import apply_project_config
def test_apply_project_config_without_branch_autopacking(tmp_path):
build_dir = tmp_path / "build"
project = build_dir / "readoor.xcodeproj"
swift = build_dir / "readoor" / "3.0" / "AppConfig"
resources = build_dir / "readoor" / "3.0" / "Resources"
assets = build_dir / "readoor" / "BookShelf" / "Resources" / "Images.xcassets"
logo = resources / "3.0.xcassets" / "AppLogo.imageset"
for path in [project, swift, resources, assets, logo]:
path.mkdir(parents=True, exist_ok=True)
(project / "project.pbxproj").write_text(
"MARKETING_VERSION = 1.0;\nCURRENT_PROJECT_VERSION = 1;\n"
"PRODUCT_BUNDLE_IDENTIFIER = old.id;\nDEVELOPMENT_TEAM = OLD;\n"
'"DEVELOPMENT_TEAM[sdk=iphoneos*]" = OLD;\n'
"PROVISIONING_PROFILE_SPECIFIER = old;\n"
'"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = old;\n',
encoding="utf-8",
)
(swift / "RDAppConfiguration.swift").write_text(
'let RD_APP_GUID: String = "old"\nlet RD_API_DOMAIN: String = "old"\n'
'let RD_WECHAT_PAY_ID: String = "old"\nlet RD_SOURCE_VERSION: String = "old"\n',
encoding="utf-8",
)
(build_dir / "readoor" / "3.0" / "readoor31.entitlements").write_text(
"<string>applinks:old</string>\n", encoding="utf-8"
)
with (build_dir / "readoor" / "3.0" / "readoor31.plist").open("wb") as f:
plistlib.dump({"CFBundleURLTypes": []}, f)
theme = tmp_path / "theme" / "AppIcon.appiconset"
theme.mkdir(parents=True)
(theme / "icon-1024.png").write_bytes(b"icon")
config = {
"VERSION": "2.0.0", "BUILD_VERSION": "2.0.0.1", "APPID": "guid",
"API": "https://api.example.com", "weixinpay": "wx-pay", "APPID_NAME": "Test",
"BUNDLE_ID": "com.example.test", "TEAM_ID": "TEAM", "PROVISIONING_NAME": "profile",
"ASSOCIATED_DOMAINS": "applinks:example.com", "THEME": str(theme.parent), "BUILD_TYPE": "Ad_Hoc",
"CERTIFICATE": "Apple Distribution",
}
messages = apply_project_config(build_dir, config)
assert "工程、签名、版本和分发配置已更新" in messages
assert 'let RD_APP_GUID: String = "guid"' in (swift / "RDAppConfiguration.swift").read_text()
assert "PRODUCT_BUNDLE_IDENTIFIER = com.example.test;" in (project / "project.pbxproj").read_text()
assert (build_dir / "exportOptions.plist").exists()
assert (logo / "icon-1024.png").read_bytes() == b"icon"