"""Tests for account_payment_term_template handlers.""" from unittest.mock import patch from owsresponse import response @patch( 'abacus_account.logic.account_payment_term_template' '.create_payment_terms_from_template' ) def test_post_account_payment_term_template_success( mock_logic, fixture_client ): """Test successful creation of new account payment term from template.""" mock_logic.return_value = response.Response(message='ok', status=201) post_body = { 'account_id': 1, } uri = '/account-payment-term-template/1/account-payment-term' res = fixture_client.post(uri, json=post_body) assert res.status_code == 201 mock_logic.assert_called_once_with(template_id=1, account_id=1) @patch( 'abacus_account.logic.account_payment_term_template' '.create_payment_terms_from_template' ) def test_post_account_payment_term_template_error( mock_logic, fixture_client ): """Test failure creating account payment term from template.""" post_body = { 'wrong_key': 'wrong_value' } res = fixture_client.post( '/account-payment-term-template/1/account-payment-term', json=post_body ) assert res.status_code == 400 mock_logic.assert_not_called() assert res.json == { 'code': 'error', 'message': { 'account_id': [ 'Must be specified.' ], 'wrong_key': [ 'Unknown field.' ] } }