Release v2.0.1: create Chrome shortcut in profile dir on add-web
All checks were successful
技能自动化发布 / release (push) Successful in 5s
All checks were successful
技能自动化发布 / release (push) Successful in 5s
This commit is contained in:
75
tests/test_profile_shortcut.py
Normal file
75
tests/test_profile_shortcut.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Profile 目录浏览器快捷方式测试。"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from util.profile_shortcut import _lnk_safe_filename, create_profile_browser_shortcut
|
||||
|
||||
|
||||
class TestLnkSafeFilename:
|
||||
def test_strips_forbidden_chars(self) -> None:
|
||||
assert _lnk_safe_filename('小红书/测试:账号') == "小红书_测试_账号"
|
||||
|
||||
def test_empty_uses_fallback(self) -> None:
|
||||
assert _lnk_safe_filename(" ") == "browser"
|
||||
|
||||
|
||||
class TestCreateProfileBrowserShortcut:
|
||||
def test_skips_non_windows(self, tmp_path, monkeypatch) -> None:
|
||||
monkeypatch.setattr("util.profile_shortcut.sys.platform", "linux")
|
||||
out = create_profile_browser_shortcut(str(tmp_path), "demo")
|
||||
assert out is None
|
||||
|
||||
def test_skips_when_no_browser(self, tmp_path, monkeypatch) -> None:
|
||||
monkeypatch.setattr("util.profile_shortcut.sys.platform", "win32")
|
||||
monkeypatch.setattr(
|
||||
"util.profile_shortcut.resolve_chromium_executable",
|
||||
lambda: None,
|
||||
)
|
||||
out = create_profile_browser_shortcut(str(tmp_path), "demo")
|
||||
assert out is None
|
||||
|
||||
@pytest.mark.skipif(sys.platform != "win32", reason="Windows .lnk only")
|
||||
def test_creates_lnk_on_windows(self, tmp_path, monkeypatch) -> None:
|
||||
from service.browser_service import resolve_chromium_executable
|
||||
|
||||
browser_exe = resolve_chromium_executable()
|
||||
if not browser_exe:
|
||||
pytest.skip("no Chrome/Edge installed")
|
||||
|
||||
label = "ShortcutTest"
|
||||
out = create_profile_browser_shortcut(str(tmp_path), label)
|
||||
assert out is not None
|
||||
assert os.path.isfile(out)
|
||||
assert out.endswith(f"{label}.lnk")
|
||||
|
||||
@pytest.mark.skipif(sys.platform != "win32", reason="Windows .lnk only")
|
||||
def test_add_web_creates_shortcut(self, clean_db, fake_env, monkeypatch) -> None:
|
||||
from service.browser_service import resolve_chromium_executable
|
||||
from service.account_service import cmd_account_add_web
|
||||
from db.accounts_repo import find_accounts
|
||||
|
||||
if not resolve_chromium_executable():
|
||||
pytest.skip("no Chrome/Edge installed")
|
||||
|
||||
label = "Maersk shortcut test"
|
||||
cmd_account_add_web(
|
||||
platform_input="maersk",
|
||||
login_id="shortcut@test.com",
|
||||
login_id_type="email",
|
||||
label=label,
|
||||
tenant_id="tenant-test",
|
||||
environment="production",
|
||||
role="booking",
|
||||
provider_code=None,
|
||||
url=None,
|
||||
extra_json_str=None,
|
||||
profile_dir_override=None,
|
||||
)
|
||||
accs = find_accounts(platform_key="maersk")
|
||||
assert len(accs) == 1
|
||||
profile_dir = accs[0]["profile_dir"]
|
||||
lnk_path = os.path.join(profile_dir, f"{label}.lnk")
|
||||
assert os.path.isfile(lnk_path), f"expected shortcut at {lnk_path}"
|
||||
Reference in New Issue
Block a user