"""Unit tests for contract_flowthrough schemas.""" from abacus_contract.constants.constants import \ CONTRACT_FLOWTHROUGH_STATUSES from abacus_contract.schemas.contract_flowthrough \ import BaseContractFlowthroughSchema from abacus_contract.schemas.contract_flowthrough \ import ContractFlowthroughDetailSchema from abacus_contract.schemas.contract_flowthrough \ import ContractFlowthroughPostSchema from abacus_contract.schemas.contract_flowthrough \ import ContractFlowthroughPutSchema from tests.utils.factories import ContractFlowthroughFactory def test_base_contract_flowthrough_schema(): """Test contract_flowthrough base schema.""" mock_contract_flowthrough = ContractFlowthroughFactory.create() res = BaseContractFlowthroughSchema().dump(mock_contract_flowthrough) assert res == { 'contract_id': mock_contract_flowthrough.contract_id, 'reference_flowthrough_calculation_id': mock_contract_flowthrough.reference_flowthrough_calculation_id, 'flowthrough_rate': str(mock_contract_flowthrough.flowthrough_rate), 'flowthrough_status': mock_contract_flowthrough.flowthrough_status, 'has_automatic_shutoff': mock_contract_flowthrough.has_automatic_shutoff, 'recoupment_cap': mock_contract_flowthrough.recoupment_cap, 'previous_flowthrough_status': mock_contract_flowthrough.previous_flowthrough_status, 'status_last_modified_by': mock_contract_flowthrough.status_last_modified_by, 'status_last_modified': str(mock_contract_flowthrough.status_last_modified.date()) } def test_contract_flowthrough_detail_schema(): """Test contract_flowthrough detail schema.""" mock_contract_flowthrough = ContractFlowthroughFactory.create() res = ContractFlowthroughDetailSchema().dump(mock_contract_flowthrough) assert res == { 'contract_id': mock_contract_flowthrough.contract_id, 'contract_flowthrough_id': mock_contract_flowthrough.contract_flowthrough_id, 'reference_flowthrough_calculation_id': mock_contract_flowthrough.reference_flowthrough_calculation_id, 'flowthrough_rate': str(mock_contract_flowthrough.flowthrough_rate), 'flowthrough_status': mock_contract_flowthrough.flowthrough_status, 'has_automatic_shutoff': mock_contract_flowthrough.has_automatic_shutoff, 'recoupment_cap': mock_contract_flowthrough.recoupment_cap, 'previous_flowthrough_status': mock_contract_flowthrough.previous_flowthrough_status, 'status_last_modified_by': mock_contract_flowthrough.status_last_modified_by, 'status_last_modified': str(mock_contract_flowthrough.status_last_modified.date()) } def test_contract_flowthrough_put_schema(): """Test contract_flowthrough PUT schema.""" mock_put_request = { 'reference_flowthrough_calculation_id': 1, 'flowthrough_rate': 1.09, 'flowthrough_status': CONTRACT_FLOWTHROUGH_STATUSES.ACTIVE, 'recoupment_cap': 1290 } res = ContractFlowthroughPutSchema().dump(mock_put_request) assert res == { 'reference_flowthrough_calculation_id': mock_put_request['reference_flowthrough_calculation_id'], 'flowthrough_rate': str(mock_put_request['flowthrough_rate']), 'flowthrough_status': mock_put_request['flowthrough_status'], 'recoupment_cap': mock_put_request['recoupment_cap'] } def test_contract_flowthrough_post_schema(): """Test contract_flowthrough POST schema.""" mock_put_request = { 'reference_flowthrough_calculation_id': 1, 'flowthrough_rate': 1.09, 'has_automatic_shutoff': 1, 'recoupment_cap': 1290 } res = ContractFlowthroughPostSchema().dump(mock_put_request) assert res == { 'reference_flowthrough_calculation_id': mock_put_request['reference_flowthrough_calculation_id'], 'flowthrough_rate': str(mock_put_request['flowthrough_rate']), 'has_automatic_shutoff': mock_put_request['has_automatic_shutoff'], 'recoupment_cap': mock_put_request['recoupment_cap'] }