Files
yiyezhqiu-refactored/tests/update/test_models.py
T

52 lines
1.7 KiB
Python

import pytest
def _mapping(**overrides):
data = {
"product": "yiyezhqiu-refactored",
"version": "1.1.0",
"channel": "stable",
"min_supported_version": "1.0.0",
"package_url": "file:///release.zip",
"sha256": "a" * 64,
"release_notes": "模块迁移",
"published_at": "2026-09-11",
}
data.update(overrides)
return data
def test_manifest_parses_semver_and_rejects_wrong_product():
from dx_productivity.update.models import UpdateManifest
manifest = UpdateManifest.from_mapping(_mapping())
assert manifest.version.is_newer_than(manifest.min_supported_version)
assert manifest.is_compatible_with("1.0.0")
with pytest.raises(ValueError, match="product"):
UpdateManifest.from_mapping(_mapping(product="other-product"))
def test_semver_orders_prerelease_before_release():
from dx_productivity.update.models import SemVer
assert SemVer.parse("1.0.0-rc.1") < SemVer.parse("1.0.0")
assert SemVer.parse("1.0.0-rc.2") > SemVer.parse("1.0.0-rc.1")
@pytest.mark.parametrize("value", ["1", "1.0", "01.0.0", "v1.0.0", "1.0.0+"])
def test_semver_requires_strict_three_part_version(value):
from dx_productivity.update.models import SemVer
with pytest.raises(ValueError, match="version"):
SemVer.parse(value)
def test_manifest_rejects_invalid_digest_and_incompatible_current_version():
from dx_productivity.update.models import UpdateManifest
with pytest.raises(ValueError, match="sha256"):
UpdateManifest.from_mapping(_mapping(sha256="bad"))
manifest = UpdateManifest.from_mapping(_mapping(min_supported_version="2.0.0"))
assert manifest.is_compatible_with("1.0.0") is False