"""Tests for ows-notifications model.""" from unittest.mock import MagicMock, patch import pytest from collaborator.constants import error, service_name from collaborator.models.ows import ows_notifications from collaborator.utils.error import OwsError @patch("collaborator.models.ows.ows_notifications.request") def test_trigger_closed_period_notification(mock_request): """Test triggering closed period notification.""" mock_response = MagicMock() mock_response.status_code = 200 mock_response.text = "" mock_request.post.return_value = mock_response active_collaborator_ids = [] statement_period = {} result = ows_notifications.trigger_closed_period_notifications( [ { "active_collaborator_ids": active_collaborator_ids, "statement_period": statement_period, } ] ) assert result == {} mock_request.post.assert_called_with( service_name.OWS_NOTIFICATIONS, "/collaborators/bulk-statement-period-closed-email", json={ "items": [ { "active_collaborator_ids": active_collaborator_ids, "statement_period": statement_period, } ] }, ) @patch("collaborator.models.ows.ows_notifications.request") def test_trigger_closed_period_notifications_fail(mock_request): """Test triggering closed period notification fails.""" mock_response = MagicMock() mock_response.status_code = 500 mock_response.json.return_value = dict( code=error.ERROR_CODE_OWS_NOTIFICATIONS, message="Some error" ) mock_request.post.return_value = mock_response with pytest.raises(OwsError) as err: ows_notifications.trigger_closed_period_notifications( [ { "active_collaborator_ids": [], "statement_period": {}, } ] ) assert err.value.code == error.ERROR_CODE_OWS_NOTIFICATIONS assert err.value.message == "Some error" assert err.value.status == 500