test_parser.py 1.4 KB

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