Files
any-auto-register/tests/test_chatgpt_plugin.py

42 lines
1.2 KiB
Python

import unittest
from unittest import mock
from core.base_mailbox import MailboxAccount
from core.base_platform import RegisterConfig
from platforms.chatgpt.plugin import ChatGPTPlatform
class _BlankMailbox:
def get_email(self):
return MailboxAccount(email="", account_id="blank-mailbox")
def wait_for_code(self, *args, **kwargs):
return "123456"
class _FakeAdapter:
def run(self, context):
context.email_service.create_email()
raise AssertionError("create_email 应该先报错")
class ChatGPTPluginTests(unittest.TestCase):
def test_custom_provider_rejects_blank_email(self):
platform = ChatGPTPlatform(
config=RegisterConfig(extra={"chatgpt_registration_mode": "refresh_token"}),
mailbox=_BlankMailbox(),
)
with mock.patch(
"platforms.chatgpt.plugin.build_chatgpt_registration_mode_adapter",
return_value=_FakeAdapter(),
):
with self.assertRaises(RuntimeError) as ctx:
platform.register()
self.assertIn("custom_provider 返回空邮箱地址", str(ctx.exception))
if __name__ == "__main__":
unittest.main()