"""AccountPayee model tests.""" import datetime from payee.models.account_payee import AccountPayee from payee.models.account_tax_info import AccountTaxInfo from payee.models.tax_form import TaxFormInfo from tests.utils.factories import AccountPayeeFactory def test_get_payees_by_ids(): """Get account payees by ids.""" account_payee_id = 1 account = AccountPayeeFactory.create(account_payee_id=account_payee_id) AccountPayeeFactory.create(account_id=2) results = AccountPayee.get_payees_by_ids([account_payee_id]) assert len(results) == 1 assert results[0].account_payee_id == account_payee_id def test_get_payees_by_ids_none_found(): """Get account payees by ids.""" account_payee_id = 1 AccountPayeeFactory.create(account_payee_id=55) results = AccountPayee.get_payees_by_ids([account_payee_id]) assert len(results) == 0 def test_tax_form_info_relationship_has_tax_form(): """Get atax_form_info relationship.""" account_payee_id = 1 AccountPayeeFactory.create(account_payee_id=account_payee_id) tax_form_info = TaxFormInfo.create( tax_form_type='W9', account_payee_id=account_payee_id, signed_date=datetime.date(2024, 2, 1), ) result = AccountPayee.get_by_id(account_payee_id) assert result.tax_form_info == tax_form_info def test_tax_form_info_relationship_no_tax_form(): """Get atax_form_info relationship.""" account_payee_id = 2 AccountPayeeFactory.create(account_payee_id=account_payee_id) result = AccountPayee.get_by_id(account_payee_id) assert result.tax_form_info is None def test_payoneer_client_reference_id_property(): """Ensure payoneer_client_reference_id returns the account_payee_id.""" account_payee_id = 42 account = AccountPayeeFactory.create(account_payee_id=account_payee_id) assert account.payoneer_client_reference_id == account_payee_id def test_payment_description_field_default(): """Test payment_description field has default value.""" account_payee = AccountPayeeFactory.create() assert account_payee.payment_description == 'Default payment description' def test_payment_description_field_custom_value(): """Test payment_description field with custom value.""" custom_description = 'Custom payment for services rendered' account_payee = AccountPayeeFactory.create(payment_description=custom_description) assert account_payee.payment_description == custom_description def test_payment_description_field_not_null(): """Test payment_description field is not nullable.""" account_payee_id = 100 account_payee = AccountPayeeFactory.create( account_payee_id=account_payee_id, payment_description='Required payment description', ) result = AccountPayee.get_by_id(account_payee_id) assert result.payment_description is not None def test_payment_description_field_max_length(): """Test payment_description field can store up to 250 characters.""" long_description = 'A' * 250 account_payee = AccountPayeeFactory.create(payment_description=long_description) assert len(account_payee.payment_description) == 250 assert account_payee.payment_description == long_description def test_payment_description_field_persistence(): """Test payment_description field is persisted to database.""" account_payee_id = 200 test_description = 'Payment for consulting services' AccountPayeeFactory.create( account_payee_id=account_payee_id, payment_description=test_description ) retrieved = AccountPayee.get_by_id(account_payee_id) assert retrieved.payment_description == test_description def test_account_tax_info_relationship(account_fixtures, account_tax_info_fixtures): """Test account_tax_info relationship.""" account_tax_info = AccountTaxInfo.get_by_id(1) account_payee = AccountPayeeFactory.create(account_id=1) assert account_payee.account_tax_info == account_tax_info account_payee = AccountPayeeFactory.create(account_id=10) assert account_payee.account_tax_info is None