test_parser.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. import dingguo.parser
  4. import email
  5. import os
  6. project_root_path = os.path.realpath(os.path.join(__file__, '..', '..'))
  7. test_data_path = os.path.join(project_root_path, 'tests', 'data')
  8. @pytest.mark.parametrize('platform,mail_path', [
  9. ('amazon.de', os.path.join(test_data_path, 'amazon', 'mail_1.eml')),
  10. ('amazon.cn', os.path.join(test_data_path, 'amazon.cn', '1.eml')),
  11. ('banggood', os.path.join(test_data_path, 'banggood', '1.eml')),
  12. ('hm', os.path.join(test_data_path, 'hm', '1.eml')),
  13. ('ikea', os.path.join(test_data_path, 'ikea', '1.eml')),
  14. ('indiegogo', os.path.join(test_data_path, 'indiegogo', 'mail_without_reward.eml')),
  15. ('kickstarter', os.path.join(test_data_path, 'kickstarter', 'mail_orbitkey.eml')),
  16. ('lieferservice.at', os.path.join(test_data_path, 'lieferservice.at', 'mail_1.eml')),
  17. ('mytaxi', os.path.join(test_data_path, 'mytaxi', 'mail_1.eml')),
  18. ('namecheap', os.path.join(test_data_path, 'namecheap', 'mail_1_year_domain_renewal.eml')),
  19. ('oebb', os.path.join(test_data_path, 'oebb', 'mail_1.eml')),
  20. ('thomann', os.path.join(test_data_path, 'thomann', '1.eml')),
  21. ('uber', os.path.join(test_data_path, 'uber', 'mail_1.eml')),
  22. ('wiener_linien', os.path.join(test_data_path, 'wienerlinien', 'mail_single_ticket.eml')),
  23. ('yipbee', os.path.join(test_data_path, 'yipbee', 'mail_1.eml')),
  24. ])
  25. def test_parse_confirmation_mail_platform(platform, mail_path):
  26. with open(mail_path) as mail:
  27. parsed_orders = dingguo.parser.parse_order_confirmation_mail(
  28. email.message_from_file(mail)
  29. )
  30. for order in parsed_orders:
  31. assert order.platform == platform
  32. def test_parse_confirmation_mail_failure():
  33. mail = email.message_from_string('empty mail')
  34. with pytest.raises(Exception):
  35. dingguo.parser.parse_order_confirmation_mail(mail)