test_archive_integration.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env python3
  2. # coding=utf-8
  3. import re
  4. import shutil
  5. from pathlib import Path
  6. import pytest
  7. from click.testing import CliRunner
  8. from bdfr.__main__ import cli
  9. does_test_config_exist = Path('./tests/test_config.cfg').exists()
  10. def copy_test_config(run_path: Path):
  11. shutil.copy(Path('./tests/test_config.cfg'), Path(run_path, 'test_config.cfg'))
  12. def create_basic_args_for_archive_runner(test_args: list[str], run_path: Path):
  13. copy_test_config(run_path)
  14. out = [
  15. 'archive',
  16. str(run_path),
  17. '-v',
  18. '--config', str(Path(run_path, 'test_config.cfg')),
  19. '--log', str(Path(run_path, 'test_log.txt')),
  20. ] + test_args
  21. return out
  22. @pytest.mark.online
  23. @pytest.mark.reddit
  24. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  25. @pytest.mark.parametrize('test_args', (
  26. ['-l', 'gstd4hk'],
  27. ['-l', 'm2601g', '-f', 'yaml'],
  28. ['-l', 'n60t4c', '-f', 'xml'],
  29. ))
  30. def test_cli_archive_single(test_args: list[str], tmp_path: Path):
  31. runner = CliRunner()
  32. test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
  33. result = runner.invoke(cli, test_args)
  34. assert result.exit_code == 0
  35. assert re.search(r'Writing entry .*? to file in .*? format', result.output)
  36. @pytest.mark.online
  37. @pytest.mark.reddit
  38. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  39. @pytest.mark.parametrize('test_args', (
  40. ['--subreddit', 'Mindustry', '-L', 25],
  41. ['--subreddit', 'Mindustry', '-L', 25, '--format', 'xml'],
  42. ['--subreddit', 'Mindustry', '-L', 25, '--format', 'yaml'],
  43. ['--subreddit', 'Mindustry', '-L', 25, '--sort', 'new'],
  44. ['--subreddit', 'Mindustry', '-L', 25, '--time', 'day'],
  45. ['--subreddit', 'Mindustry', '-L', 25, '--time', 'day', '--sort', 'new'],
  46. ))
  47. def test_cli_archive_subreddit(test_args: list[str], tmp_path: Path):
  48. runner = CliRunner()
  49. test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
  50. result = runner.invoke(cli, test_args)
  51. assert result.exit_code == 0
  52. assert re.search(r'Writing entry .*? to file in .*? format', result.output)
  53. @pytest.mark.online
  54. @pytest.mark.reddit
  55. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  56. @pytest.mark.parametrize('test_args', (
  57. ['--user', 'me', '--authenticate', '--all-comments', '-L', '10'],
  58. ['--user', 'me', '--user', 'djnish', '--authenticate', '--all-comments', '-L', '10'],
  59. ))
  60. def test_cli_archive_all_user_comments(test_args: list[str], tmp_path: Path):
  61. runner = CliRunner()
  62. test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
  63. result = runner.invoke(cli, test_args)
  64. assert result.exit_code == 0
  65. @pytest.mark.online
  66. @pytest.mark.reddit
  67. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  68. @pytest.mark.parametrize('test_args', (
  69. ['--comment-context', '--link', 'gxqapql'],
  70. ))
  71. def test_cli_archive_full_context(test_args: list[str], tmp_path: Path):
  72. runner = CliRunner()
  73. test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
  74. result = runner.invoke(cli, test_args)
  75. assert result.exit_code == 0
  76. assert 'Converting comment' in result.output
  77. @pytest.mark.online
  78. @pytest.mark.reddit
  79. @pytest.mark.slow
  80. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  81. @pytest.mark.parametrize('test_args', (
  82. ['--subreddit', 'all', '-L', 100],
  83. ['--subreddit', 'all', '-L', 100, '--sort', 'new'],
  84. ))
  85. def test_cli_archive_long(test_args: list[str], tmp_path: Path):
  86. runner = CliRunner()
  87. test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
  88. result = runner.invoke(cli, test_args)
  89. assert result.exit_code == 0
  90. assert re.search(r'Writing entry .*? to file in .*? format', result.output)
  91. @pytest.mark.online
  92. @pytest.mark.reddit
  93. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  94. @pytest.mark.parametrize('test_args', (
  95. ['--ignore-user', 'ArjanEgges', '-l', 'm3hxzd'],
  96. ))
  97. def test_cli_archive_ignore_user(test_args: list[str], tmp_path: Path):
  98. runner = CliRunner()
  99. test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
  100. result = runner.invoke(cli, test_args)
  101. assert result.exit_code == 0
  102. assert 'being an ignored user' in result.output
  103. assert 'Attempting to archive submission' not in result.output
  104. @pytest.mark.online
  105. @pytest.mark.reddit
  106. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  107. @pytest.mark.parametrize('test_args', (
  108. ['--file-scheme', '{TITLE}', '-l', 'suy011'],
  109. ))
  110. def test_cli_archive_file_format(test_args: list[str], tmp_path: Path):
  111. runner = CliRunner()
  112. test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
  113. result = runner.invoke(cli, test_args)
  114. assert result.exit_code == 0
  115. assert 'Attempting to archive submission' in result.output
  116. assert re.search('format at /.+?/Judge says Trump and two adult', result.output)
  117. @pytest.mark.online
  118. @pytest.mark.reddit
  119. @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
  120. @pytest.mark.parametrize('test_args', (
  121. ['-l', 'm2601g', '--exclude-id', 'm2601g'],
  122. ))
  123. def test_cli_archive_links_exclusion(test_args: list[str], tmp_path: Path):
  124. runner = CliRunner()
  125. test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
  126. result = runner.invoke(cli, test_args)
  127. assert result.exit_code == 0
  128. assert 'in exclusion list' in result.output
  129. assert 'Attempting to archive' not in result.output