"""Factories for testing models.""" import datetime from decimal import Decimal from abacus_common_logic.test_utils.factories import BaseModelFactoryWithTimestamps import factory.fuzzy from payee.constants.constants import ( PAYEE_TYPES, PAYONEER_WHITELABEL_REFERENCE_PAYMENT_TYPE_ID, TAX_FORM_TYPES, TAX_TYPES, ) from payee.models.account_payee import AccountPayee from payee.models.account_tax_info import AccountTaxInfo from payee.models.payee import Payee from payee.models.payee_collaborator import PayeeCollaborator from payee.models.payee_kyc_notification import ( AccountPayeeKycNotification, PayeeKycNotification, ) from payee.models.reports_tax_info import ReportsTaxInfo from payee.models.tax_form import TaxFormInfo, TaxFormInfoDetails from payee.models.tax_withholding_override import TaxWithholdingOverride from payee.utils.models import object_as_dict from tests.constants import MOCK_AUDIT_FIELDS, MOCK_TAX_FORM_DETAILS class AccountPayeeFactory(BaseModelFactoryWithTimestamps): """Factory to create account_payee models for testing.""" class Meta: """Meta definition for the factory.""" model = AccountPayee account_id = factory.Sequence(lambda n: n + 1) account_payee_id = factory.Sequence(lambda n: n + 1) payoneer_payee_id = 100 payoneer_payee_name = 'Payoneer Payee' payoneer_iframe_url = 'payoneer.com/fake_iframe_url' payoneer_iframe_url_date = datetime.date(2022, 2, 1) payoneer_session_id = 'B99' payoneer_program_id = 1 sap_vendor_id = factory.Sequence(lambda n: n + 1) payment_description = 'Default payment description' last_modified = datetime.date(2022, 2, 28) class BasePayeeKycNotificationFactory(BaseModelFactoryWithTimestamps): """Base factory to create payee_kyc_notification models for testing.""" file_upload_link = 'test_file_upload_link' requirement_id = 'test_requirement_id' requirement_type_id = 12 sub_requirement_id = 'test_sub_requirement_id' sub_requirement_status_id = 10 possible_sub_requirement_types = '1,5,101' entity_reference_id = 'ef4d765b-995e-468b-adc2-8d8434f85b95' entity_reference_type_id = 100 deleted_at = None deleted_by = None created_by = 'test_created_by' last_modified_by = 'test_last_modified_by' class PayeeKycNotificationFactory(BasePayeeKycNotificationFactory): """Factory to create payee_kyc_notification models for testing.""" class Meta: """Meta definition for the factory.""" model = PayeeKycNotification payee_kyc_notification_id = factory.Sequence(lambda n: n + 1) payee_id = 1 class AccountPayeeKycNotificationFactory(BasePayeeKycNotificationFactory): """Factory to create account_payee_kyc_notification models for testing.""" class Meta: """Meta definition for the factory.""" model = AccountPayeeKycNotification account_payee_kyc_notification_id = factory.Sequence(lambda n: n + 1) account_payee_id = 1 class TaxFormInfoFactory(BaseModelFactoryWithTimestamps): """Factory to create tax_form_info models for testing.""" class Meta: model = TaxFormInfo account_payee_tax_form_info_id = 1 tax_form_type = TAX_FORM_TYPES.W9 account_payee_id = 1 signed_date = datetime.date(2024, 2, 1) expiration_date = datetime.date.today() + datetime.timedelta(days=1) last_modified = datetime.date(2024, 2, 1) class TaxFormInfoDetailsFactory(factory.Factory): """Factory to create TaxFormInfoDetails instances.""" class Meta: model = TaxFormInfoDetails account_payee_tax_form_info_id = 11 tax_form_type = TAX_FORM_TYPES.W9 account_payee_id = 1 signed_date = datetime.date(2024, 2, 1) expiration_date = datetime.date.today() + datetime.timedelta(days=1) last_modified = datetime.date(2024, 2, 1) details = factory.LazyAttribute( lambda obj: { **MOCK_AUDIT_FIELDS, **MOCK_TAX_FORM_DETAILS.get(obj.tax_form_type), 'account_payee_id': obj.account_payee_id, 'tax_form_type': obj.tax_form_type, 'revision': '0', } ) @classmethod def _build(cls, model_class, *args, **kwargs): details = kwargs.pop('details') return model_class( **object_as_dict( TaxFormInfoFactory.build(**kwargs), ignore_fields=('revision_id',) ), details=details, ) class BankDetailsIndividualTypeFlattenFactory(factory.DictFactory): """Factory to create bank details models for testing.""" type = 'INDIVIDUAL' first_name = 'firstName' last_name = 'lastName' email = 'test@example.com' phone = '4567890' phone_country = 'US' date_of_birth = '2000-10-10' address_1 = 'asdf' address_2 = 'dfgh' city = 'odesa' province = 'AZ' country_code = 'US' zip = '65000' bank_account_type = 'PERSONAL' country = 'UA' currency = 'UAH' bank_field_details = factory.LazyAttribute( lambda o: [ {'name': 'AccountNumber', 'value': '345234552345'}, {'name': 'AccountName', 'value': 'John Smith'}, {'name': 'BankName', 'value': 'Bank of Hope'}, {'name': 'RoutingNumber', 'value': '122105155'}, {'name': 'AccountType', 'value': 'S'}, ] ) class BankDetailsCompanyTypeFlattenFactory(factory.DictFactory): """Factory to create bank details models for testing.""" type = 'COMPANY' name = 'company name' address_1 = 'asdf' address_2 = 'dfgh' city = 'odesa' province = 'odesa' country_code = 'USA' zip = '65000' bank_account_type = 'COMPANY' country = 'UA' currency = 'UAH' bank_field_details = factory.LazyAttribute( lambda o: [ {'name': 'AccountNumber', 'value': '345234552345'}, {'name': 'AccountName', 'value': 'John Smith'}, {'name': 'BankName', 'value': 'Bank of Hope'}, {'name': 'RoutingNumber', 'value': '122105155'}, {'name': 'AccountType', 'value': 'S'}, ] ) class BankDetailsWithAuditIndividualTypeFlattenFactory( BankDetailsIndividualTypeFlattenFactory ): """Factory to create bank details models with audit attributes for testing.""" modified_at = None name = None class BankDetailsWithAuditObscuredFactory( BankDetailsWithAuditIndividualTypeFlattenFactory ): """Factory to create bank details obscured models with audit attributes for testing.""" account_number = '******6789' sort_code = '1s******' class AddressFactory(factory.DictFactory): address_1 = 'asdf' address_2 = 'dfgh' city = 'odesa' province = 'AZ' country_code = 'US' zip = '65000' class CompanyFactory(factory.DictFactory): name = 'company name' class ContactFactory(factory.DictFactory): first_name = 'firstName' last_name = 'lastName' date_of_birth = '2000-10-10' email = 'test@example.com' phone = '4567890' phone_country = 'US' class PaymentMethodFactory(factory.DictFactory): bank_account_type = 'PERSONAL' country = 'UA' currency = 'UAH' bank_field_details = factory.LazyAttribute( lambda o: [ {'name': 'AccountNumber', 'value': '345234552345'}, {'name': 'AccountName', 'value': 'John Smith'}, {'name': 'BankName', 'value': 'Bank of Hope'}, {'name': 'RoutingNumber', 'value': '122105155'}, {'name': 'AccountType', 'value': 'S'}, ] ) class BankDetailsIndividualTypeNestedFactory(factory.DictFactory): """Factory to create bank details response for testing.""" type = 'INDIVIDUAL' contact = factory.SubFactory(ContactFactory) payout_method = factory.SubFactory(PaymentMethodFactory) address = factory.SubFactory(AddressFactory) class BankDetailsIndividualTypeResponseFactory(BankDetailsIndividualTypeNestedFactory): """Factory to create bank details response for testing account payees.""" payoneer_client_reference_id = '1' account_payee_id = '1' modified_at = None class BankDetailsIndividualPayeeTypeResponseFactory( BankDetailsIndividualTypeNestedFactory ): """Factory to create bank details response for testing payees.""" payoneer_client_reference_id = '00000000-0000-0000-0000-000000000001' account_payee_id = '00000000-0000-0000-0000-000000000001' class BankDetailsCompanyTypeNestedFactory(factory.DictFactory): """Factory to create bank details response for testing.""" type = 'COMPANY' company = factory.SubFactory(CompanyFactory) payout_method = factory.SubFactory(PaymentMethodFactory) address = factory.SubFactory(AddressFactory) class BankDetailsCompanyTypeResponseFactory(BankDetailsIndividualTypeNestedFactory): """Factory to create bank details response for testing.""" payee_id = '1' account_payee_id = '1' class BankDetailsIndividualTypeResponseObscuredFactory( BankDetailsIndividualTypeResponseFactory ): """Factory to create bank details response obscured for testing.""" class PayeeRegistrationFormatOptionsItemFactory(factory.DictFactory): """Factory to payee registration format options item response for testing.""" description = 'options description 1' value = 'possible value 1' class PayeeRegistrationFormatDependentOptionsItemFactory(factory.DictFactory): """Factory to payee registration format dependent options item response for testing.""" name = 'ADS Canadian Bank' options = factory.Dict( { 'items': factory.List( [ factory.SubFactory(PayeeRegistrationFormatOptionsItemFactory), factory.SubFactory( PayeeRegistrationFormatOptionsItemFactory, description='des5', value='val55', ), factory.SubFactory( PayeeRegistrationFormatOptionsItemFactory, description='des7', value='val77', ), ] ) } ) class PayeeRegistrationFormatItemBaseFactory(factory.DictFactory): """Factory to payee registration format response item base fields for testing.""" field_name = 'BankName' field_id = 1 field_type = 'Text' label = 'Bank Name' required = True min_length = 0 max_length = 35 regex = '^[\\.\\(\\)a-zA-Z0-9 &]+$' options_contains_other = False dependent_options_contains_others = False class PayeeRegistrationFormatItemFactory(PayeeRegistrationFormatItemBaseFactory): """Factory to payee registration format response item for testing.""" description = 'Full name of the official bank account holder' watermark = 'e.g. State Bank' options = factory.Dict( { 'items': factory.List( [ factory.SubFactory(PayeeRegistrationFormatOptionsItemFactory), factory.SubFactory( PayeeRegistrationFormatOptionsItemFactory, description='d2', value='pv2', ), factory.SubFactory( PayeeRegistrationFormatOptionsItemFactory, description='d4', value='pv6', ), ] ) } ) dependent_options = factory.Dict( { 'items': factory.List( [ factory.SubFactory( PayeeRegistrationFormatDependentOptionsItemFactory ), factory.SubFactory( PayeeRegistrationFormatDependentOptionsItemFactory, name='Affinity Credit Union', ), ] ) } ) parent_field_id = 1 parent_list_item = 'UniCredit Bank d.d. Mostar' class PayeeRegistrationFormatFieldsFactory(factory.DictFactory): """Factory to payee registration format fields response for testing.""" items = factory.List( [ factory.SubFactory(PayeeRegistrationFormatItemFactory), factory.SubFactory( PayeeRegistrationFormatItemBaseFactory, field_name='AccountName', field_id=2, field_type='Text', label='Account Holder Name', required=True, min_length=0, max_length=70, regex='^[a-zA-Z0-9& ]+$', options_contains_other=False, dependent_options_contains_others=False, ), ] ) class PayeeRegistrationFormatFactory(factory.DictFactory): """Factory to payee registration format response for testing.""" type = 'bank' country = 'AD' currency = 'EUR' bank_account_type = 'PERSONAL' fields = factory.SubFactory(PayeeRegistrationFormatFieldsFactory) class PayeeRegistrationFormatDumpedFactory(factory.DictFactory): """Factory to payee registration format response for testing.""" type = 'bank' bank_country = 'AD' bank_currency = 'EUR' bank_account_type = 'PERSONAL' fields = factory.SubFactory(PayeeRegistrationFormatFieldsFactory) class PayeeRegistrationFormatGetFactory(factory.DictFactory): """Factory to payee registration format request for testing.""" bank_account_type = 'PERSONAL' bank_country = 'AD' bank_currency = 'EUR' class PayeeFactory(BaseModelFactoryWithTimestamps): """Factory to create payee models for testing.""" class Meta: """Meta definition for the factory.""" model = Payee payee_id = 1 reference_payment_type_id = PAYONEER_WHITELABEL_REFERENCE_PAYMENT_TYPE_ID payoneer_client_reference_id = 'uuid' payoneer_program_id = 1 payoneer_assigned_id = 100 payee_name = 'payee' payee_type = PAYEE_TYPES.COLLABORATOR created_by = 'default_user_id' last_modified_by = 'default_user_id' class PayeeCollaboratorFactory(BaseModelFactoryWithTimestamps): """Factory to create payee collaborator models for testing.""" class Meta: """Meta definition for the factory.""" model = PayeeCollaborator payee_collaborator_id = 1 collaborator_id = 1 payee_id = 1 account_id = 1 class AbacusStateFactory(factory.DictFactory): """ABACUS state factory.""" abacus_state_id = factory.fuzzy.FuzzyInteger(low=1, high=999999) action_name = factory.fuzzy.FuzzyText(length=50) action_status = factory.fuzzy.FuzzyText(length=20) message = factory.fuzzy.FuzzyText(length=100) created_at = factory.fuzzy.FuzzyText(length=40) created_by = factory.fuzzy.FuzzyText(length=36) last_modified = factory.fuzzy.FuzzyText(length=40) last_modified_by = factory.fuzzy.FuzzyText(length=36) class TaxWithholdingOverrideFactory(BaseModelFactoryWithTimestamps): """Tax withholding override factory.""" class Meta: """Meta definition for the factory.""" model = TaxWithholdingOverride account_payee_id = 1 rate_override = Decimal('15.50') certificate_expiration_date = datetime.date(2024, 12, 31) message = 'Test message' created_by = 'test_user' created_at = datetime.datetime.now() last_modified_by = 'test_user' last_modified = datetime.datetime.now() class ReportsTaxInfoFactory(BaseModelFactoryWithTimestamps): """Reports tax info factory.""" class Meta: """Meta definition for the factory.""" model = ReportsTaxInfo account_tax_info_history_id = 1 tax_type = TAX_TYPES.DETAILS revision_id = '0' class AccountTaxInfoFactory(BaseModelFactoryWithTimestamps): """Factory to create account_tax_info models for testing.""" class Meta: """Meta definition for the factory.""" model = AccountTaxInfo account_id = 1 country_of_tax_residence = 'USA' is_sba_signed = False is_vat_exempt = True is_tax_treaty_claimed = False is_wht_applicable = True certificate_of_residence_expiration_date = None