1234567891011121314151617181920212223242526272829303132333435 |
- # -*- coding: utf-8 -*-
- import pytest
- import dingguo.parser
- import email
- import os
- project_root_path = os.path.realpath(os.path.join(__file__, '..', '..'))
- test_data_path = os.path.join(project_root_path, 'tests', 'data')
- @pytest.mark.parametrize('platform,mail_path', [
- ('amazon.de', os.path.join(test_data_path, 'amazon', 'mail_1.eml')),
- ('banggood', os.path.join(test_data_path, 'banggood', '1.eml')),
- ('hm', os.path.join(test_data_path, 'hm', '1.eml')),
- ('ikea', os.path.join(test_data_path, 'ikea', '1.eml')),
- ('lieferservice.at', os.path.join(test_data_path, 'lieferservice.at', 'mail_1.eml')),
- ('mytaxi', os.path.join(test_data_path, 'mytaxi', 'mail_1.eml')),
- ('oebb', os.path.join(test_data_path, 'oebb', 'mail_1.eml')),
- ('thomann', os.path.join(test_data_path, 'thomann', '1.eml')),
- ('uber', os.path.join(test_data_path, 'uber', 'mail_1.eml')),
- ('yipbee', os.path.join(test_data_path, 'yipbee', 'mail_1.eml')),
- ])
- def test_parse_confirmation_mail_platform(platform, mail_path):
- with open(mail_path) as mail:
- parsed_orders = dingguo.parser.parse_order_confirmation_mail(
- email.message_from_file(mail)
- )
- for order in parsed_orders:
- assert order.platform == platform
- def test_parse_confirmation_mail_failure():
- mail = email.message_from_string('empty mail')
- with pytest.raises(Exception):
- dingguo.parser.parse_order_confirmation_mail(mail)
|