test_parser_banggood.py 826 B

123456789101112131415161718192021222324
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. import dingguo.parser.banggood
  4. import email
  5. import glob
  6. import os
  7. import test_yaml
  8. import yaml
  9. project_root_path = os.path.realpath(os.path.join(__file__, '..', '..'))
  10. test_data_path = os.path.join(project_root_path, 'tests', 'data', 'banggood')
  11. @pytest.mark.parametrize('mail_path', glob.glob(os.path.join(test_data_path, '*.eml')))
  12. def test_parse_confirmation_mail(mail_path):
  13. with open(mail_path) as mail:
  14. parsed_orders = dingguo.parser.banggood.parse_order_confirmation_mail(
  15. email.message_from_file(mail)
  16. )
  17. with open(mail_path.replace('.eml', '.yml')) as yaml_file:
  18. expected_orders = yaml.load(yaml_file.read())
  19. assert expected_orders == parsed_orders, \
  20. test_yaml.yaml_diff(expected_orders, parsed_orders)