feat: configure WebDAV artifact destination path

This commit is contained in:
shenlei
2026-10-08 15:28:48 +09:00
parent 5582aadc09
commit 9465c98859
7 changed files with 228 additions and 19 deletions
+81
View File
@@ -4,6 +4,7 @@ from unittest.mock import patch
from backend.services.distribution import (
_artifact_stem,
_upload_webdav,
delete_published_artifacts,
_write_distribution_files,
_write_download_page,
@@ -122,6 +123,86 @@ def test_delete_uses_saved_url_for_legacy_artifact_name():
]
def test_webdav_upload_uses_configured_directory_without_oss_path(tmp_path, monkeypatch):
ipa = tmp_path / "build.ipa"
ipa.write_bytes(b"ipa")
calls = {"mkcol": [], "put": []}
class FakeResponse:
status_code = 201
class FakeClient:
def __init__(self, **_kwargs): pass
def __enter__(self): return self
def __exit__(self, *_args): pass
def request(self, method, url):
calls["mkcol"].append((method, url))
return FakeResponse()
def put(self, url, content):
calls["put"].append((url, content))
return FakeResponse()
monkeypatch.setattr("backend.services.distribution.httpx.Client", FakeClient)
result = _upload_webdav(
{
"webdav": {
"server_url": "http://dav.example.com",
"username": "u",
"password": "p",
"base_path": "/iOS/",
"public_url": "https://download.example.com",
},
},
[(ipa, "ios-builds/iOS/legacy-path.ipa")],
)
assert calls["mkcol"] == [("MKCOL", "http://dav.example.com/iOS/")]
assert calls["put"] == [("http://dav.example.com/iOS/build.ipa", b"ipa")]
assert result[".ipa"] == "https://download.example.com/iOS/build.ipa"
def test_delete_webdav_artifacts_uses_path_from_published_url():
config = {
"APPID": "100", "VERSION": "2.0.0.0", "SOURCE_BRANCH": "main",
"BUILD_TYPE": "Ad_Hoc", "OSS_FLODER": "legacy-oss-folder",
}
upload = {
"mode": "webdav",
"webdav": {
"base_path": "/Android",
"public_url": "https://download.example.com",
},
}
with patch("backend.services.distribution._delete_webdav") as delete:
delete_published_artifacts(
config, upload,
"https://download.example.com/Android/build.html",
)
assert delete.call_args.args[1] == [
"Android/build.ipa",
"Android/build.plist",
"Android/build.html",
"Android/build.png",
]
def test_delete_webdav_dsym_uses_published_url():
config = {"APPID": "100", "VERSION": "2.0.0.0", "SOURCE_BRANCH": "main"}
upload = {
"mode": "webdav",
"webdav": {
"base_path": "/iOS",
"public_url": "https://download.example.com",
},
}
with patch("backend.services.distribution._delete_webdav") as delete:
from backend.services.distribution import delete_published_dsym
delete_published_dsym(config, upload, "https://download.example.com/iOS/build.dSYM.zip")
assert delete.call_args.args[1] == ["iOS/build.dSYM.zip"]
def test_oss_download_url_is_short_lived_and_uses_actual_object_key(monkeypatch):
class FakeBucket:
def __init__(self, *_args, **_kwargs): pass