| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import importlib.util
- import pathlib
- import unittest
- from email.message import EmailMessage
- def load_hotmail_helper_module():
- module_path = pathlib.Path(__file__).resolve().parents[1] / "scripts" / "hotmail_helper.py"
- spec = importlib.util.spec_from_file_location("hotmail_helper", module_path)
- module = importlib.util.module_from_spec(spec)
- assert spec.loader is not None
- spec.loader.exec_module(module)
- return module
- hotmail_helper = load_hotmail_helper_module()
- class HotmailHelperMessageSelectionTest(unittest.TestCase):
- def test_select_latest_code_reads_code_from_full_body_when_preview_is_truncated(self):
- filler = "A" * 800
- verification_code = "731091"
- message = EmailMessage()
- message["Subject"] = "Your temporary ChatGPT login code"
- message["From"] = "noreply@tm.openai.com"
- message["To"] = "n20260420225606@a4sky.com"
- message["Date"] = "Tue, 21 Apr 2026 08:49:15 +0800"
- message.set_content(
- f"Your temporary ChatGPT login code\n{filler}\nEnter this temporary code to continue: {verification_code}\n"
- )
- normalized = hotmail_helper.normalize_message("1343", message.as_bytes(), "INBOX")
- selected = hotmail_helper.select_latest_code(
- [normalized],
- ["openai", "noreply", "chatgpt"],
- ["verify", "verification", "code", "login"],
- [],
- 0,
- "n20260420225606@a4sky.com",
- )
- self.assertEqual(selected["code"], verification_code)
- self.assertEqual(selected["message"]["id"], "1343")
- if __name__ == "__main__":
- unittest.main()
|