test_integration.py 957 B

1234567891011121314151617181920
  1. import pytest
  2. import os
  3. import glob
  4. import yaml
  5. import subprocess
  6. project_root_path = os.path.realpath(os.path.join(__file__, '..', '..'))
  7. script_path = os.path.join(project_root_path, 'scripts', 'order-confirmation-mail-parser')
  8. test_data_path = os.path.join(project_root_path, 'tests', 'data')
  9. def test_integration():
  10. for mail_path in glob.glob(os.path.join(test_data_path, '*', 'mail_*.eml')):
  11. with open(mail_path, 'r') as mail_file:
  12. process = subprocess.Popen([script_path], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
  13. script_stdout, script_stderr = process.communicate(input = mail_file.read())
  14. result = yaml.load(script_stdout)
  15. with open(mail_path.replace('.eml', '.yml'), 'r') as expected_result_file:
  16. expected_result = yaml.load(expected_result_file.read())
  17. assert result == expected_result, 'unexpected result for ' + os.path.basename(mail_path)