Skip to content

Commit

Permalink
Add one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed May 3, 2024
1 parent e193073 commit 14c3572
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions tests/manager/api/test_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.mock import patch
from unittest.mock import MagicMock, patch

from palace.manager.api.app import initialize_application
import pytest

from palace.manager.api.app import (
initialize_application,
initialize_circulation_manager,
)
from palace.manager.util.http import HTTP
from tests.fixtures.database import DatabaseTransactionFixture
from tests.fixtures.services import ServicesFixture
Expand All @@ -23,3 +28,30 @@ def test_initialize_application_http(

# Make sure that the HTTP configuration was set
mock_set_quick_failure_settings.assert_called_once()


def test_initialize_circulation_manager(caplog: pytest.LogCaptureFixture):
with (
patch("palace.manager.api.app.app") as mock_app,
patch("palace.manager.api.app.CirculationManager") as mock_circulation_manager,
patch("palace.manager.api.app.CachedData") as mock_cached_data,
):
# If app is already initialized, it should not be re-initialized
mock_app.manager = MagicMock()
initialize_circulation_manager()
mock_circulation_manager.assert_not_called()
mock_cached_data.initialize.assert_not_called()

# If app is not initialized, it should be initialized
mock_app.manager = None
initialize_circulation_manager()
mock_circulation_manager.assert_called_once()
mock_cached_data.initialize.assert_called_once()
assert mock_app.manager == mock_circulation_manager.return_value

# If an exception is raised, it should be logged
mock_app.manager = None
mock_circulation_manager.side_effect = Exception("Test exception")
with pytest.raises(Exception):
initialize_circulation_manager()
assert "Error instantiating circulation manager!" in caplog.text

0 comments on commit 14c3572

Please sign in to comment.