"""Unit testcases for AdjustmentFileProcessor.""" from decimal import Decimal from adjustment_file_import.adjustment_file_processor \ import AdjustmentFileProcessor def test_formatted_worksheet_adjustment( mock_adjustment_file_content, mock_reference_adjustment_types, mock_statement_periods ): """Test _formatted_worksheet_adjustment method.""" mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustment_file_processor = AdjustmentFileProcessor( mock_abacus_event_id, enumerate(mock_adjustment_file_content), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id ) result = mock_adjustment_file_processor._formatted_worksheet_adjustment( mock_adjustment_file_content[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_adjustment_file_content[1]['account_id'], 'contract_id': mock_adjustment_file_content[1]['contract_id'], 'activity_statement_period_id': 301, 'apply_to_statement_period_id': 302, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustment_file_content[1]['currency'], 'note': mock_adjustment_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustment_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': None } def test_formatted_worksheet_adjustment_special_characters( mock_adjustment_file_content, mock_adjustment_file_content_special_characters, mock_reference_adjustment_types, mock_statement_periods ): """Test _formatted_worksheet_adjustment method with special characters.""" mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustment_file_processor = AdjustmentFileProcessor( mock_abacus_event_id, enumerate(mock_adjustment_file_content_special_characters), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id ) result = mock_adjustment_file_processor._formatted_worksheet_adjustment( mock_adjustment_file_content_special_characters[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_adjustment_file_content[1]['account_id'], # noqa: E501 'contract_id': mock_adjustment_file_content[1]['contract_id'], # noqa: E501 'activity_statement_period_id': 301, 'apply_to_statement_period_id': 302, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustment_file_content[1]['currency'], # noqa: E501 'note': mock_adjustment_file_content[1]['client_facing_comments'], # noqa: E501 'internal_note': mock_adjustment_file_content[1]['internal_note'], # noqa: E501 'apply_to_flowthrough_payment': None } def test_formatted_worksheet_adjustment_detail( mock_adjustment_file_content, mock_reference_adjustment_types, mock_statement_periods ): """Test _formatted_worksheet_adjustment_detail method.""" mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustment_file_processor = AdjustmentFileProcessor( mock_abacus_event_id, enumerate(mock_adjustment_file_content), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id ) result = mock_adjustment_file_processor._formatted_worksheet_adjustment_detail( mock_adjustment_file_content[0] ) assert result == { 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, # noqa: E501 'account_id': mock_adjustment_file_content[0]['account_id'], 'contract_id': mock_adjustment_file_content[0]['contract_id'], 'activity_statement_period_id': 301, 'apply_to_statement_period_id': 302, 'reference_adjustment_type_id': 1, 'currency_code': mock_adjustment_file_content[0]['currency'], 'amount': Decimal('-50.90'), 'upc': mock_adjustment_file_content[0]['upc'], 'distribution_type': mock_adjustment_file_content[0]['distribution_type'], 'note': mock_adjustment_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustment_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': None } def test_process( mock_adjustment_file_content, mock_reference_adjustment_types, mock_statement_periods ): """Test process method.""" mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustment_file_processor = AdjustmentFileProcessor( mock_abacus_event_id, enumerate(mock_adjustment_file_content), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id ) mock_adjustment_file_processor.process() assert mock_adjustment_file_processor.worksheet_adjustment_detail_entries == [{ 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, # noqa: E501 'account_id': mock_adjustment_file_content[0]['account_id'], 'contract_id': mock_adjustment_file_content[0]['contract_id'], 'activity_statement_period_id': 301, 'apply_to_statement_period_id': 302, 'reference_adjustment_type_id': 1, 'currency_code': mock_adjustment_file_content[0]['currency'], 'amount': Decimal('-50.90'), 'upc': mock_adjustment_file_content[0]['upc'], 'distribution_type': mock_adjustment_file_content[0]['distribution_type'], 'note': mock_adjustment_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustment_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': None }] assert mock_adjustment_file_processor.worksheet_adjustment_entries == [{ 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, # noqa: E501 'abacus_event_id': mock_abacus_event_id, 'account_id': mock_adjustment_file_content[1]['account_id'], 'contract_id': mock_adjustment_file_content[1]['contract_id'], 'activity_statement_period_id': 301, 'apply_to_statement_period_id': 302, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustment_file_content[1]['currency'], 'note': mock_adjustment_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustment_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': None }] def test_formatted_worksheet_adjustment_currency_in_lowercase( mock_adjustment_file_content, mock_reference_adjustment_types, mock_statement_periods ): """Test _formatted_worksheet_adjustment method. When currency is in lowercase. """ mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustment_file_processor = AdjustmentFileProcessor( mock_abacus_event_id, enumerate(mock_adjustment_file_content), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id ) mock_adjustment_file_content[1]['currency'] = 'USD' result = mock_adjustment_file_processor._formatted_worksheet_adjustment( mock_adjustment_file_content[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_adjustment_file_content[1]['account_id'], 'contract_id': mock_adjustment_file_content[1]['contract_id'], 'activity_statement_period_id': 301, 'apply_to_statement_period_id': 302, 'reference_adjustment_type_id': 2, 'adjustment_amount': Decimal('-50.90'), 'adjustment_currency_code': mock_adjustment_file_content[1]['currency'].upper(), # noqa: E501 'note': mock_adjustment_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustment_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': None } def test_formatted_worksheet_adjustment_detail_currency_in_lowercase( mock_adjustment_file_content, mock_reference_adjustment_types, mock_statement_periods ): """Test _formatted_worksheet_adjustment_detail method. When currency is in lowercase. """ mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustment_file_processor = AdjustmentFileProcessor( mock_abacus_event_id, enumerate(mock_adjustment_file_content), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id ) mock_adjustment_file_content[0]['currency'] = 'USD' result = mock_adjustment_file_processor._formatted_worksheet_adjustment_detail( mock_adjustment_file_content[0] ) assert result == { 'statement_period_adjustment_file_id': mock_statement_period_adjustment_file_id, # noqa: E501 'account_id': mock_adjustment_file_content[0]['account_id'], 'contract_id': mock_adjustment_file_content[0]['contract_id'], 'activity_statement_period_id': 301, 'apply_to_statement_period_id': 302, 'reference_adjustment_type_id': 1, 'currency_code': mock_adjustment_file_content[0]['currency'].upper(), 'amount': Decimal('-50.90'), 'upc': mock_adjustment_file_content[0]['upc'], 'distribution_type': mock_adjustment_file_content[0]['distribution_type'], 'note': mock_adjustment_file_content[1]['client_facing_comments'], 'internal_note': mock_adjustment_file_content[1]['internal_note'], 'apply_to_flowthrough_payment': None } def test_formatted_worksheet_adjustment_with_flowthrough_payment( mock_adjustment_file_content, mock_reference_adjustment_types, mock_statement_periods ): """Test _formatted_worksheet_adjustment method with apply_to_flowthrough_payment.""" mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustment_file_processor = AdjustmentFileProcessor( mock_abacus_event_id, enumerate(mock_adjustment_file_content), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id ) # Modify content to include 'apply_to_flowthrough_payment' mock_content = mock_adjustment_file_content[1] mock_content['apply_to_flowthrough_payment'] = 'true' result = mock_adjustment_file_processor._formatted_worksheet_adjustment( mock_content ) assert result['apply_to_flowthrough_payment'] is True def test_formatted_worksheet_adjustment_flowthrough_true_false( mock_adjustment_file_content, mock_reference_adjustment_types, mock_statement_periods ): """Test _formatted_worksheet_adjustment with True and False flowthrough values.""" mock_abacus_event_id = 1 mock_statement_period_adjustment_file_id = 1 mock_adjustment_file_processor = AdjustmentFileProcessor( mock_abacus_event_id, enumerate(mock_adjustment_file_content), mock_reference_adjustment_types, mock_statement_periods, mock_statement_period_adjustment_file_id ) # Test with True mock_adjustment_file_content[1]['apply_to_flowthrough_payment'] = 'true' result = mock_adjustment_file_processor._formatted_worksheet_adjustment( mock_adjustment_file_content[1] ) assert result['apply_to_flowthrough_payment'] is True # Test with False mock_adjustment_file_content[1]['apply_to_flowthrough_payment'] = 'false' result = mock_adjustment_file_processor._formatted_worksheet_adjustment( mock_adjustment_file_content[1] ) assert result['apply_to_flowthrough_payment'] is False