Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Jul 25, 2024
1 parent 28f24f8 commit 6badce8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
15 changes: 12 additions & 3 deletions fastapi_tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import requests
from converge import settings
from requests.exceptions import HTTPError

import apphelpers.sessions as sessionslib
from apphelpers.db.piccolo import destroy_db_from_basetable, setup_db_from_basetable
Expand Down Expand Up @@ -368,10 +369,18 @@ async def worst_endpoint(foo):
asyncio.run(wrapped_worst_endpoint(1))
assert mocked_honeybadger.notify.call_count == 2

mocked_honeybadger.notify.side_effect = requests.exceptions.HTTPError(
mocked_honeybadger.notify.side_effect = HTTPError(
response=mock.MagicMock(status_code=403)
)
with pytest.raises(RuntimeError) as e:
with pytest.raises(RuntimeError):
asyncio.run(wrapped_worst_endpoint(1))
assert "HttpError" in str(e)
# TODO: How to check nested exception?
assert mocked_honeybadger.notify.call_count == 3

mocked_honeybadger.notify.side_effect = HTTPError(
response=mock.MagicMock(status_code=401)
)
with pytest.raises(HTTPError):
asyncio.run(wrapped_worst_endpoint(1))
# TODO: How to check nested exception?
assert mocked_honeybadger.notify.call_count == 4
16 changes: 13 additions & 3 deletions tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pytest
import requests
from converge import settings
from exceptiongroup import ExceptionGroup
from requests.exceptions import HTTPError

import apphelpers.sessions as sessionslib
from apphelpers.errors.hug import BaseError
Expand Down Expand Up @@ -365,10 +367,18 @@ def worst_endpoint(foo):
wrapped_worst_endpoint(1)
assert mocked_honeybadger.notify.call_count == 2

mocked_honeybadger.notify.side_effect = requests.exceptions.HTTPError(
mocked_honeybadger.notify.side_effect = HTTPError(
response=mock.MagicMock(status_code=403)
)
with pytest.raises(RuntimeError) as e:
with pytest.raises(RuntimeError):
wrapped_worst_endpoint(1)
assert "HttpError" in str(e)
# TODO: How to check nested exception?
assert mocked_honeybadger.notify.call_count == 3

mocked_honeybadger.notify.side_effect = HTTPError(
response=mock.MagicMock(status_code=401)
)
with pytest.raises(HTTPError):
wrapped_worst_endpoint(1)
# TODO: How to check nested exception?
assert mocked_honeybadger.notify.call_count == 4

0 comments on commit 6badce8

Please sign in to comment.