diff --git a/tests/integration_tests/__init__.py b/tests/integration_tests/__init__.py new file mode 100644 index 0000000..d4c1799 --- /dev/null +++ b/tests/integration_tests/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python3 +# coding=utf-8 diff --git a/tests/integration_tests/test_archive_integration.py b/tests/integration_tests/test_archive_integration.py new file mode 100644 index 0000000..8cbb2d5 --- /dev/null +++ b/tests/integration_tests/test_archive_integration.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python3 +# coding=utf-8 + +import re +import shutil +from pathlib import Path + +import pytest +from click.testing import CliRunner + +from bdfr.__main__ import cli + +does_test_config_exist = Path('../test_config.cfg').exists() + + +def copy_test_config(run_path: Path): + shutil.copy(Path('../test_config.cfg'), Path(run_path, '../test_config.cfg')) + + +def create_basic_args_for_archive_runner(test_args: list[str], run_path: Path): + copy_test_config(run_path) + out = [ + 'archive', + str(run_path), + '-v', + '--config', str(Path(run_path, '../test_config.cfg')), + '--log', str(Path(run_path, 'test_log.txt')), + ] + test_args + return out + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['-l', 'gstd4hk'], + ['-l', 'm2601g', '-f', 'yaml'], + ['-l', 'n60t4c', '-f', 'xml'], +)) +def test_cli_archive_single(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_archive_runner(test_args, tmp_path) + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert re.search(r'Writing entry .*? to file in .*? format', result.output) + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['--subreddit', 'Mindustry', '-L', 25], + ['--subreddit', 'Mindustry', '-L', 25, '--format', 'xml'], + ['--subreddit', 'Mindustry', '-L', 25, '--format', 'yaml'], + ['--subreddit', 'Mindustry', '-L', 25, '--sort', 'new'], + ['--subreddit', 'Mindustry', '-L', 25, '--time', 'day'], + ['--subreddit', 'Mindustry', '-L', 25, '--time', 'day', '--sort', 'new'], +)) +def test_cli_archive_subreddit(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_archive_runner(test_args, tmp_path) + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert re.search(r'Writing entry .*? to file in .*? format', result.output) + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['--user', 'me', '--authenticate', '--all-comments', '-L', '10'], + ['--user', 'me', '--user', 'djnish', '--authenticate', '--all-comments', '-L', '10'], +)) +def test_cli_archive_all_user_comments(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_archive_runner(test_args, tmp_path) + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['--comment-context', '--link', 'gxqapql'], +)) +def test_cli_archive_full_context(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_archive_runner(test_args, tmp_path) + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert 'Converting comment' in result.output + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.slow +@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['--subreddit', 'all', '-L', 100], + ['--subreddit', 'all', '-L', 100, '--sort', 'new'], +)) +def test_cli_archive_long(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_archive_runner(test_args, tmp_path) + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert re.search(r'Writing entry .*? to file in .*? format', result.output) diff --git a/tests/integration_tests/test_clone_integration.py b/tests/integration_tests/test_clone_integration.py new file mode 100644 index 0000000..84892fc --- /dev/null +++ b/tests/integration_tests/test_clone_integration.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# coding=utf-8 + +import re +import shutil +from pathlib import Path + +import pytest +from click.testing import CliRunner + +from bdfr.__main__ import cli + +does_test_config_exist = Path('../test_config.cfg').exists() + + +def copy_test_config(run_path: Path): + shutil.copy(Path('../test_config.cfg'), Path(run_path, '../test_config.cfg')) + + +def create_basic_args_for_cloner_runner(test_args: list[str], tmp_path: Path): + out = [ + 'clone', + str(tmp_path), + '-v', + '--config', 'test_config.cfg', + '--log', str(Path(tmp_path, 'test_log.txt')), + ] + test_args + return out + + +@pytest.mark.online +@pytest.mark.reddit +@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') +@pytest.mark.parametrize('test_args', ( + ['-l', 'm2601g'], + ['-s', 'TrollXChromosomes/', '-L', 1], +)) +def test_cli_scrape_general(test_args: list[str], tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_cloner_runner(test_args, tmp_path) + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert 'Downloaded submission' in result.output + assert 'Record for entry item' in result.output diff --git a/tests/test_integration.py b/tests/integration_tests/test_download_integration.py similarity index 71% rename from tests/test_integration.py rename to tests/integration_tests/test_download_integration.py index 5f1dfea..fca0f8b 100644 --- a/tests/test_integration.py +++ b/tests/integration_tests/test_download_integration.py @@ -10,11 +10,11 @@ from click.testing import CliRunner from bdfr.__main__ import cli -does_test_config_exist = Path('test_config.cfg').exists() +does_test_config_exist = Path('../test_config.cfg').exists() def copy_test_config(run_path: Path): - shutil.copy(Path('test_config.cfg'), Path(run_path, 'test_config.cfg')) + shutil.copy(Path('../test_config.cfg'), Path(run_path, '../test_config.cfg')) def create_basic_args_for_download_runner(test_args: list[str], run_path: Path): @@ -22,35 +22,12 @@ def create_basic_args_for_download_runner(test_args: list[str], run_path: Path): out = [ 'download', str(run_path), '-v', - '--config', str(Path(run_path, 'test_config.cfg')), + '--config', str(Path(run_path, '../test_config.cfg')), '--log', str(Path(run_path, 'test_log.txt')), ] + test_args return out -def create_basic_args_for_archive_runner(test_args: list[str], run_path: Path): - copy_test_config(run_path) - out = [ - 'archive', - str(run_path), - '-v', - '--config', str(Path(run_path, 'test_config.cfg')), - '--log', str(Path(run_path, 'test_log.txt')), - ] + test_args - return out - - -def create_basic_args_for_cloner_runner(test_args: list[str], tmp_path: Path): - out = [ - 'clone', - str(tmp_path), - '-v', - '--config', 'test_config.cfg', - '--log', str(Path(tmp_path, 'test_log.txt')), - ] + test_args - return out - - @pytest.mark.online @pytest.mark.reddit @pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') @@ -211,85 +188,6 @@ def test_cli_download_long(test_args: list[str], tmp_path: Path): assert result.exit_code == 0 -@pytest.mark.online -@pytest.mark.reddit -@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') -@pytest.mark.parametrize('test_args', ( - ['-l', 'gstd4hk'], - ['-l', 'm2601g', '-f', 'yaml'], - ['-l', 'n60t4c', '-f', 'xml'], -)) -def test_cli_archive_single(test_args: list[str], tmp_path: Path): - runner = CliRunner() - test_args = create_basic_args_for_archive_runner(test_args, tmp_path) - result = runner.invoke(cli, test_args) - assert result.exit_code == 0 - assert re.search(r'Writing entry .*? to file in .*? format', result.output) - - -@pytest.mark.online -@pytest.mark.reddit -@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') -@pytest.mark.parametrize('test_args', ( - ['--subreddit', 'Mindustry', '-L', 25], - ['--subreddit', 'Mindustry', '-L', 25, '--format', 'xml'], - ['--subreddit', 'Mindustry', '-L', 25, '--format', 'yaml'], - ['--subreddit', 'Mindustry', '-L', 25, '--sort', 'new'], - ['--subreddit', 'Mindustry', '-L', 25, '--time', 'day'], - ['--subreddit', 'Mindustry', '-L', 25, '--time', 'day', '--sort', 'new'], -)) -def test_cli_archive_subreddit(test_args: list[str], tmp_path: Path): - runner = CliRunner() - test_args = create_basic_args_for_archive_runner(test_args, tmp_path) - result = runner.invoke(cli, test_args) - assert result.exit_code == 0 - assert re.search(r'Writing entry .*? to file in .*? format', result.output) - - -@pytest.mark.online -@pytest.mark.reddit -@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') -@pytest.mark.parametrize('test_args', ( - ['--user', 'me', '--authenticate', '--all-comments', '-L', '10'], - ['--user', 'me', '--user', 'djnish', '--authenticate', '--all-comments', '-L', '10'], -)) -def test_cli_archive_all_user_comments(test_args: list[str], tmp_path: Path): - runner = CliRunner() - test_args = create_basic_args_for_archive_runner(test_args, tmp_path) - result = runner.invoke(cli, test_args) - assert result.exit_code == 0 - - -@pytest.mark.online -@pytest.mark.reddit -@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') -@pytest.mark.parametrize('test_args', ( - ['--comment-context', '--link', 'gxqapql'], -)) -def test_cli_archive_full_context(test_args: list[str], tmp_path: Path): - runner = CliRunner() - test_args = create_basic_args_for_archive_runner(test_args, tmp_path) - result = runner.invoke(cli, test_args) - assert result.exit_code == 0 - assert 'Converting comment' in result.output - - -@pytest.mark.online -@pytest.mark.reddit -@pytest.mark.slow -@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') -@pytest.mark.parametrize('test_args', ( - ['--subreddit', 'all', '-L', 100], - ['--subreddit', 'all', '-L', 100, '--sort', 'new'], -)) -def test_cli_archive_long(test_args: list[str], tmp_path: Path): - runner = CliRunner() - test_args = create_basic_args_for_archive_runner(test_args, tmp_path) - result = runner.invoke(cli, test_args) - assert result.exit_code == 0 - assert re.search(r'Writing entry .*? to file in .*? format', result.output) - - @pytest.mark.online @pytest.mark.reddit @pytest.mark.slow @@ -393,19 +291,3 @@ def test_cli_download_disable_modules(test_args: list[str], tmp_path: Path): assert result.exit_code == 0 assert 'skipped due to disabled module' in result.output assert 'Downloaded submission' not in result.output - - -@pytest.mark.online -@pytest.mark.reddit -@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests') -@pytest.mark.parametrize('test_args', ( - ['-l', 'm2601g'], - ['-s', 'TrollXChromosomes/', '-L', 1], -)) -def test_cli_scrape_general(test_args: list[str], tmp_path: Path): - runner = CliRunner() - test_args = create_basic_args_for_cloner_runner(test_args, tmp_path) - result = runner.invoke(cli, test_args) - assert result.exit_code == 0 - assert 'Downloaded submission' in result.output - assert 'Record for entry item' in result.output