hotmail_helper_test.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import importlib.util
  2. import pathlib
  3. import unittest
  4. from email.message import EmailMessage
  5. def load_hotmail_helper_module():
  6. module_path = pathlib.Path(__file__).resolve().parents[1] / "scripts" / "hotmail_helper.py"
  7. spec = importlib.util.spec_from_file_location("hotmail_helper", module_path)
  8. module = importlib.util.module_from_spec(spec)
  9. assert spec.loader is not None
  10. spec.loader.exec_module(module)
  11. return module
  12. hotmail_helper = load_hotmail_helper_module()
  13. class HotmailHelperMessageSelectionTest(unittest.TestCase):
  14. def test_select_latest_code_reads_code_from_full_body_when_preview_is_truncated(self):
  15. filler = "A" * 800
  16. verification_code = "731091"
  17. message = EmailMessage()
  18. message["Subject"] = "Your temporary ChatGPT login code"
  19. message["From"] = "noreply@tm.openai.com"
  20. message["To"] = "n20260420225606@a4sky.com"
  21. message["Date"] = "Tue, 21 Apr 2026 08:49:15 +0800"
  22. message.set_content(
  23. f"Your temporary ChatGPT login code\n{filler}\nEnter this temporary code to continue: {verification_code}\n"
  24. )
  25. normalized = hotmail_helper.normalize_message("1343", message.as_bytes(), "INBOX")
  26. selected = hotmail_helper.select_latest_code(
  27. [normalized],
  28. ["openai", "noreply", "chatgpt"],
  29. ["verify", "verification", "code", "login"],
  30. [],
  31. 0,
  32. "n20260420225606@a4sky.com",
  33. )
  34. self.assertEqual(selected["code"], verification_code)
  35. self.assertEqual(selected["message"]["id"], "1343")
  36. if __name__ == "__main__":
  37. unittest.main()