"""Tests for Persister.""" from unittest.mock import MagicMock from unittest.mock import Mock import sentry_sdk from sqlalchemy.exc import OperationalError from ows_product_physical.models import persister def test_create_history_success( db_with_data, valid_create_physical_product_change_history_fields_artwork): """Assert physical product change history table was written to.""" resp = persister.create_history( **valid_create_physical_product_change_history_fields_artwork) assert resp.status == 201 def test_create_history_fail( monkeypatch, db_with_data, invalid_create_physical_product_change_history_field_name): """Assert release fail exception was captured.""" monkeypatch.setattr( sentry_sdk, 'capture_exception', value=MagicMock()) session = Mock() session.flush = MagicMock(side_effect=OperationalError('', None, None)) resp = persister.create_history( **invalid_create_physical_product_change_history_field_name) assert resp.status == 500 assert sentry_sdk.capture_exception.called