"""Configuration for functional tests.""" from abacus_worksheet.constants import constants from tests.utils.factories import WorksheetCorrectionFactory def test_bulk_create_worksheet_correction_entries(fixture_client): """Test create worksheet correction entries.""" post_body = [ { 'account_id': 1, 'contract_id': None, 'correction_statement_period_id': 2, 'currency_code': 'GBP', 'correction_type': 'royalty_reversal', 'gross_revenue': 9876.5432, 'distribution_fee': 1975.30864, 'mechanical_deduction_total': -100.89, 'mechanical_deduction_admin_fee_total': -45.13, 'net_revenue': 7901.23456, 'statement_period_id': 2, }, { 'account_id': 1, 'contract_id': 1, 'correction_statement_period_id': 1, 'currency_code': 'USD', 'correction_type': 'royalty_correction', 'gross_revenue': 1000.00, 'distribution_fee': 0, 'net_revenue': 1000.00, 'statement_period_id': 2, }, ] res = fixture_client.post('/worksheet-correction/bulk', json=post_body) assert res.status_code == 201 assert len(res.json) == 2 assert res.json == [ { 'account_id': 1, 'contract_id': None, 'correction_statement_period_id': 2, 'correction_type': 'royalty_reversal', 'currency_code': 'GBP', 'gross_revenue': '9876.543200000000000000', 'distribution_fee': '1975.308640000000000000', 'mechanical_deduction_total': '-100.890000000000000000', 'mechanical_deduction_admin_fee_total': '-45.130000000000000000', 'net_revenue': '7901.234560000000000000', 'note': None, 'statement_period_id': 2, 'worksheet_correction_id': 1, }, { 'account_id': 1, 'contract_id': 1, 'correction_statement_period_id': 1, 'correction_type': 'royalty_correction', 'currency_code': 'USD', 'gross_revenue': '1000.000000000000000000', 'distribution_fee': '0.000000000000000000', 'mechanical_deduction_total': None, 'mechanical_deduction_admin_fee_total': None, 'net_revenue': '1000.000000000000000000', 'note': None, 'statement_period_id': 2, 'worksheet_correction_id': 2, }, ] def test_get_unapplied_worksheet_corrections( fixture_client, create_mock_ledger_correction ): """Test to get unapplied worksheet corrections. return records that are not deleted and don't exist in ledger_correction_table. """ WorksheetCorrectionFactory.create( correction_type=constants.CORRECTION_TYPES.ROYALTY_REVERSAL, deleted_by='Test', deleted_at='2019-03-01 00:00:00', ) worksheet_correction = WorksheetCorrectionFactory.create( correction_type=constants.CORRECTION_TYPES.ROYALTY_REVERSAL ) statement_period = 2 correction_type = constants.CORRECTION_TYPES.ROYALTY_REVERSAL res = fixture_client.get( f'/worksheet-correction/statement-period/{statement_period}/{correction_type}/unapplied?limit=10&offset=0' ) assert res.status_code == 200 assert res.json['total_count'] == 1 assert res.json['items'] == [ { 'worksheet_correction_id': worksheet_correction.worksheet_correction_id, 'account_id': 1, 'contract_id': None, 'correction_type': 'royalty_reversal', 'currency_code': 'USD', 'statement_period_id': 2, 'correction_statement_period_id': 1, 'gross_revenue': '9876.543200000000000000', 'distribution_fee': '1975.308640000000000000', 'mechanical_deduction_total': None, 'mechanical_deduction_admin_fee_total': None, 'net_revenue': '7901.234560000000000000', 'note': None, } ] def test_get_unapplied_worksheet_corrections_error(fixture_client): """Test to get unapplied worksheet corrections for invalid correction_type.""" statement_period = 1 correction_type = 'Test' res = fixture_client.get( f'/worksheet-correction/statement-period/{statement_period}/{correction_type}/unapplied' ) assert res.status_code == 400 assert res.json['message'] == str( {'correction_type': ['Must be one of royalty_reversal, royalty_correction']} )