"""Unit testcases for AdjustmentJsonProcessor.""" from decimal import Decimal import numpy as np import pandas as pd from adjustments_json_import.adjustments_json_processor import AdjustmentsJsonProcessor def test__formatted_worksheet_adjustment( mock_adjustments_json_file_content, mock_reference_adjustment_types, mock_statement_periods, ): """Test _formatted_worksheet_adjustment method.""" mock_data = pd.DataFrame(mock_adjustments_json_file_content) mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustments_json_processor = AdjustmentsJsonProcessor( mock_abacus_event_id, mock_data, mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id, ) result = mock_adjustments_json_processor._formatted_worksheet_adjustment( mock_data.iloc[1] ) assert result == { 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, # noqa: E501 'abacus_event_id': mock_abacus_event_id, 'account_id': mock_adjustments_json_file_content[1]['account_id'], 'contract_id': mock_adjustments_json_file_content[1]['contract_id'], 'activity_statement_period_id': 325, 'apply_to_statement_period_id': 326, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustments_json_file_content[1]['currency'], 'note': mock_adjustments_json_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustments_json_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': 1, } def test__formatted_worksheet_adjustment_special_characters( mock_adjustments_json_content_special_characters, mock_reference_adjustment_types, mock_statement_periods, ): """Test _formatted_worksheet_adjustment method with special characters.""" mock_data = pd.DataFrame(mock_adjustments_json_content_special_characters) mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustments_json_processor = AdjustmentsJsonProcessor( mock_abacus_event_id, mock_data, mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id, ) result = mock_adjustments_json_processor._formatted_worksheet_adjustment( mock_data.iloc[1] ) assert result == { 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, 'abacus_event_id': mock_abacus_event_id, 'account_id': mock_adjustments_json_content_special_characters[1]['account_id'], 'contract_id': mock_adjustments_json_content_special_characters[1][ 'contract_id' ], 'activity_statement_period_id': 325, 'apply_to_statement_period_id': 326, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustments_json_content_special_characters[1][ 'currency' ], 'note': mock_adjustments_json_content_special_characters[1][ 'client_facing_comments' ], 'internal_note': mock_adjustments_json_content_special_characters[1][ 'internal_note' ], 'apply_to_flowthrough_payment': 1, } def test__formatted_worksheet_adjustment_with_nan_values( mock_adjustments_json_file_content, mock_reference_adjustment_types, mock_statement_periods, ): """Test _formatted_worksheet_adjustment method for nan values.""" mock_data = pd.DataFrame(mock_adjustments_json_file_content) mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustments_json_processor = AdjustmentsJsonProcessor( mock_abacus_event_id, mock_data, mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id, ) mock_data.loc[1, ['client_facing_comments', 'internal_note']] = np.nan result = mock_adjustments_json_processor._formatted_worksheet_adjustment( mock_data.iloc[1] ) assert result == { 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, # noqa: E501 'abacus_event_id': mock_abacus_event_id, 'account_id': mock_adjustments_json_file_content[1]['account_id'], 'contract_id': mock_adjustments_json_file_content[1]['contract_id'], 'activity_statement_period_id': 325, 'apply_to_statement_period_id': 326, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustments_json_file_content[1]['currency'], 'note': None, 'internal_note': None, 'apply_to_flowthrough_payment': 1, } def test_process( mock_adjustments_json_file_content, mock_reference_adjustment_types, mock_statement_periods, ): """Test process method.""" mock_data = pd.DataFrame(mock_adjustments_json_file_content) mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustments_json_processor = AdjustmentsJsonProcessor( mock_abacus_event_id, mock_data.iterrows(), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id, ) mock_adjustments_json_processor.process() assert mock_adjustments_json_processor._worksheet_adjustment_entries == [ { 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, 'abacus_event_id': mock_abacus_event_id, 'account_id': mock_adjustments_json_file_content[0]['account_id'], 'contract_id': mock_adjustments_json_file_content[0]['contract_id'], 'activity_statement_period_id': 325, 'apply_to_statement_period_id': 326, 'reference_adjustment_type_id': 1, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustments_json_file_content[1][ 'currency' ], 'note': mock_adjustments_json_file_content[0]['client_facing_comments'], 'internal_note': mock_adjustments_json_file_content[0]['internal_note'], 'apply_to_flowthrough_payment': True, }, { 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, 'abacus_event_id': mock_abacus_event_id, 'account_id': mock_adjustments_json_file_content[1]['account_id'], 'contract_id': mock_adjustments_json_file_content[1]['contract_id'], 'activity_statement_period_id': 325, 'apply_to_statement_period_id': 326, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustments_json_file_content[1][ 'currency' ], 'note': mock_adjustments_json_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustments_json_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': True, }, ] def test__formatted_worksheet_adjustment_currency_in_lowercase( mock_adjustments_json_file_content, mock_reference_adjustment_types, mock_statement_periods, ): """Test _formatted_worksheet_adjustment method. When currency is in lowercase. """ mock_data = pd.DataFrame(mock_adjustments_json_file_content) mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustments_json_processor = AdjustmentsJsonProcessor( mock_abacus_event_id, mock_data, mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id, ) mock_adjustments_json_file_content[1]['currency'] = 'usd' result = mock_adjustments_json_processor._formatted_worksheet_adjustment( mock_data.iloc[1] ) assert result == { 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, 'abacus_event_id': mock_abacus_event_id, 'account_id': mock_adjustments_json_file_content[1]['account_id'], 'contract_id': mock_adjustments_json_file_content[1]['contract_id'], 'activity_statement_period_id': 325, 'apply_to_statement_period_id': 326, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustments_json_file_content[1][ 'currency' ].upper(), 'note': mock_adjustments_json_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustments_json_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': 1, }