diff --git a/tests/integration_tests/test_archive_integration.py b/tests/integration_tests/test_archive_integration.py index f10f37c..1c0d30a 100644 --- a/tests/integration_tests/test_archive_integration.py +++ b/tests/integration_tests/test_archive_integration.py @@ -4,7 +4,9 @@ import re import shutil from pathlib import Path +from unittest.mock import MagicMock, patch +import prawcore import pytest from click.testing import CliRunner @@ -176,3 +178,30 @@ def test_cli_archive_soft_fail(test_args: list[str], tmp_path: Path): assert result.exit_code == 0 assert "failed to be archived due to a PRAW exception" in result.output assert "Attempting to archive" not in result.output + + +@pytest.mark.skipif(not does_test_config_exist, reason="A test config file is required for integration tests") +@pytest.mark.parametrize( + ("test_args", "response"), + ( + ( + ["--user", "nasa", "--submitted"], + 502, + ), + ( + ["--user", "nasa", "--submitted"], + 504, + ), + ), +) +def test_user_serv_fail(test_args: list[str], response: int, tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_archive_runner(test_args, tmp_path) + with patch("bdfr.connector.sleep", return_value=None): + with patch( + "bdfr.connector.RedditConnector.check_user_existence", + side_effect=prawcore.exceptions.ResponseException(MagicMock(status_code=response)), + ): + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert f"received {response} HTTP response" in result.output diff --git a/tests/integration_tests/test_clone_integration.py b/tests/integration_tests/test_clone_integration.py index e8dc008..eb64364 100644 --- a/tests/integration_tests/test_clone_integration.py +++ b/tests/integration_tests/test_clone_integration.py @@ -3,7 +3,9 @@ import shutil from pathlib import Path +from unittest.mock import MagicMock, patch +import prawcore import pytest from click.testing import CliRunner @@ -68,3 +70,30 @@ def test_cli_scrape_soft_fail(test_args: list[str], tmp_path: Path): assert result.exit_code == 0 assert "Downloaded submission" not in result.output assert "Record for entry item" not in result.output + + +@pytest.mark.skipif(not does_test_config_exist, reason="A test config file is required for integration tests") +@pytest.mark.parametrize( + ("test_args", "response"), + ( + ( + ["--user", "nasa", "--submitted"], + 502, + ), + ( + ["--user", "nasa", "--submitted"], + 504, + ), + ), +) +def test_user_serv_fail(test_args: list[str], response: int, tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_cloner_runner(test_args, tmp_path) + with patch("bdfr.connector.sleep", return_value=None): + with patch( + "bdfr.connector.RedditConnector.check_user_existence", + side_effect=prawcore.exceptions.ResponseException(MagicMock(status_code=response)), + ): + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert f"received {response} HTTP response" in result.output diff --git a/tests/integration_tests/test_download_integration.py b/tests/integration_tests/test_download_integration.py index 2ab38a0..e44c95e 100644 --- a/tests/integration_tests/test_download_integration.py +++ b/tests/integration_tests/test_download_integration.py @@ -3,7 +3,9 @@ import shutil from pathlib import Path +from unittest.mock import MagicMock, patch +import prawcore import pytest from click.testing import CliRunner @@ -396,3 +398,30 @@ def test_cli_download_score_filter(test_args: list[str], was_filtered: bool, tmp result = runner.invoke(cli, test_args) assert result.exit_code == 0 assert ("filtered due to score" in result.output) == was_filtered + + +@pytest.mark.skipif(not does_test_config_exist, reason="A test config file is required for integration tests") +@pytest.mark.parametrize( + ("test_args", "response"), + ( + ( + ["--user", "nasa", "--submitted"], + 502, + ), + ( + ["--user", "nasa", "--submitted"], + 504, + ), + ), +) +def test_user_serv_fail(test_args: list[str], response: int, tmp_path: Path): + runner = CliRunner() + test_args = create_basic_args_for_download_runner(test_args, tmp_path) + with patch("bdfr.connector.sleep", return_value=None): + with patch( + "bdfr.connector.RedditConnector.check_user_existence", + side_effect=prawcore.exceptions.ResponseException(MagicMock(status_code=response)), + ): + result = runner.invoke(cli, test_args) + assert result.exit_code == 0 + assert f"received {response} HTTP response" in result.output