diff --git a/tests/test_main.py b/tests/test_main.py index 7100d2b3..895d3d3e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -3,7 +3,7 @@ from unittest import mock import pytest from folio_migration_tools.custom_exceptions import TransformationProcessError -from httpx import HTTPError +import httpx def test_inheritance(): @@ -151,6 +151,25 @@ def test_task_name_arg_exception(insecure_inputs, secure_inputs): } +@mock.patch( + "sys.argv", + ["__main__.py", "tests/test_data/main/not_a_file.json", "task_name"], +) +@mock.patch.dict( + "os.environ", + { + "FOLIO_MIGRATION_TOOLS_OKAPI_PASSWORD": "okapi_password", + "FOLIO_MIGRATION_TOOLS_BASE_FOLDER_PATH": ".", + }, + clear=True, +) +def test_file_not_found(): + with pytest.raises(SystemExit) as exit_info: + __main__.main() + + assert exit_info.value.args[0] == "File not found" + + @mock.patch( "sys.argv", ["__main__.py", "tests/test_data/main/invalid_json.json", "task_name"], @@ -270,6 +289,13 @@ def thrower(): return thrower +from types import SimpleNamespace + + +class TestException(Exception): + request = SimpleNamespace(url="http://test.com") + + @mock.patch("folio_migration_tools.__main__.inheritors", lambda x: [MockTask]) @mock.patch.dict( "os.environ", @@ -332,8 +358,9 @@ def test_fail_unhandled(do_work, wrap_up): ) @mock.patch.object(MockTask, "do_work", wraps=MockTask.do_work) @mock.patch.object(MockTask, "wrap_up", wraps=MockTask.wrap_up) +@mock.patch("httpx.HTTPError", TestException) def test_fail_http(do_work, wrap_up): - do_work.side_effect = raise_exception_factory(HTTPError, "error_message", "error_data") + do_work.side_effect = raise_exception_factory(httpx.HTTPError, "message") with pytest.raises(SystemExit) as exit_info: __main__.main() assert exit_info.value.args[0] == "HTTP Not Connecting"