"""Unit testcases for EarningsTransfer model.""" from abacus_contract.tests.utils.factories import ContractFactory from royalties.constants.constants import ( EARNINGS_TRANSFER_INPUT, EARNINGS_TRANSFER_RATE_TYPES, EARNINGS_TRANSFER_SORT_OPTIONS, EARNINGS_TRANSFER_TYPES, SORT_ORDER_OPTIONS, ) from royalties.models.earnings_transfer import ( EarningsTransfer, ) def test_create(): """Test creating a earnings_transfer.""" assert len(EarningsTransfer.query.all()) == 0 mock_from_contract = ContractFactory.create() mock_to_contract = ContractFactory.create() EarningsTransfer.create( from_contract_id=mock_from_contract.contract_id, to_contract_id=mock_to_contract.contract_id, transfer_type=EARNINGS_TRANSFER_TYPES.TRANSFER, rate_type=EARNINGS_TRANSFER_RATE_TYPES.PERCENT, transfer_amount=1290.123000000000, input=EARNINGS_TRANSFER_INPUT.NET_REVENUE, negative=0, comment='Test Earnings Transfer', ) result = EarningsTransfer.query.all() assert len(result) == 1 assert result[0].from_contract_id == mock_from_contract.contract_id assert result[0].to_contract_id == mock_to_contract.contract_id def test_filtering_earnings_transfers(mock_earnings_transfer_fixture): """Test to filters earnings transfers.""" items, total_count = EarningsTransfer.get_earnings_transfers( 10, 0, EARNINGS_TRANSFER_SORT_OPTIONS.EARNINGS_TRANSFER_ID, SORT_ORDER_OPTIONS.DESC, '1,2,3', '60_days_after_month_end', ) assert total_count == 1 assert items[0].from_contract_id == 90002 assert items[0].to_contract_id == 90004 def test_get_earnings_transfers_by_contract_id(mock_earnings_transfer_fixture): """Test get a list of earnings transfers for specified contract_id.""" items, total_count = EarningsTransfer.get_earnings_transfers_by_contract_id( 10, 0, EARNINGS_TRANSFER_SORT_OPTIONS.EARNINGS_TRANSFER_ID, SORT_ORDER_OPTIONS.DESC, 90002, ) assert total_count == 1 assert items[0].from_contract_id == 90002 assert items[0].to_contract_id == 90004 def test_get_earnings_transfers_by_from_contract_id(mock_earnings_transfer_fixture): """Test get a list of earnings transfers for specified contract_id.""" items, total_count = EarningsTransfer.get_earnings_transfers_by_contract_id( 10, 0, EARNINGS_TRANSFER_SORT_OPTIONS.EARNINGS_TRANSFER_ID, SORT_ORDER_OPTIONS.DESC, 90002, ) assert total_count == 1 assert items[0].from_contract_id == 90002 assert items[0].to_contract_id == 90004 def test_get_earnings_transfers_by_to_contract_id(mock_earnings_transfer_fixture): """Test get a list of earnings transfers for specified contract_id.""" items, total_count = EarningsTransfer.get_earnings_transfers_by_contract_id( 10, 0, EARNINGS_TRANSFER_SORT_OPTIONS.EARNINGS_TRANSFER_ID, SORT_ORDER_OPTIONS.DESC, 90003, ) assert total_count == 1 assert items[0].from_contract_id == 90001 assert items[0].to_contract_id == 90003 def test_get_earnings_transfers_by_contract_id_and_transfer_type( mock_earnings_transfer_fixture, ): """Test get a list of earnings transfers for specified contract_id and transfer type.""" items, total_count = EarningsTransfer.get_earnings_transfers_by_contract_id( 10, 0, EARNINGS_TRANSFER_SORT_OPTIONS.EARNINGS_TRANSFER_ID, SORT_ORDER_OPTIONS.DESC, 90004, EARNINGS_TRANSFER_TYPES.OVERRIDE, ) assert total_count == 1 assert items[0].from_contract_id == 90002 assert items[0].to_contract_id == 90004 def test_get_no_earnings_transfers_by_contract_id_and_transfer_type( mock_earnings_transfer_fixture, ): """Test that an empty list is returned for specified contract_id and transfer type.""" items, total_count = EarningsTransfer.get_earnings_transfers_by_contract_id( 10, 0, EARNINGS_TRANSFER_SORT_OPTIONS.EARNINGS_TRANSFER_ID, SORT_ORDER_OPTIONS.DESC, 90004, EARNINGS_TRANSFER_TYPES.TRANSFER, ) assert total_count == 0 assert len(items) == 0 def test_get_earnings_transfers_from_contract( mock_earnings_transfer_fixture, ): """Test getting the earnings transfers from a contract.""" items = EarningsTransfer.get_earnings_transfers_from_contract(90001) assert len(items) == 1 assert items[0].from_contract_id == 90001