Initial release with Gitea updater
This commit is contained in:
commit
46c2474985
36 files changed
+3674
No files matched your search
@@ -0,0 +1,67 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from syncvito.updater import GiteaUpdateService, UpdateFormatError, parse_version
|
||||
|
||||
|
||||
def _release(version: str, *, draft: bool = False, prerelease: bool = False) -> dict[str, object]:
|
||||
return {
|
||||
"tag_name": f"v{version}",
|
||||
"name": f"SyncVito {version}",
|
||||
"body": "Änderungen",
|
||||
"html_url": f"https://gitea.example/releases/v{version}",
|
||||
"draft": draft,
|
||||
"prerelease": prerelease,
|
||||
"assets": [
|
||||
{
|
||||
"name": "SyncVito.exe",
|
||||
"browser_download_url": "https://gitea.example/download/SyncVito.exe",
|
||||
"size": 1234,
|
||||
},
|
||||
{
|
||||
"name": "SyncVito.exe.sha256",
|
||||
"browser_download_url": "https://gitea.example/download/SyncVito.exe.sha256",
|
||||
"size": 80,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_parse_version_accepts_stable_tags() -> None:
|
||||
assert parse_version("v1.2.3") == (1, 2, 3)
|
||||
assert parse_version("10.20.30") == (10, 20, 30)
|
||||
|
||||
|
||||
def test_parse_version_rejects_prerelease() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
parse_version("1.2.3-beta")
|
||||
|
||||
|
||||
def test_check_selects_newest_stable_release(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
service = GiteaUpdateService("1.0.0", base_url="https://gitea.example", update_directory=tmp_path)
|
||||
releases = [_release("1.1.0"), _release("2.0.0", prerelease=True), _release("1.3.0")]
|
||||
monkeypatch.setattr(service, "_read_json", lambda _url: releases)
|
||||
|
||||
update = service.check()
|
||||
|
||||
assert update is not None
|
||||
assert update.version == "1.3.0"
|
||||
assert update.download_url.endswith("SyncVito.exe")
|
||||
|
||||
|
||||
def test_check_returns_none_for_current_version(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
service = GiteaUpdateService("1.3.0", base_url="https://gitea.example", update_directory=tmp_path)
|
||||
monkeypatch.setattr(service, "_read_json", lambda _url: [_release("1.3.0"), _release("1.2.0")])
|
||||
|
||||
assert service.check() is None
|
||||
|
||||
|
||||
def test_release_requires_checksum(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
service = GiteaUpdateService("1.0.0", base_url="https://gitea.example", update_directory=tmp_path)
|
||||
release = _release("1.1.0")
|
||||
release["assets"] = [release["assets"][0]] # type: ignore[index]
|
||||
monkeypatch.setattr(service, "_read_json", lambda _url: [release])
|
||||
|
||||
with pytest.raises(UpdateFormatError, match="Prüfsumme|SyncVito.exe.sha256"):
|
||||
service.check()
|
||||
Reference in new issue
Block a user