"""Tests for payment_hold_history model.""" from datetime import date, timedelta from abacus_account.models.payment_hold_history import PaymentHoldHistory from tests.utils.factories import PaymentHoldFactory, PaymentHoldHistoryFactory def test_get_payment_hold_history_by_id(): """Test to get a payment hold history by id.""" object_id = 1 assert len(PaymentHoldHistory.query.all()) == 0 payment_hold_history = PaymentHoldHistoryFactory.create( payment_hold_history_id=object_id ) assert len(PaymentHoldHistory.query.all()) == 1 result = PaymentHoldHistory.get_by_id(object_id) assert result.payment_hold_history_id == \ payment_hold_history.payment_hold_history_id assert result.payment_hold_id == payment_hold_history.payment_hold_id assert result.account_id == payment_hold_history.account_id def test_create_payment_hold_history_on_trigger(): """Test to create payment hold history entry. An actual entry is created via database trigger on payment_hold update. """ assert len(PaymentHoldHistory.query.all()) == 0 payment_hold = PaymentHoldFactory.create() new_start_date = date.today() + timedelta(days=1) payment_hold.update_attributes(start_date=new_start_date) payment_hold.commit_changes() payment_hold_history = PaymentHoldHistory.query.all() assert len(payment_hold_history) == 1 assert payment_hold_history[0].payment_hold_id == payment_hold.payment_hold_id assert payment_hold_history[0].end_date == new_start_date