"""Test ows-abacus-event requests.""" from unittest import mock import httpx from owsclient import OwsClient from owsclient.test import OwsClientMock import pytest from src.connectors.exceptions import OwsEventException from src.connectors.ows_event import create_event from src.models import Event from tests.unit.factories import EventFactory def test_create_event_success(ows_client_mock: OwsClientMock) -> None: """Test successfully creating event.""" event: Event = EventFactory.build() ows_client_mock.post( 'ows-abacus-event', '/abacus-event/', json={ 'event_name': event.event_name, 'target_type': event.target_type, 'target_id': event.target_id, }, ).mock( return_value=httpx.Response( status_code=201, json=Event.model_dump(event), ) ) res = create_event(event.event_name, event.target_type, event.target_id) assert res == event def test_get_events_by_target_type_failure(ows_client_mock: OwsClientMock) -> None: """Test failure creating event.""" event = EventFactory.build() ows_client_mock.post( 'ows-abacus-event', '/abacus-event/', json={ 'event_name': event.event_name, 'target_type': event.target_type, 'target_id': event.target_id, }, ).mock( return_value=httpx.Response( 400, json={}, ) ) with pytest.raises(OwsEventException, match='ERROR in POST /abacus-event/'): create_event(event.event_name, event.target_type, event.target_id)