# -*- 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')),
    ('amazon.cn', os.path.join(test_data_path, 'amazon.cn', '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')),
    ('indiegogo', os.path.join(test_data_path, 'indiegogo', 'mail_without_reward.eml')),
    ('kickstarter', os.path.join(test_data_path, 'kickstarter', 'mail_orbitkey.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')),
    ('namecheap', os.path.join(test_data_path, 'namecheap', 'mail_1_year_domain_renewal.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')),
    ('wiener_linien', os.path.join(test_data_path, 'wienerlinien', 'mail_single_ticket.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)