test_parser.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  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. ('lieferservice.at', os.path.join(test_data_path, 'lieferservice.at', 'mail_1.eml')),
  13. ('mytaxi', os.path.join(test_data_path, 'mytaxi', 'mail_1.eml')),
  14. ('oebb', os.path.join(test_data_path, 'oebb', 'mail_1.eml')),
  15. ('uber', os.path.join(test_data_path, 'uber', 'mail_1.eml')),
  16. ('yipbee', os.path.join(test_data_path, 'yipbee', 'mail_1.eml')),
  17. ])
  18. def test_parse_confirmation_mail_platform(platform, mail_path):
  19. with open(mail_path) as mail:
  20. parsed_orders = dingguo.parser.parse_order_confirmation_mail(
  21. email.message_from_file(mail)
  22. )
  23. for order in parsed_orders:
  24. assert order.platform == platform
  25. def test_parse_confirmation_mail_failure():
  26. mail = email.message_from_string('empty mail')
  27. with pytest.raises(Exception):
  28. dingguo.parser.parse_order_confirmation_mail(mail)