test_parser.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. ('banggood', os.path.join(test_data_path, 'banggood', '1.eml')),
  11. ('hm', os.path.join(test_data_path, 'hm', '1.eml')),
  12. ('ikea', os.path.join(test_data_path, 'ikea', '1.eml')),
  13. ('kickstarter', os.path.join(test_data_path, 'kickstarter', 'mail_orbitkey.eml')),
  14. ('lieferservice.at', os.path.join(test_data_path, 'lieferservice.at', 'mail_1.eml')),
  15. ('mytaxi', os.path.join(test_data_path, 'mytaxi', 'mail_1.eml')),
  16. ('oebb', os.path.join(test_data_path, 'oebb', 'mail_1.eml')),
  17. ('thomann', os.path.join(test_data_path, 'thomann', '1.eml')),
  18. ('uber', os.path.join(test_data_path, 'uber', 'mail_1.eml')),
  19. ('wiener_linien', os.path.join(test_data_path, 'wienerlinien', 'mail_single_ticket.eml')),
  20. ('yipbee', os.path.join(test_data_path, 'yipbee', 'mail_1.eml')),
  21. ])
  22. def test_parse_confirmation_mail_platform(platform, mail_path):
  23. with open(mail_path) as mail:
  24. parsed_orders = dingguo.parser.parse_order_confirmation_mail(
  25. email.message_from_file(mail)
  26. )
  27. for order in parsed_orders:
  28. assert order.platform == platform
  29. def test_parse_confirmation_mail_failure():
  30. mail = email.message_from_string('empty mail')
  31. with pytest.raises(Exception):
  32. dingguo.parser.parse_order_confirmation_mail(mail)