"""Unit tests for contract_flowthrough model.""" import datetime from decimal import Decimal from abacus_contract.constants.constants import \ CONTRACT_FLOWTHROUGH_PREVIOUS_STATUSES from abacus_contract.constants.constants import \ CONTRACT_FLOWTHROUGH_STATUSES from abacus_contract.models import ContractFlowthrough from tests.utils.factories import ContractFactory from tests.utils.factories import ContractFlowthroughFactory from tests.utils.factories import ReferenceFlowthroughCalculationFactory def test_create_contract_flowthrough(): """Test creating a contract_flowthrough.""" mock_contract = ContractFactory.create() mock_reference_flowthrough_calculation = \ ReferenceFlowthroughCalculationFactory.create() reference_flowthrough_calculation_id = \ mock_reference_flowthrough_calculation.reference_flowthrough_calculation_id args = { 'contract_id': mock_contract.contract_id, 'reference_flowthrough_calculation_id': reference_flowthrough_calculation_id, 'flowthrough_rate': 0.51, 'flowthrough_status': CONTRACT_FLOWTHROUGH_STATUSES.ACTIVE, 'has_automatic_shutoff': 1, 'recoupment_cap': 1234231, 'previous_flowthrough_status': CONTRACT_FLOWTHROUGH_PREVIOUS_STATUSES.PAUSED, 'status_last_modified_by': 'Test User', 'status_last_modified': '2025-02-28 00:00:00' } ContractFlowthrough.create(**args) res = ContractFlowthrough.query.all() assert len(res) == 1 assert res[0].contract_id == mock_contract.contract_id assert res[0].reference_flowthrough_calculation_id == \ reference_flowthrough_calculation_id assert res[0].flowthrough_rate == Decimal('0.51') assert res[0].flowthrough_status == CONTRACT_FLOWTHROUGH_STATUSES.ACTIVE assert res[0].has_automatic_shutoff == 1 assert res[0].recoupment_cap == 1234231 assert res[0].previous_flowthrough_status == \ CONTRACT_FLOWTHROUGH_PREVIOUS_STATUSES.PAUSED assert res[0].status_last_modified_by == 'Test User' assert res[0].status_last_modified == datetime.datetime(2025, 2, 28, 0, 0) def test_get_by_contract_id(): """Test to get contract_flowthrough by contract_id.""" mock_contract = ContractFactory.create() mock_flowthroughs = [ ContractFlowthroughFactory.create( contract=mock_contract, deleted_by='Test User', deleted_at=datetime.datetime(2025, 2, 28, 0, 0) ), ContractFlowthroughFactory.create( contract=mock_contract ) ] result = ContractFlowthrough.get_by_contract_id(mock_contract.contract_id) assert result == mock_flowthroughs[1]