Files
TimeTracker/tests/test_utils/test_version_compare.py
T
Dries Peeters 96955aee62 feat(admin): GitHub-based version update notification for admins
Add VersionService to fetch and cache the latest GitHub release, compare it to the installed semver (APP_VERSION when valid, else setup.py), and expose admin-only GET /api/version/check and POST /api/version/dismiss on the legacy /api blueprint (session or Bearer token).

Persist per-user dismissal in users.dismissed_release_version (Alembic 148) and show a non-blocking update card in base.html for administrators. Add packaging for semver parsing and tests for comparison, service, and routes.

Document configuration in docs/admin/deployment/VERSION_MANAGEMENT.md and endpoints in docs/api/REST_API.md and docs/API.md.
2026-04-15 09:39:32 +02:00

46 lines
1.1 KiB
Python

"""Tests for app.utils.version_compare."""
import pytest
from app.utils.version_compare import is_upgrade, normalize_version_tag
@pytest.mark.parametrize(
"raw,expected",
[
("v4.1.0", "4.1.0"),
(" 4.1.0 ", "4.1.0"),
("4.0.0-beta.1", "4.0.0b1"), # canonical form from packaging
(None, None),
("", None),
(" ", None),
("v", None),
("not-a-version", None),
],
)
def test_normalize_version_tag(raw, expected):
got = normalize_version_tag(raw)
if expected is None:
assert got is None
else:
assert got == expected
def test_normalize_version_tag_strips_v_only():
assert normalize_version_tag("v1.2.3") == "1.2.3"
@pytest.mark.parametrize(
"current,latest,expect",
[
("4.0.0", "4.1.0", True),
("4.0.0", "4.0.0", False),
("4.1.0", "4.0.0", False),
("4.0.0", None, False),
(None, "4.0.0", False),
("dev-1", "4.0.0", False),
],
)
def test_is_upgrade(current, latest, expect):
assert is_upgrade(current, latest) is expect