"""Unit tests for Payment Group Payment Batch Accounts logic.""" from unittest.mock import patch import pytest from payment.logic import payment_group_payment_batch_account as logic from tests.utils.factories import ( PaymentGroupPaymentAccountFactory, PaymentGroupPaymentBatchFactory, ) @patch( 'payment.logic.payment_group_payment_batch_account.PaymentGroupPaymentBatchAccount' ) @patch('payment.logic.payment_group_payment_batch_account.PaymentGroupPaymentBatch') @patch('payment.logic.payment_group_payment_batch_account.PaymentGroupPaymentAccount') def test_bulk_create_success( mock_payment_group_payment_account, mock_payment_group_payment_batch, mock_payment_group_payment_batch_account, mock_accounts, ): """Test successfully creating multiple payment_group_payment_batch_account records.""" # noqa: E501 payment_group_payment_account_1 = PaymentGroupPaymentAccountFactory.create( account_id=1 ) payment_group_payment_account_2 = PaymentGroupPaymentAccountFactory.create( account_id=2 ) payment_group_payment_batch = PaymentGroupPaymentBatchFactory.create() payment_group_payment_batch_id = ( payment_group_payment_batch.payment_group_payment_batch_id ) params = ( { 'payment_group_payment_account_id': payment_group_payment_account_1.payment_group_payment_account_id, 'payment_group_payment_batch_id': payment_group_payment_batch_id, }, { 'payment_group_payment_account_id': payment_group_payment_account_2.payment_group_payment_account_id, 'payment_group_payment_batch_id': payment_group_payment_batch_id, }, ) res = logic.bulk_create(params) assert res == [mock_payment_group_payment_batch_account.build.return_value] * len( params ) assert mock_payment_group_payment_batch_account.build.call_count == len(params) def test_bulk_create_failure(): """Test bulk creation throws an exception when payment_group_payment_account_id doesn't exist.""" # noqa: E501 params = ( {'payment_group_payment_account_id': 1234, 'payment_group_payment_batch_id': 1}, ) with pytest.raises(Exception): logic.bulk_create(params)