Files
Anthias/tests/test_http.py
Viktor Petersson 87374fe2c3 feat(webview): append Anthias version to the User-Agent (#3102)
- Add an "Anthias/<version>" product token to QtWebEngine's default
  User-Agent so requests still read as Mozilla/Chrome/Safari while
  identifying the source screen and release
- Inject ANTHIAS_VERSION into the webview env from get_anthias_release(),
  falling back to "unknown" when unavailable

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 07:22:22 +01:00

31 lines
954 B
Python

from unittest import mock
from anthias_common.http import (
ANTHIAS_HOMEPAGE,
get_anthias_product_token,
get_user_agent,
)
def test_product_token_uses_release() -> None:
with mock.patch(
'anthias_common.http.get_anthias_release', return_value='2026.6.3'
):
assert get_anthias_product_token() == 'Anthias/2026.6.3'
def test_product_token_falls_back_to_unknown() -> None:
# get_anthias_release() returns '' when neither the installed package
# metadata nor the repo-root pyproject.toml can be read.
with mock.patch(
'anthias_common.http.get_anthias_release', return_value=''
):
assert get_anthias_product_token() == 'Anthias/unknown'
def test_user_agent_wraps_product_token_with_homepage() -> None:
with mock.patch(
'anthias_common.http.get_anthias_release', return_value='2026.6.3'
):
assert get_user_agent() == (f'Anthias/2026.6.3 (+{ANTHIAS_HOMEPAGE})')