Skip to content

Commit

Permalink
Test HTTP Error
Browse files Browse the repository at this point in the history
  • Loading branch information
ClintonWB-EBSCO committed Oct 23, 2023
1 parent b478364 commit 2e2d9ec
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2e2d9ec

Please sign in to comment.