"""Test ows-abacus-account requests.""" from http import HTTPStatus from typing import Any import httpx from owsclient.test import OwsClientMock import pytest from src.connectors import ows_abacus_account from src.connectors.exceptions import OwsPayeeException from src.models.ows_abacus_account import AccountPayeeUpdateModel from tests.unit.factories import AccountPayeeFactory, AccountPaymentTermFactory @pytest.mark.parametrize('expected_status', (HTTPStatus.OK, HTTPStatus.BAD_REQUEST)) def test_get_account_payee( expected_status: HTTPStatus, ows_client_mock: OwsClientMock ) -> None: """Test get_account_payee.""" account_payee_id = 311 account_payee = AccountPayeeFactory.build(account_payee_id=account_payee_id) path = f'/account-payee/{account_payee_id}' ows_client_mock.get('ows-abacus-account', path).mock( return_value=httpx.Response( expected_status, json=account_payee.model_dump(mode='json'), ) ) if expected_status == HTTPStatus.OK: result = ows_abacus_account.get_account_payee(account_payee_id) assert result == account_payee else: with pytest.raises(OwsPayeeException): ows_abacus_account.get_account_payee(account_payee_id) @pytest.mark.parametrize( 'expected_status,update_data', ( (HTTPStatus.OK, dict(reference_payment_type_id=11)), (HTTPStatus.OK, dict(reference_payment_type_id=16, payoneer_program_id=100100)), (HTTPStatus.BAD_REQUEST, {}), ), ) def test_update_account_payee( expected_status: HTTPStatus, update_data: dict[str, Any], ows_client_mock: OwsClientMock, ) -> None: """Test update_account_payee.""" account_payee_id = 311 account_payee = AccountPayeeFactory.build(account_payee_id=account_payee_id) ows_client_mock.put( 'ows-abacus-account', f'/account-payee/{account_payee_id}', json=update_data ).mock( return_value=httpx.Response( expected_status, json=account_payee.model_dump(mode='json') ) ) if expected_status == HTTPStatus.OK: result = ows_abacus_account.update_account_payee( account_payee_id, AccountPayeeUpdateModel(**update_data) ) assert result == account_payee else: with pytest.raises(OwsPayeeException): ows_abacus_account.update_account_payee( account_payee_id, AccountPayeeUpdateModel(**update_data) ) @pytest.mark.parametrize('expected_status', (HTTPStatus.OK, HTTPStatus.BAD_REQUEST)) def test_get_account_payment_term( expected_status: HTTPStatus, ows_client_mock: OwsClientMock ) -> None: """Test get_account_payment_term.""" account_id = 42 account_payment_term = AccountPaymentTermFactory.build(account_id=account_id) path = f'/account/{account_id}/account-payment-term/' ows_client_mock.get('ows-abacus-account', path).mock( return_value=httpx.Response( expected_status, json=account_payment_term.model_dump(mode='json'), ) ) if expected_status == HTTPStatus.OK: result = ows_abacus_account.get_account_payment_term(account_id) assert result == account_payment_term else: with pytest.raises(OwsPayeeException): ows_abacus_account.get_account_payment_term(account_id)