Files
account-manager/tests/test_account_delete.py
chendelian 7d0ec94210
All checks were successful
技能自动化发布 / release (push) Successful in 7s
feat: take over host delete so profile dirs are removed
2026-10-01 09:56:55 +08:00

55 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""delete id 会删库记录和硬盘 Profile,避免假删除残留登录态。"""
from __future__ import annotations
import os
from db.accounts_repo import find_accounts, get_account_by_id
def _add_web(**kwargs):
from service.account_service import cmd_account_add_web
defaults = dict(
platform_input="maersk",
login_id="demo@maersk.com",
login_id_type="email",
label="Maersk delete test",
tenant_id="tenant-demo",
environment="simulator",
role="booking",
provider_code=None,
url=None,
extra_json_str=None,
profile_dir_override=None,
)
defaults.update(kwargs)
cmd_account_add_web(**defaults)
def test_delete_by_id_removes_row_and_profile(clean_db, fake_env):
from service.account_service import cmd_delete_by_id
_add_web()
acc = find_accounts(platform_key="maersk")[0]
profile_dir = acc["profile_dir"]
marker = os.path.join(profile_dir, "Default", "Cookies")
os.makedirs(os.path.dirname(marker), exist_ok=True)
with open(marker, "w", encoding="utf-8") as handle:
handle.write("session")
assert os.path.isfile(marker)
cmd_delete_by_id(acc["id"])
assert get_account_by_id(acc["id"]) is None
assert find_accounts(platform_key="maersk") == []
assert not os.path.exists(profile_dir)
def test_delete_by_id_missing_account(clean_db, capsys):
from service.account_service import cmd_delete_by_id
cmd_delete_by_id(99999)
out = capsys.readouterr().out
assert "ERROR:ACCOUNT_NOT_FOUND" in out