Files
outlookEmailPlus/tests/test_export_enhanced_v2.py
T
胡绍康andCopilot 973412d44c feat: 账号导入导出无缝迁移(PRD-00006/FD-00006)
- 新增 auto 智能混合导入模式:自动识别 Outlook/IMAP/GPTMail 行类型
- 域名推断 provider(gmail/qq/163/126/yahoo/aliyun/outlook)
- 自动按 provider 创建/复用分组
- 支持重复策略(skip/overwrite)和兜底 IMAP 设置
- 导出升级为 v2:头部元信息 + GPTMail 分段 + 时间戳文件名
- 前端导入模态框支持 auto 模式 UI 交互
- 新增 41 个单元测试(163 总测试全部通过)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-04 20:33:19 +08:00

138 lines
5.5 KiB
Python
Raw 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.
"""tests/test_export_enhanced_v2.py — FD-00006 导出 v2 增强测试"""
import unittest
from tests._import_app import clear_login_attempts, import_web_app_module
class TestExportEnhancedV2(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.module = import_web_app_module()
cls.app = cls.module.app
def setUp(self):
with self.app.app_context():
clear_login_attempts()
def test_build_export_text_v2_header(self):
"""导出文本包含 v2 头部元信息"""
with self.app.app_context():
from outlook_web.controllers.accounts import _build_export_text
accounts = [
{
"email": "test@outlook.com",
"password": "pwd",
"client_id": "cid",
"refresh_token": "rt",
"account_type": "outlook",
"provider": "outlook",
},
]
content = _build_export_text(accounts)
self.assertIn("# Outlook Email Plus — 账号导出", content)
self.assertIn("# 格式版本:v2", content)
self.assertIn("# 账号总数:1", content)
self.assertIn("Outlook:1", content)
def test_build_export_text_v2_outlook_section(self):
"""Outlook 分段格式不变"""
with self.app.app_context():
from outlook_web.controllers.accounts import _build_export_text
accounts = [
{
"email": "a@outlook.com",
"password": "p",
"client_id": "c",
"refresh_token": "r",
"account_type": "outlook",
"provider": "outlook",
},
]
content = _build_export_text(accounts)
self.assertIn("# === Outlook 账号 ===", content)
self.assertIn("a@outlook.com----p----c----r", content)
def test_build_export_text_v2_imap_section(self):
"""IMAP 分段格式正确"""
with self.app.app_context():
from outlook_web.controllers.accounts import _build_export_text
accounts = [
{
"email": "a@gmail.com",
"imap_password": "imap_pwd",
"account_type": "imap",
"provider": "gmail",
},
]
content = _build_export_text(accounts)
self.assertIn("# === IMAP 账号(Gmail)===", content)
self.assertIn("a@gmail.com----imap_pwd----gmail", content)
def test_build_export_text_v2_custom_5_segment(self):
"""Custom IMAP 输出 5 段"""
with self.app.app_context():
from outlook_web.controllers.accounts import _build_export_text
accounts = [
{
"email": "a@corp.com",
"imap_password": "pwd",
"account_type": "imap",
"provider": "custom",
"imap_host": "mail.corp.com",
"imap_port": 995,
},
]
content = _build_export_text(accounts)
self.assertIn("a@corp.com----pwd----custom----mail.corp.com----995", content)
def test_build_export_text_v2_gptmail_section(self):
"""GPTMail 分段仅邮箱地址"""
with self.app.app_context():
from outlook_web.controllers.accounts import _build_export_text
temp_emails = [{"email": "t1@gptmail.com"}, {"email": "t2@gptmail.com"}]
content = _build_export_text([], temp_emails)
self.assertIn("# === 临时邮箱(GPTMail)===", content)
self.assertIn("t1@gptmail.com", content)
self.assertIn("t2@gptmail.com", content)
# GPTMail 行不应包含 ----
for line in content.split("\n"):
if "@gptmail.com" in line and not line.startswith("#"):
self.assertNotIn("----", line)
def test_build_export_text_v2_mixed_counts(self):
"""混合账号统计正确"""
with self.app.app_context():
from outlook_web.controllers.accounts import _build_export_text
accounts = [
{"email": "a@o.com", "password": "p", "client_id": "c", "refresh_token": "r", "account_type": "outlook", "provider": "outlook"},
{"email": "b@o.com", "password": "p", "client_id": "c", "refresh_token": "r", "account_type": "outlook", "provider": "outlook"},
{"email": "c@gmail.com", "imap_password": "ip", "account_type": "imap", "provider": "gmail"},
]
temp_emails = [{"email": "t@gptmail.com"}]
content = _build_export_text(accounts, temp_emails)
self.assertIn("# 账号总数:4", content)
self.assertIn("Outlook:2", content)
self.assertIn("Gmail:1", content)
self.assertIn("临时邮箱:1", content)
def test_export_ends_with_newline(self):
"""导出文件末尾有换行"""
with self.app.app_context():
from outlook_web.controllers.accounts import _build_export_text
accounts = [
{"email": "a@o.com", "password": "p", "client_id": "c", "refresh_token": "r", "account_type": "outlook", "provider": "outlook"},
]
content = _build_export_text(accounts)
self.assertTrue(content.endswith("\n"))
if __name__ == "__main__":
unittest.main()