This commit is contained in:
75
tests/test_reveal_profile.py
Normal file
75
tests/test_reveal_profile.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""account reveal-profile:打开 profile 目录(不启动浏览器)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def _insert_account(conn, *, profile_dir: str) -> int:
|
||||
from db.accounts_repo import insert_account
|
||||
from util.platforms import seed_platforms
|
||||
|
||||
seed_platforms(conn)
|
||||
aid = insert_account(
|
||||
conn,
|
||||
platform_key="sohu",
|
||||
account_label="reveal-test",
|
||||
login_id="13800000000",
|
||||
login_id_type="phone",
|
||||
tenant_id=None,
|
||||
environment="production",
|
||||
role="default",
|
||||
provider_code="sohu",
|
||||
profile_dir=profile_dir,
|
||||
url="https://mp.sohu.com",
|
||||
extra_json=None,
|
||||
now=1_700_000_000,
|
||||
auth_strategy="password_auto",
|
||||
session_persistent=1,
|
||||
device_fingerprint=None,
|
||||
)
|
||||
conn.commit()
|
||||
return aid
|
||||
|
||||
|
||||
def test_reveal_profile_opens_dir(clean_db, tmp_path, capsys):
|
||||
from service.browser_service import cmd_reveal_profile
|
||||
|
||||
profile = tmp_path / "profiles" / "sohu" / "reveal-test"
|
||||
aid = _insert_account(clean_db, profile_dir=str(profile))
|
||||
|
||||
with mock.patch("service.browser_service.os.startfile") as startfile:
|
||||
with mock.patch("service.browser_service.sys.platform", "win32"):
|
||||
cmd_reveal_profile(str(aid))
|
||||
|
||||
startfile.assert_called_once()
|
||||
called_path = startfile.call_args[0][0]
|
||||
assert os.path.isdir(called_path)
|
||||
assert os.path.abspath(str(profile)) == called_path
|
||||
|
||||
out = capsys.readouterr().out.strip()
|
||||
payload = json.loads(out.splitlines()[-1])
|
||||
assert payload["success"] is True
|
||||
assert payload["data"]["account_id"] == aid
|
||||
assert payload["data"]["profile_dir"] == called_path
|
||||
|
||||
|
||||
def test_reveal_profile_missing_account(clean_db):
|
||||
from service.browser_service import cmd_reveal_profile
|
||||
|
||||
with pytest.raises(SystemExit) as ei:
|
||||
cmd_reveal_profile("999999")
|
||||
assert ei.value.code == 1
|
||||
|
||||
|
||||
def test_reveal_profile_empty_dir(clean_db):
|
||||
from service.browser_service import cmd_reveal_profile
|
||||
|
||||
aid = _insert_account(clean_db, profile_dir="")
|
||||
with pytest.raises(SystemExit) as ei:
|
||||
cmd_reveal_profile(str(aid))
|
||||
assert ei.value.code == 1
|
||||
@@ -32,6 +32,7 @@ def test_usage_includes_all_account_subcommands():
|
||||
"get-credential",
|
||||
"pick-web",
|
||||
"resolve",
|
||||
"reveal-profile",
|
||||
):
|
||||
assert cmd in usage, f"USAGE 缺少 {cmd}"
|
||||
assert "--ensure" in usage
|
||||
|
||||
Reference in New Issue
Block a user