"""Payment Group Payment Batch Account functional tests.""" from tests.utils.factories import ( PaymentGroupPaymentAccountFactory, PaymentGroupPaymentBatchFactory, ) def test_bulk_create_success(fixture_client, mock_accounts): """Test successful creation of payment_group_payment_batch_account in bulk.""" 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 ) post_body = [ { '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, }, ] response = fixture_client.post( '/payment-group-payment-batch-account/bulk/', json=post_body ) assert response.status_code == 201 assert len(response.json) == len(post_body) assert all( res.get('payment_group_payment_batch_account_id') for res in response.json ) assert all(res.get('payment_group_payment_account_id') for res in response.json) assert all(res.get('payment_group_payment_batch_id') for res in response.json) def test_bulk_create_failure(fixture_client): """Test bulk creation returns error when fields are missing.""" post_body = [ {'payment_group_payment_account_id': 1}, {'payment_group_payment_batch_id': 2}, ] response = fixture_client.post( '/payment-group-payment-batch-account/bulk/', json=post_body ) assert response.status_code == 400 assert response.json['message']['json'] == { '0': {'payment_group_payment_batch_id': ['Must be specified.']}, '1': {'payment_group_payment_account_id': ['Must be specified.']}, }