test_clone_integration.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. # coding=utf-8
  3. import shutil
  4. from pathlib import Path
  5. import pytest
  6. from click.testing import CliRunner
  7. from bdfr.__main__ import cli
  8. does_test_config_exist = Path('./tests/test_config.cfg').exists()
  9. def copy_test_config(run_path: Path):
  10. shutil.copy(Path('./tests/test_config.cfg'), Path(run_path, 'test_config.cfg'))
  11. def create_basic_args_for_cloner_runner(test_args: list[str], tmp_path: Path):
  12. copy_test_config(tmp_path)
  13. out = [
  14. 'clone',
  15. str(tmp_path),
  16. '-v',
  17. '--config', str(Path(tmp_path, 'test_config.cfg')),
  18. '--log', str(Path(tmp_path, 'test_log.txt')),
  19. ] + test_args
  20. return out
  21. @pytest.mark.online
  22. @pytest.mark.reddit
  23. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  24. @pytest.mark.parametrize('test_args', (
  25. ['-l', '6l7778'],
  26. ['-s', 'TrollXChromosomes/', '-L', 1],
  27. ['-l', 'eiajjw'],
  28. ['-l', 'xl0lhi'],
  29. ))
  30. def test_cli_scrape_general(test_args: list[str], tmp_path: Path):
  31. runner = CliRunner()
  32. test_args = create_basic_args_for_cloner_runner(test_args, tmp_path)
  33. result = runner.invoke(cli, test_args)
  34. assert result.exit_code == 0
  35. assert 'Downloaded submission' in result.output
  36. assert 'Record for entry item' in result.output