"""Shared fixtures for tests.""" import os from uuid import uuid4 import pytest from sqlalchemy import text from payment.api import create_app, db from payment.config import Config from payment.models import PaymentGroupPaymentAccount from tests.utils.auth import MockJWTAuth from tests.utils.factories import ( PaymentGroupPaymentAccountDetailFactory, PaymentGroupPaymentAccountFactory, PaymentGroupPaymentBatchAccountFactory, PaymentGroupPaymentBatchFactory, PaymentGroupPaymentFactory, WorksheetAccountContractClosingBalanceFactory, WorksheetPayableBalanceAfterTaxFactory, ) Config.ENVIRONMENT = 'test' Config.PAYMENT_ALLOCATION_IDENTITIES = [str(uuid4())] def _exec_sql(sql): """Execute raw SQL using SA2-compatible engine.connect().""" with db.engine.connect() as conn: conn.execute(text(sql)) conn.commit() class TestConfig(Config): """Test configuration.""" MYSQL_DB_NAME = os.environ.get('MYSQL_TEST_DB_NAME', Config.MYSQL_DB_NAME + '_test') AUDIT_LOG_ES_ENDPOINT = None @pytest.fixture(scope='session', autouse=True) def test_app(): """Create a test application.""" return create_app(TestConfig) @pytest.fixture(autouse=True) def test_app_in_context(test_app): """Push the test app onto the context.""" with test_app.app_context(): yield test_app @pytest.fixture(autouse=True) def test_app_request(test_app_in_context): """Push the test app onto the context and trigger preprocessing.""" with test_app_in_context.test_request_context(): test_app_in_context.preprocess_request() yield test_app_in_context @pytest.fixture def fixture_client(test_app_in_context): """Create a client fixture.""" with test_app_in_context.test_client() as test_client: yield test_client @pytest.fixture def fresh_db(): """Refresh the test database.""" top_level_tables = ( 'abacus_state', 'abacus_event', 'account', 'account_payee', 'account_payment_term', 'payment_group', 'payment_group_payment', 'payment_group_payment_account', 'payment_group_payment_account_detail', 'payment_group_payment_batch', 'payment_group_payment_batch_account', 'payment_minimum', 'reference_tax_withholding', 'reference_payoneer_program', 'report_payment_group_payment', 'statement_period', 'worksheet_payment_contract_advance', 'worksheet_payment_custom', 'exchange_rate', 'contract_advance', 'contract', 'reference_payment_entity', 'reference_signing_entity', 'worksheet_account_contract_closing_balance', 'ledger_account_contract', 'worksheet_account_contract_payable_after_tax', 'worksheet_account_contract_payable_details', 'worksheet_account_contract_taxable_revenue', 'worksheet_tax_correction', 'worksheet_tax_correction_vat', 'report_payment', 'payment_allocation', ) tables_statements = '\n'.join([f'TRUNCATE {table};' for table in top_level_tables]) statements = ( f'SET FOREIGN_KEY_CHECKS=0;\n{tables_statements}\nSET FOREIGN_KEY_CHECKS=1;' ) _exec_sql(statements) @pytest.fixture def mock_worksheet_account_contract_closing_balance(mock_ledger_account_contracts): """Insert mock worksheet_account_contract_closing_balance.""" sql = """ INSERT INTO `worksheet_account_contract_closing_balance`( `worksheet_account_contract_closing_balance_id`, `account_id`, `contract_id`, `reference_payment_entity_id`, `abacus_event_id`, `statement_period_id`, `ledger_account_contract_id`, `currency_code`, `amount`, `includes_tax_adjustments`, `created_at`, `created_by`, `last_modified`, `last_modified_by`, `deleted_at`, `deleted_by` ) VALUES (1, 1, 1, 1, 1, 2, 1, 'USD', '100.00', 0, '2022-01-01', 'test', '2022-01-01', 'test', '2022-01-01', 'test'), (2, 1, 2, 1, 1, 2, 1, 'USD', '100.00', 0, '2022-01-01', 'test', '2022-01-01', 'test', '2022-01-01', 'test') """ # noqa _exec_sql(sql) @pytest.fixture def mock_worksheet_account_contract_closing_balance_active( mock_ledger_account_contracts, ): """Insert mock worksheet_account_contract_closing_balance with active records.""" sql = """ INSERT INTO `worksheet_account_contract_closing_balance`( `worksheet_account_contract_closing_balance_id`, `account_id`, `contract_id`, `reference_payment_entity_id`, `abacus_event_id`, `statement_period_id`, `ledger_account_contract_id`, `currency_code`, `amount`, `includes_tax_adjustments`, `created_at`, `created_by`, `last_modified`, `last_modified_by`, `deleted_at`, `deleted_by` ) VALUES (1, 1, 1, 1, 1, 2, 1, 'USD', '100.00', 0, '2022-01-01', 'test', '2022-01-01', 'test', NULL, NULL), (2, 1, 2, 1, 1, 2, 1, 'USD', '100.00', 0, '2022-01-01', 'test', '2022-01-01', 'test', NULL, NULL) """ # noqa _exec_sql(sql) @pytest.fixture def mock_worksheet_account_contract_payable_after_tax( mock_worksheet_account_contract_closing_balance, ): """Insert mock worksheet_account_contract_payable_after_tax.""" sql = """ INSERT INTO `worksheet_account_contract_payable_after_tax`( `worksheet_account_contract_payable_after_tax_id`, `worksheet_account_contract_closing_balance_id`, `account_id`, `contract_id`, `abacus_event_id`, `statement_period_id`, `payable_amount_pre_tax`, `tax_withholding_amount`, `payable_amount_post_tax`, `currency_code`, `country_of_tax_residence`, `country_of_tax_policy`, `created_at`, `created_by`, `last_modified`, `last_modified_by`, `deleted_at`, `deleted_by` ) VALUES (1, 1, 1, 1, 1, 2, '100.00', '10.00', '90.00', 'USD', 'UK', 'UK', '2022-01-01', 'test', '2022-01-01', 'test', '2022-01-01', 'test'), (2, 2, 2, 1, 1, 2, '50.00', '5.00', '45.00', 'USD', 'UK', 'UK', '2022-01-01', 'test', '2022-01-01', 'test', '2022-01-01', 'test') """ # noqa _exec_sql(sql) @pytest.fixture def mock_accounts(mock_reference_payoneer_program): """Create mock accounts.""" account_insert = """ INSERT INTO account( account_id, account_name, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 'Account 1', 'dana', NOW(), 'dana', NOW()), (2, 'Account 2', 'dana', NOW(), 'dana', NOW()), (3, 'Account 3', 'dana', NOW(), 'dana', NOW()), (4, 'Account 4', 'igor', NOW(), 'igor', NOW()), (5, 'Account 5', 'aarti', NOW(), 'aarti', NOW()), (6, 'Account 6', 'aarti', NOW(), 'aarti', NOW()), (7, 'Account 7', 'aarti', NOW(), 'aarti', NOW()), (8, 'Account 8', 'aarti', NOW(), 'aarti', NOW()), (9, 'Account 9', 'aarti', NOW(), 'aarti', NOW()); """ _exec_sql(account_insert) @pytest.fixture def mock_reference_payoneer_program(): """Create mock reference_payoneer_program.""" reference_payoneer_program_insert = """ INSERT INTO reference_payoneer_program( payoneer_program_id, payoneer_program_name, funding_currency, reference_payment_type_id ) VALUES ('100158970', 'test_name', 'USD', 3), ('1001', 'test_name', 'AUS', 3), ('0', 'sap', 'USD', 3); """ _exec_sql(reference_payoneer_program_insert) @pytest.fixture def mock_account_payees(): """Create mock account payees.""" account_payee_insert = """ INSERT INTO account_payee( account_payee_id, account_id, payoneer_payee_id, payoneer_program_id, payoneer_payee_name, payoneer_iframe_url, payoneer_iframe_url_date, payoneer_session_id, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 1, 1, '100158970', NULL, NULL, NULL, NULL, 'Test', NOW(), 'Test', NOW()), (2, 2, 2, '100158970', NULL, NULL, NULL, NULL, 'Test', NOW(), 'Test', NOW()), (3, 3, 3, '1001', NULL, NULL, NULL, NULL, 'Test', NOW(), 'Test', NOW()), (4, 4, 4, '1001', NULL, NULL, NULL, NULL, 'Test', NOW(), 'Test', NOW()), (5, 5, 4, '1001', NULL, NULL, NULL, NULL, 'Test', NOW(), 'Test', NOW()), (6, 6, 4, '1001', NULL, NULL, NULL, NULL, 'Test', NOW(), 'Test', NOW()), (7, 7, 4, '1001', NULL, NULL, NULL, NULL, 'Test', NOW(), 'Test', NOW()), (8, 8, 4, '1001', NULL, NULL, NULL, NULL, 'Test', NOW(), 'Test', NOW()); """ _exec_sql(account_payee_insert) @pytest.fixture def create_mock_payment_state(): """Create mock abacus-state for payments.""" SQL_QUERY = """ INSERT INTO abacus_state( `parent_table_name`, `parent_table_id`, `action_name`, `action_status`, `message`, `created_by`, `created_at`, `last_modified_by`, `last_modified` ) VALUES ('payment_group_payment', 1, 'generate_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 1, 'generate_export', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 1, 'upload_approval', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 1, 'send_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 2, 'generate_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 2, 'generate_export', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 2, 'upload_approval', 'init', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 2, 'send_payments', 'init', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 3, 'send_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_account', 1, 'send_payments', 'init', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_account', 2, 'send_payments', 'init', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_account', 3, 'send_payments', 'rejected', 'Payment Rejected', '2', NOW(), '2', NOW()), ('payment_group_payment_account', 4, 'send_payments', 'init', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_account', 5, 'send_payments', 'running', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_account', 6, 'send_payments', 'error', 'Insufficient Funds', '2', NOW(), '2', NOW()), ('payment_group_payment_account', 7, 'send_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_account', 9, 'send_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_account', 10, 'send_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_batch', 1, 'send_payment', 'error', 'Batch Failed', '2', NOW(), '2', NOW()), ('payment_group_payment_batch', 2, 'send_payment', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_batch', 3, 'send_payment', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_batch', 4, 'send_payment', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_batch', 5, 'send_payment', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment_batch', 6, 'send_payment', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 501, 'generate_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 501, 'generate_export', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 501, 'upload_approval', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 501, 'send_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('payment_group_payment', 502, 'send_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('worksheet_payment_contract_advance', 1, 'send_payments', 'init', NULL, '2', NOW(), '2', NOW()), ('worksheet_payment_contract_advance', 2, 'send_payments', 'complete', NULL, '2', NOW(), '2', NOW()), ('worksheet_payment_contract_advance', 3, 'send_payments', 'rejected', NULL, '2', NOW(), '2', NOW()) """ _exec_sql(SQL_QUERY) @pytest.fixture def mock_abacus_event(): """Insert abacus_event fixtures directly into the DB.""" sql = """ INSERT INTO `abacus_event` ( `abacus_event_id`, `statement_period_id`, `event_name`, `target_type`, `target_id`, `event_date`, `previous_abacus_event_id`, `rolled_back_at`, `created_by` ) VALUES (1, 1, 'payment_group_payment', 'payment_group_payment', 1, '2022-01-01', NULL, NULL, 'default_user_id'), (2, 1, 'payment_group_payment', 'payment_group_payment', 2, '2022-01-01', NULL, NULL, 'default_user_id'), (3, 1, 'payment_group_payment', 'payment_group_payment', 3, '2022-01-01', NULL, NULL, 'default_user_id'), (4, 1, 'payment_group_payment', 'payment_group_payment', 4, '2022-01-01', NULL, NULL, 'default_user_id'), (5, 1, 'payment_group_payment', 'payment_group_payment', 5, '2022-01-01', NULL, NULL, 'default_user_id'), (6, 1, 'payment_group_payment', 'payment_group_payment', 6, '2022-01-01', NULL, NULL, 'default_user_id'), (7, 1, 'payment_group_payment', 'payment_group_payment', 7, '2022-01-01', NULL, NULL, 'default_user_id'), (8, 1, 'payment_group_payment', 'payment_group_payment', 8, '2022-01-01', NULL, NULL, 'default_user_id'), (9, 1, 'payment_group_payment', 'payment_group_payment', 9, '2022-01-01', NULL, NULL, 'default_user_id'), (10, 1, 'payment_group_payment', 'payment_group_payment', 10, '2022-01-01', NULL, NULL, 'default_user_id'), (11, 1, 'payment_group_payment', 'payment_group_payment', 11, '2022-01-01', NULL, NULL, 'default_user_id'), (12, 1, 'payment_group_payment', 'payment_group_payment', 12, '2022-01-01', NULL, NULL, 'default_user_id'), (13, 1, 'payment_group_payment', 'payment_group_payment', 13, '2022-01-01', NULL, NULL, 'default_user_id'), (14, 1, 'payment_group_payment', 'payment_group_payment', 14, '2022-01-01', NULL, NULL, 'default_user_id') """ # noqa _exec_sql(sql) @pytest.fixture def payment_minimum_fixtures(): """Insert payment minimum fixtures directly into the DB.""" sql = """ INSERT INTO `payment_minimum` ( currency_code, check_amount, wire_transfer_amount, western_union_amount, created_by, created_at, last_modified_by, last_modified ) VALUES ('USD', 10, 20, 30, '', NOW(), '', NOW()), ('EUR', 10, 20, 30, '', NOW(), '', NOW()), ('GBP', 10, 20, 30, '', NOW(), '', NOW()) """ _exec_sql(sql) @pytest.fixture def mock_account_payment_terms(): """Insert Account Payment Term test data into the DB.""" sql = """ INSERT INTO `account_payment_term`( account_id, currency_code, payment_entity_id, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 'GBP', 1, '', NOW(), '', NOW()), (2, 'GBP', 1, '', NOW(), '', NOW()), (3, 'GBP', 1, '', NOW(), '', NOW()), (4, 'GBP', 1, '', NOW(), '', NOW()) """ _exec_sql(sql) @pytest.fixture def mock_statement_periods(): """Insert Statement Period test data into the DB.""" sql = """ INSERT INTO `statement_period`( statement_period_id, statement_period_name, statement_period_status, closed_date, closed_by ) VALUES (1, 'Month 1', 'closed', '2022-01-01', 'default_user_id'), (2, 'Month 2', 'closed', '2022-02-01', 'default_user_id'), (3, 'Month 3', 'current', NULL, NULL), (4, 'Month 4', 'open', NULL, NULL), (5, 'Month 5', 'open', NULL, NULL), (6, 'Month 5', 'open', NULL, NULL), (7, 'Month 5', 'open', NULL, NULL), (8, 'Month 5', 'open', NULL, NULL) """ _exec_sql(sql) @pytest.fixture def mock_ledger_account_contracts(): """Insert Ledger Account Contract test data into the DB.""" sql = """ INSERT INTO `ledger_account_contract`( ledger_account_contract_id, abacus_event_id, account_id, contract_id, currency_code, currency_amount, previous_balance, current_balance, note, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 1, 1, 1, 'USD', '1000.00', '0.00', '1000.00', 'note', 'default_user_id', '2022-01-01', 'default_user_id', '2022-01-01'), (2, 2, 1, 2, 'USD', '1000.00', '0.00', '1000.00', 'note', 'default_user_id', '2022-01-01', 'default_user_id', '2022-01-01') """ _exec_sql(sql) @pytest.fixture def mock_contracts(mock_signing_entities): """Insert Contract test data into the DB.""" sql = """ INSERT INTO `contract`( contract_id, reference_signing_entity_id, reference_sap_profit_center_id, contract_name, contract_type, sap_created_at, summary_note, general_note, term_start, term_end, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 1, 1, 'TEST', 'distribution', NULL, NULL, NULL, '2022-03-15', '2023-03-15', 'default_account', '2022-03-02 00:01:08', 'default_account', '2022-04-18 15:53:09'), (2, 1, 1, 'TEST 2', 'distribution', NULL, NULL, NULL, '2022-03-15', '2023-03-15', 'default_account', '2022-03-02 00:01:08', 'default_account', '2022-04-18 15:53:09'), (3, 1, 1, 'TEST 3', 'distribution', NULL, NULL, NULL, '2022-03-15', '2023-03-15', 'default_account', '2022-03-02 00:01:08', 'default_account', '2022-04-18 15:53:09'), (4, 1, 1, 'TEST 4', 'distribution', NULL, NULL, NULL, '2022-03-15', '2023-03-15', 'default_account', '2022-03-02 00:01:08', 'default_account', '2022-04-18 15:53:09'), (5, 1, 1, 'TEST 5', 'distribution', NULL, NULL, NULL, '2022-03-15', '2023-03-15', 'default_account', '2022-03-02 00:01:08', 'default_account', '2022-04-18 15:53:09'), (6, 1, 1, 'TEST 5', 'distribution', NULL, NULL, NULL, '2022-03-15', '2023-03-15', 'default_account', '2022-03-02 00:01:08', 'default_account', '2022-04-18 15:53:09'), (7, 1, 1, 'TEST 5', 'distribution', NULL, NULL, NULL, '2022-03-15', '2023-03-15', 'default_account', '2022-03-02 00:01:08', 'default_account', '2022-04-18 15:53:09'), (8, 1, 1, 'TEST 5', 'distribution', NULL, NULL, NULL, '2022-03-15', '2023-03-15', 'default_account', '2022-03-02 00:01:08', 'default_account', '2022-04-18 15:53:09') """ # noqa _exec_sql(sql) @pytest.fixture def mock_exchange_rates(): """Insert Exchange Rate test data into the DB.""" sql = """ INSERT INTO `exchange_rate`( exchange_rate_id, statement_period_id, rate, from_currency_code, to_currency_code, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 1, '1.4991820000000000000', 'USD', 'AUD', 'default_user_id', '2022-10-11', 'default_user_id', '2022-10-11'), (2, 1, '1.3335180000000000000', 'USD', 'CAD', 'default_user_id', '2022-10-11', 'default_user_id', '2022-10-11'), (3, 1, '0.9735590000000000000', 'USD', 'CHF', 'default_user_id', '2022-10-11', 'default_user_id', '2022-10-11') """ # noqa _exec_sql(sql) @pytest.fixture def mock_signing_entities(): """Create signing_entities in the database.""" SQL_INSERT = """ INSERT INTO `reference_payment_entity`( reference_payment_entity_id, payment_entity_name, country_of_tax_reporting, created_by, created_at, last_modified_by, last_modified ) VALUES (1, 'AWAL-UK', 'GBR', 'test', NOW(), 'test', NOW()); """ _exec_sql(SQL_INSERT) SQL_INSERT = """ INSERT INTO `reference_signing_entity`( reference_signing_entity_id, reference_payment_entity_id, reference_sap_profit_center_id, company_code, legal_name, vat_number, company_registration_number, address ) VALUES ( 1, 1, 1, 4914, 'AWAL Digital Limited', 'GB 423 4787 86', '04430703', '2 Canal Reach, London, N1C 4DB' ); """ _exec_sql(SQL_INSERT) @pytest.fixture def mock_contract(mock_signing_entities): """Insert Contract test data into DB.""" sql = """ INSERT INTO `contract`( contract_id, reference_signing_entity_id, reference_sap_profit_center_id, contract_name, contract_type, sap_created_at, summary_note, general_note, term_start, term_end, created_by, created_at, last_modified_by, last_modified ) VALUES (1,1,1,'TEST','distribution',NULL,NULL,NULL,'2022-03-15','2023-03-15','default_account','2022-03-02 00:01:08','default_account','2022-04-18 15:53:09') """ # noqa _exec_sql(sql) @pytest.fixture def mock_contract_advance(mock_contract): """Insert Contract Advance test data into DB.""" sql = """ INSERT INTO `contract_advance`( contract_advance_id, contract_id, reference_payment_type_id, reference_advance_payment_method_id, advance_description, amount, vat_amount, withholding_tax_amount, amount_after_withholding_and_vat, us_source_income_rate, currency_code, milestone, milestone_description, milestone_date, advance_status, note, created_by, created_at, last_modified_by, last_modified ) VALUES (1,1,NULL,NULL,'Test advance', '1000.00','200.00', '-100.00', '1100.00', '50.00', 'USD', 'contract_execution', 'Milestone finish', '2024-01-10', 'qualified', 'note', 'default_user', '2024-01-10 11:59:12.0', 'default_user', '2024-01-10 11:59:12.0'), (2,1,NULL,NULL,'Test advance 2', '1000.00','200.00', '-100.00', '1100.00', '50.00', 'USD', 'contract_execution', 'Milestone finish', '2024-01-10', 'qualified', 'note', 'default_user', '2024-01-10 11:59:12.0', 'default_user', '2024-01-10 11:59:12.0') """ # noqa _exec_sql(sql) @pytest.fixture def mock_payments( mock_accounts, mock_account_payees, create_mock_payment_state, mock_contracts, mock_abacus_event, mock_ledger_account_contracts, ): """Mock payments for accounts.""" payment_group_payment = PaymentGroupPaymentFactory.create( payment_group_payment_id=501 ) payment_accounts_100158970 = [ PaymentGroupPaymentAccountFactory.create( payment_group_payment_account_id=i, account_id=i, payoneer_program_id=100158970, payment_group_payment=payment_group_payment, ) for i in range(1, 3) ] payment_accounts_1001 = [ PaymentGroupPaymentAccountFactory.create( payment_group_payment_account_id=i, account_id=i, payoneer_program_id=1001, payment_group_payment=payment_group_payment, ) for i in range(3, 8) ] PaymentGroupPaymentAccountFactory.create( payment_group_payment_account_id=8, account_id=8, payoneer_program_id=1001, payment_group_payment=payment_group_payment, ) [ WorksheetAccountContractClosingBalanceFactory.create( worksheet_account_contract_closing_balance_id=i, account_id=i, contract_id=i, ) for i in range(1, 9) ] [ WorksheetPayableBalanceAfterTaxFactory.create( worksheet_account_contract_payable_after_tax_id=i, account_id=i, contract_id=i, ) for i in range(1, 9) ] [ PaymentGroupPaymentAccountDetailFactory.create( payment_group_payment_account=PaymentGroupPaymentAccount.get_by_id(i), account_id=i, contract_id=i, worksheet_account_contract_payable_after_tax_id=i, ) for i in range(1, 9) ] payment_batch_100158970 = PaymentGroupPaymentBatchFactory.create( payment_group_payment_batch_id=1, batch_num=1, payment_group_payment=payment_group_payment, payoneer_program_id=100158970, ) payment_batch_1001 = [ PaymentGroupPaymentBatchFactory.create( payment_group_payment_batch_id=i, batch_num=i, payment_group_payment=payment_group_payment, payoneer_program_id=1001, ) for i in range(2, 4) ] [ PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_account=payment_account, payment_group_payment_batch=payment_batch_100158970, ) for payment_account in payment_accounts_100158970 ] [ PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_account=payment_accounts_1001[i], payment_group_payment_batch=payment_batch_1001[0], ) for i in range(0, 3) ] [ PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_account=payment_accounts_1001[i], payment_group_payment_batch=payment_batch_1001[1], ) for i in range(3, len(payment_accounts_1001)) ] @pytest.fixture def mock_payments_knr(mock_accounts, mock_account_payees, create_mock_payment_state): """Mock payments for KNR accounts.""" payment_group_payment_knr = PaymentGroupPaymentFactory.create( payment_group_payment_id=502 ) payment_group_payment_account = PaymentGroupPaymentAccountFactory.create( payment_group_payment_account_id=9, account_id=9, payoneer_program_id=0, payment_group_payment=payment_group_payment_knr, ) payment_group_payment_batch = PaymentGroupPaymentBatchFactory.create( payment_group_payment_batch_id=5, batch_num=1, payment_group_payment=payment_group_payment_knr, payoneer_program_id=0, ) PaymentGroupPaymentBatchAccountFactory.create( payment_group_payment_account=payment_group_payment_account, payment_group_payment_batch=payment_group_payment_batch, ) @pytest.fixture def mock_jwt_auth(test_app): """Return mocked JWTAuth client.""" mock_jwtauth = MockJWTAuth() test_app.jwt_auth_client = mock_jwtauth return mock_jwtauth