"""Configuration for unit tests.""" from collections import namedtuple from contextlib import contextmanager from datetime import date from datetime import datetime from datetime import timedelta from functools import wraps from typing import Any from typing import Callable import pytest from sqlalchemy import delete from starlette.testclient import TestClient from moneyhub.api import create_app from moneyhub.config import Config from moneyhub.connectors.mysql import db from moneyhub.connectors.snowflake import db as snowflake_db from moneyhub.constants.constants import ContractType from moneyhub.constants.constants import JWTKeys from moneyhub.constants.constants import NumberFormat from moneyhub.constants.constants import ReportCustomColumnDimension from moneyhub.constants.constants import ReportCustomFileType from moneyhub.constants.constants import ReportCustomRowDimension from moneyhub.constants.constants import ReportCustomStatus from moneyhub.constants.constants import RevenueType from moneyhub.constants.constants import StatementAttachmentFileType from moneyhub.constants.constants import StatementAttachmentStatus from moneyhub.constants.constants import StatementAttachmentType from moneyhub.models import Expenses from moneyhub.models import ExpensesByArtist from moneyhub.models import ExpensesByImprint from moneyhub.models import Payments from moneyhub.models.mysql_base import BaseModel as Base from moneyhub.models.snowflake_base import BaseModel as SnowflakeBase from moneyhub.schemas.report_custom import ReportCustomFiltersSchema from moneyhub.utils.request import extract_token DISTRIBUTION_FEE_INVOICE = StatementAttachmentType.DISTRIBUTION_FEE_INVOICE SELF_BILLING_INVOICE = StatementAttachmentType.SELF_BILLING_INVOICE REVENUE_DETAIL = StatementAttachmentType.REVENUE_DETAIL class TestConfig(Config): """Test configuration.""" # create all tables for in-memory test database Base.metadata.create_all(db.engine) SnowflakeBase.metadata.create_all(snowflake_db.engine) db.engine.execute('PRAGMA foreign_keys = OFF;') def insert_mock_data(data: dict, database: str = 'mysql'): """Insert mock data into the database tables. The format is a dict where the key is the table to insert into and the value is either a dict or a list of dicts that contain the column:value pairs. Args: data (dict): The data to insert database: database type whether sql or snowflake """ for table_name, entries in data.items(): if database == 'mysql': model = Base.metadata.tables.get(table_name) else: model = SnowflakeBase.metadata.tables.get(table_name) if model is None: raise ValueError(f"Table '{table_name}' does not exist in the database.") if not isinstance(entries, list): entries = [entries] for entry in entries: if database == 'mysql': db.engine.execute(model.insert().values(**entry)) else: snowflake_db.engine.execute(model.insert().values(**entry)) async def override_extract_token_dependency(): """Override extract_token function.""" return { JWTKeys.ORCHARD_IDENTITY_ID: 'me', JWTKeys.PROFILE_ID: 1111, JWTKeys.PROFILE_TYPE: 'MoneyhubProfile', JWTKeys.ROLES: ['role']} def using_mock_snowflake_table( model_class: SnowflakeBase, mock_data: dict | None = None ) -> Callable: """Make a decorator which creates and fills a Snowflake table based off a model. Args: model_class (BaseModel): A model class mock_data (dict | None): Optional mock data to fill the database with Returns: Callable: Decorator function """ def decorator(function: Callable) -> Callable: """Create wrapper function which does the table creation/filling. Args: function (Callable): Function to call Returns: Callable: Wrapper function """ @wraps(function) def wrapper(*args: list, **kwargs: dict) -> Any: """Create and fill the table before calling the function, then remove table. Args: args (list): Argument list kwargs (dict): Keyword arguments Returns: Any: Whatever the wrapped function returns """ # insert data if mock_data: insert_mock_data(mock_data, database='snowflake') try: # Run the test result = function(*args, **kwargs) except Exception as e: raise e # test failures are raised as Exceptions finally: # Commit (to avoid query locks) and then delete the table snowflake_db.session.execute(delete(model_class)) snowflake_db.session.commit() snowflake_db.session.close() return result return wrapper return decorator @pytest.fixture(scope='session', autouse=True) def app(): """Create app fixture.""" app_instance = create_app(TestConfig) app_instance.dependency_overrides[extract_token] = override_extract_token_dependency return app_instance @pytest.fixture(scope='session', autouse=True) def fixture_client(app): """Test client fixture.""" with TestClient(app) as c: yield c @pytest.fixture(autouse=True) def fresh_db(): """Refresh the test database.""" for table in reversed(Base.metadata.sorted_tables): db.session.execute(delete(table)) db.session.commit() db.session.close() @pytest.fixture def latest_statement_invoice_fixture(): """Fixture containing latest statement invoices.""" StatementAttachment = namedtuple( 'StatementAttachment', [ 'statement_attachment_type', 'invoice_number', 'created_at', 'sap_id' ] ) return [ StatementAttachment( DISTRIBUTION_FEE_INVOICE, '4921_2021_0000000002', datetime(2021, 5, 17), '4921' ), StatementAttachment( SELF_BILLING_INVOICE, '1901_2021_SB00000001', datetime(2021, 8, 21), '1901' ), StatementAttachment( REVENUE_DETAIL, None, datetime(2021, 5, 17), '4921' ), StatementAttachment( REVENUE_DETAIL, None, datetime(2021, 8, 21), '1901' ), ] @pytest.fixture def statement_period_accounts_fixture(): """Fixture containing statement period accounts.""" StatementAttachmentAccount = namedtuple( 'StatementPeriodAccount', ['account_id', 'statement_period_id', 'signing_entity_id', 'signing_entity_name', 'sap_id'] ) account_1 = StatementAttachmentAccount(1, 1, 2, 'AWAL Digital Limited (UK)', '4921') account_2 = StatementAttachmentAccount(2, 1, 2, 'AWAL Digital Limited (UK)', '4921') account_3 = StatementAttachmentAccount(3, 1, 2, 'The Orchard', None) return [account_1, account_2, account_3] @pytest.fixture def account_statement_periods_by_account_fixture(): """Fixture containing account statement period data.""" return [ { 'account_id': 77, 'contract_id': None, 'statement_period_id': 270, 'currency_code': 'USD', 'total_gross_revenue_amount': 1416.38, 'total_net_revenue_amount': 1133.10, 'distribution_fee': None, 'mechanical_deduction_total': 0.00, 'mechanical_deduction_admin_fee_total': 0.00, }, { 'account_id': 77, 'contract_id': None, 'statement_period_id': 271, 'currency_code': 'USD', 'total_gross_revenue_amount': 100.10, 'total_net_revenue_amount': 760.80, 'distribution_fee': None, 'mechanical_deduction_total': 0.00, 'mechanical_deduction_admin_fee_total': 0.00, }, ] @pytest.fixture def paginated_account_statement_periods_by_account_fixture(): """Fixture containing account statement period data paginated.""" return { 'items': [ { 'account_id': 77, 'contract_id': None, 'statement_period_id': 270, 'currency_code': 'USD', 'total_gross_revenue_amount': 1416.38, 'total_net_revenue_amount': 1133.10, 'distribution_fee': None, 'mechanical_deduction_total': 0.00, 'mechanical_deduction_admin_fee_total': 0.00, }, { 'account_id': 77, 'contract_id': None, 'statement_period_id': 271, 'currency_code': 'USD', 'total_gross_revenue_amount': 100.10, 'total_net_revenue_amount': 760.80, 'distribution_fee': None, 'mechanical_deduction_total': 0.00, 'mechanical_deduction_admin_fee_total': 0.00, }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 3 } } @pytest.fixture() def report_custom_fixture(): """Return a custom report fixture.""" return { 'report_custom_id': 1, 'account_id': 11111, 'contract_id': None, 'statement_period_ids': '265,266', 'report_custom_status': 'in_progress', 'dimension_column': 'territory', 'dimension_row': 'product', 'revenue_type': 'distribution', 'file_location': 's3://file.csv', 'created_by': 'you', 'created_at': '2022-07-25T17:59:12Z', } @pytest.fixture def contract_fixture(): """Fixture containing contract information.""" return [ { 'term_start': '2022-03-15', 'contract_type': ContractType.DISTRIBUTION, 'term_end': '2023-03-15', 'contract_id': 1001, 'account_id': 24601, 'oa_contract_id': None, 'sap_created_at': None, 'contract_name': 'TEST GDA - GBP - VAT' }, { 'term_start': '2022-03-15', 'contract_type': ContractType.DISTRIBUTION, 'term_end': '2023-03-15', 'contract_id': 2001, 'account_id': 24601, 'oa_contract_id': None, 'sap_created_at': None, 'contract_name': 'TEST GDA - NOK' }, { 'term_start': '2022-03-15', 'contract_type': ContractType.NEIGHBOURING_RIGHTS, 'term_end': '2023-03-15', 'contract_id': 3001, 'account_id': 24602, 'oa_contract_id': None, 'sap_created_at': None, 'contract_name': 'TEST GDA - NOK' } ] def insert_mock_account(account_id=1): """Insert account data.""" insert_mock_data({ 'account': { 'account_id': account_id, 'account_name': f'Test 1 {account_id}', } }) def insert_mock_report_custom( report_custom_id=1, account_id=1, contract_id=1, subaccount_id=None, statement_period_ids='1,2,3', revenue_type=RevenueType.DISTRIBUTION, report_custom_status=ReportCustomStatus.IN_PROGRESS, dimension_column=ReportCustomColumnDimension.TERRITORY, dimension_row=ReportCustomRowDimension.PRODUCT, filters: ReportCustomFiltersSchema | None = None, number_format=NumberFormat.US, file_type=ReportCustomFileType.CSV, file_location=None, created_at=datetime.utcnow() - timedelta(hours=1), created_by='test' ): """Insert report_custom data.""" insert_mock_data({ 'report_custom': { 'report_custom_id': report_custom_id, 'account_id': account_id, 'contract_id': contract_id, 'subaccount_id': subaccount_id, 'statement_period_ids': statement_period_ids, 'revenue_type': revenue_type, 'report_custom_status': report_custom_status, 'dimension_column': dimension_column, 'dimension_row': dimension_row, 'filters': filters, 'number_format': number_format, 'file_type': file_type, 'file_location': file_location, 'created_at': created_at, 'created_by': created_by } }) def insert_mock_statement_period( statement_period_id=1, statement_period_status='closed'): """Insert statement_period data.""" insert_mock_data({ 'statement_period': { 'statement_period_id': statement_period_id, 'statement_period_name': f'Statement Period {statement_period_id}', 'statement_period_status': statement_period_status, } }) def insert_mock_abacus_event(): """Insert abacus_event data.""" insert_mock_data({ 'abacus_event': [ { 'abacus_event_id': 1, 'event_date': date(2020, 1, 1), 'event_name': 'accounting_period_close', 'target_type': 'accounting_period', 'target_id': 1, }, { 'abacus_event_id': 5, 'event_date': date(2020, 1, 4), 'event_name': 'accounting_period_calculate_vat', 'target_type': 'accounting_period', 'target_id': 1, }, ] }) def insert_mock_accounting_run(): """Insert accounting_run data.""" insert_mock_data({ 'accounting_run': [ { 'accounting_run_id': 1, 'accounting_period_id': 1, 'run_controller_id': 1, 'run_status': 'Skipped', }, { 'accounting_run_id': 2, 'accounting_period_id': 1, 'run_controller_id': 1, 'run_status': 'Committed', }, ] }) def insert_mock_accounting_period(): """Insert accounting_period data.""" insert_mock_data({ 'accounting_period': [ { 'accounting_period_id': 1, 'statement_period_id': 1, 'accounting_period_name': 'Jan 20', 'accounting_period_status': 'closed', }, { 'accounting_period_id': 2, 'statement_period_id': 1, 'accounting_period_name': 'Mar 20', 'accounting_period_status': 'closed', }, ] }) def insert_mock_ledger_accounting_run_balance(): """Insert ledger_accounting_run_balance data.""" insert_mock_data({ 'ledger_accounting_run_balance': [ { 'ledger_accounting_run_balance_id': 1, 'accounting_run_id': 2, 'abacus_event_id': 1, 'contract_id': 1, 'currency_code': 'GBP', 'total_gross_revenue_amount': 42.00, 'total_net_revenue_amount': 52.00, 'mechanical_deduction_total': 12.00, 'mechanical_deduction_admin_fee_total': 7.00, 'distribution_fee': 6.30, 'adjusted_net_revenue': 636.00 }, { 'ledger_accounting_run_balance_id': 2, 'accounting_run_id': 2, 'abacus_event_id': 1, 'contract_id': 2, 'currency_code': 'USD', 'total_gross_revenue_amount': 42.00, 'total_net_revenue_amount': 52.00, 'mechanical_deduction_total': 12.00, 'mechanical_deduction_admin_fee_total': 7.00, 'distribution_fee': 6.30, 'adjusted_net_revenue': 636.00 }, { 'ledger_accounting_run_balance_id': 3, 'accounting_run_id': 2, 'abacus_event_id': 1, 'contract_id': 3, 'currency_code': 'AUD', 'total_gross_revenue_amount': 42.00, 'total_net_revenue_amount': 52.00, 'mechanical_deduction_total': 12.00, 'mechanical_deduction_admin_fee_total': 7.00, 'distribution_fee': 6.30, 'adjusted_net_revenue': 636.00 }, ] }) def insert_mock_ledger_account_contract(account_id: int | None = 1): """Insert ledger_account_contract data.""" insert_mock_data({ 'ledger_account_contract': [ { 'ledger_account_contract_id': 1, 'abacus_event_id': 1, 'account_id': account_id, 'contract_id': 1, 'currency_code': 'GBP', 'currency_amount': 5000.00, 'previous_balance': 0.00, 'current_balance': 5000.00, }, { 'ledger_account_contract_id': 2, 'abacus_event_id': 1, 'account_id': account_id, 'contract_id': 2, 'currency_code': 'USD', 'currency_amount': 2000.00, 'previous_balance': 0.00, 'current_balance': 2000.00, }, { 'ledger_account_contract_id': 3, 'abacus_event_id': 1, 'account_id': account_id, 'contract_id': 3, 'currency_code': 'AUD', 'currency_amount': 1000.00, 'previous_balance': 0.00, 'current_balance': 1000.00, }, ] }) def insert_mock_account_payment_terms(): """Insert account_payment_term data.""" insert_mock_data({ 'account_payment_term': [ { 'account_payment_term_id': 1, 'account_id': 1, 'currency_code': 'GBP', 'payment_minimum': 42.00, 'payment_entity_id': 1, 'payment_schedule': None, 'created_by': 'test', 'created_at': datetime(2022, 1, 1, 11, 55, 55), 'last_modified_by': 'test', 'last_modified': datetime(2022, 1, 1, 11, 55, 55), }, { 'account_payment_term_id': 2, 'account_id': 2, 'currency_code': 'GBP', 'payment_minimum': 42.00, 'payment_entity_id': 1, 'payment_schedule': None, 'created_by': 'test', 'created_at': datetime(2022, 1, 1, 11, 55, 55), 'last_modified_by': 'test', 'last_modified': datetime(2022, 1, 1, 11, 55, 55), }, ] }) def insert_mock_ledger_accounting_run_vat(): """Insert ledger_accounting_run_vat data.""" insert_mock_data({ 'ledger_accounting_run_vat': [ { 'ledger_accounting_run_vat_id': 1, 'accounting_run_id': 2, 'abacus_event_id': 5, 'contract_id': 1, 'currency_code': 'GBP', 'country_of_tax_residence': 'USA', 'gross_revenue': 42.00, 'net_revenue': 52.00, 'distribution_fee': 66.00, 'gross_vat_rate': 12.00, 'distribution_vat_rate': 7.00, 'gross_vat': 6.30, 'distribution_vat': 1.0, 'adjusted_net_revenue': 2.0, }, { 'ledger_accounting_run_vat_id': 2, 'accounting_run_id': 2, 'abacus_event_id': 5, 'contract_id': 2, 'currency_code': 'USD', 'country_of_tax_residence': 'USA', 'gross_revenue': 42.00, 'net_revenue': 52.00, 'distribution_fee': 66.00, 'gross_vat_rate': 12.00, 'distribution_vat_rate': 7.00, 'gross_vat': 6.30, 'distribution_vat': 1.0, 'adjusted_net_revenue': 2.0, }, { 'ledger_accounting_run_vat_id': 3, 'accounting_run_id': 2, 'abacus_event_id': 5, 'contract_id': 3, 'currency_code': 'AUD', 'country_of_tax_residence': 'AUS', 'gross_revenue': 42.00, 'net_revenue': 52.00, 'distribution_fee': 66.00, 'gross_vat_rate': 12.00, 'distribution_vat_rate': 7.00, 'gross_vat': 6.30, 'distribution_vat': 1.0, 'adjusted_net_revenue': 2.0, }, ] }) def insert_mock_run_controller(): """Insert run_controller data.""" insert_mock_data({ 'run_controller': { 'run_controller_id': 1, 'run_controller_name': 'foo', }, }) def insert_mock_reference_payment_entity(): """Insert reference payment entity data.""" insert_mock_data({ 'reference_payment_entity': { 'reference_payment_entity_id': 1, 'payment_entity_name': 'The Entity', }, }) def insert_mock_reference_signing_entity(): """Insert reference signing entity data.""" insert_mock_data({ 'reference_signing_entity': { 'reference_signing_entity_id': 1, 'reference_payment_entity_id': 1, 'reference_sap_profit_center_id': 1, 'company_code': '1234', 'tax_entity_company_code': '1234', 'legal_name': 'Company', 'vat_number': '12341234', 'company_registration_number': '12341234', 'address': None, }, }) def insert_mock_reference_sap_profit_center(): """Insert reference sap profit center data.""" insert_mock_data({ 'reference_sap_profit_center': { 'reference_sap_profit_center_id': 1, 'profit_center': 'UK1234', 'company_code': '1234', 'business_group': 'ORC', }, }) def insert_mock_contracts(): """Insert contract data.""" insert_mock_data({ 'contract': [ { 'contract_id': 1, 'reference_signing_entity_id': 1, 'contract_name': 'Test Contract 1', 'contract_type': ContractType.DISTRIBUTION, }, { 'contract_id': 2, 'reference_signing_entity_id': 1, 'contract_name': 'Test Contract 2', 'contract_type': ContractType.NEIGHBOURING_RIGHTS, }, { 'contract_id': 3, 'reference_signing_entity_id': 1, 'contract_name': 'Test Contract 3', 'contract_type': ContractType.DISTRIBUTION, }, { 'contract_id': 4, 'reference_signing_entity_id': 1, 'contract_name': 'Test Contract 4', 'contract_type': ContractType.NEIGHBOURING_RIGHTS, }, ] }) def insert_mock_account_contracts(account_id: int | None = 1): """Insert account_contract data.""" insert_mock_data({ 'account_contract': [ { 'account_id': account_id, 'contract_id': 1, }, { 'account_id': account_id, 'contract_id': 2, }, { 'account_id': account_id, 'contract_id': 3, }, { 'account_id': 2, 'contract_id': 4, }, ] }) def insert_mock_run_controller_contract(): """Insert run_controller_contract data.""" insert_mock_data({ 'run_controller_contract': [ { 'run_controller_id': 1, 'contract_id': 1, }, { 'run_controller_id': 2, 'contract_id': 2, }, { 'run_controller_id': 3, 'contract_id': 3, }, { 'run_controller_id': 4, 'contract_id': 4, }, ] }) def insert_mock_statement_attachment( account_id=1, contract_id=1, statement_period_id=1, invoice_number='test1234', file_location=None): """Insert mock statement attachment data.""" insert_mock_data({ 'statement_attachment': { 'account_id': account_id, 'contract_id': contract_id, 'statement_period_id': statement_period_id, 'invoice_number': invoice_number, 'file_location': file_location, 'file_type': StatementAttachmentFileType.PDF, 'statement_attachment_status': StatementAttachmentStatus.IN_PROGRESS, 'statement_attachment_type': StatementAttachmentType.DISTRIBUTION_FEE_INVOICE, 'created_at': '2010-09-08 07:06:05', 'created_by': 'me', }, }) def insert_mock_account_statement_period_payments(): """Mock data for payments.""" account_id = 10 statement_period_id = 20 abacus_event_id = 30 abacus_wht_event_id = 35 abacus_credit_event_id = 40 insert_mock_account(account_id) insert_mock_statement_period(statement_period_id) insert_mock_reference_payment_entity() insert_mock_reference_signing_entity() insert_mock_reference_sap_profit_center() insert_mock_contracts() insert_mock_data({ 'payment_group': {'payment_group_id': 1}, 'payment_group_payment': { 'payment_group_payment_id': 2, 'payment_group_id': 1, 'statement_period_id': statement_period_id, }, 'payment_group_payment_account': { 'payment_group_payment_account_id': 1, 'payment_group_payment_id': 2, 'account_id': account_id, 'current_statement_period_id': statement_period_id, }, 'abacus_state': { 'abacus_state_id': 20, 'parent_table_id': 1, 'parent_table_name': 'payment_group_payment_account', 'action_status': 'complete', }, 'abacus_event': [ { 'abacus_event_id': abacus_event_id, 'statement_period_id': statement_period_id, 'event_date': '2020-01-01', 'event_name': 'send_payments', 'target_type': 'payment_group_payment', 'target_id': 2, }, { 'abacus_event_id': abacus_credit_event_id, 'statement_period_id': statement_period_id, 'event_date': '2020-01-01', 'event_name': 'payment_returned', 'target_type': 'payment_group_payment_account', 'target_id': 2, }, { 'abacus_event_id': abacus_event_id + 1, 'statement_period_id': statement_period_id, 'event_date': '2020-01-01', 'event_name': 'send_payments', 'target_type': 'payment_group_payment', 'target_id': 3, }, { 'abacus_event_id': abacus_wht_event_id, 'statement_period_id': statement_period_id, 'event_date': '2020-01-01', 'event_name': 'tax_withholding', 'target_type': 'payment_group_payment', 'target_id': 2, }, ], 'ledger_account_contract': [ { 'ledger_account_contract_id': 1, 'abacus_event_id': abacus_event_id, 'account_id': account_id, 'contract_id': 1, 'currency_code': 'USD', 'currency_amount': -5000.00, 'previous_balance': 10000.00, 'current_balance': 5000.00, 'created_by': 'me', 'created_at': '2022-01-01 11:55:55', }, { 'ledger_account_contract_id': 2, 'abacus_event_id': abacus_event_id + 1, 'account_id': account_id, 'contract_id': 2, 'currency_code': 'USD', 'currency_amount': -2000.00, 'previous_balance': 4000.00, 'current_balance': 2000.00, 'created_by': 'me', 'created_at': '2022-01-02 12:11:15', }, { 'ledger_account_contract_id': 3, 'abacus_event_id': abacus_wht_event_id, 'account_id': account_id, 'contract_id': 2, 'currency_code': 'USD', 'currency_amount': -1000.00, 'previous_balance': 5000.00, 'current_balance': 4000.00, 'created_by': 'me', 'created_at': '2022-01-01 11:55:55', }, { 'ledger_account_contract_id': 4, 'abacus_event_id': abacus_credit_event_id, 'account_id': account_id, 'contract_id': 1, 'currency_code': 'USD', 'currency_amount': -2000.00, 'previous_balance': 4000.00, 'current_balance': 2000.00, 'created_by': 'me', 'created_at': '2022-01-02 12:11:15', }, ], }) def insert_mock_vw_account_statement_period_data(): """Create the records required for vw_account_statement_period.""" insert_mock_account(1) insert_mock_account(2) insert_mock_statement_period() insert_mock_abacus_event() insert_mock_run_controller() insert_mock_accounting_period() insert_mock_accounting_run() insert_mock_reference_payment_entity() insert_mock_reference_signing_entity() insert_mock_account_payment_terms() insert_mock_reference_sap_profit_center() insert_mock_contracts() insert_mock_account_contracts() insert_mock_run_controller_contract() insert_mock_ledger_account_contract() insert_mock_ledger_accounting_run_balance() insert_mock_ledger_accounting_run_vat() @contextmanager def _using_mock_expenses_data(mock_data: dict): """Create the necessary mock tables and fills them with the data. Args: mock_data (dict): Data to enter. """ ExpensesByArtist.__table__.drop(db.engine, checkfirst=True) ExpensesByImprint.__table__.drop(db.engine, checkfirst=True) Expenses.__table__.drop(db.engine, checkfirst=True) db.session.commit() ExpensesByArtist.__table__.create(db.engine) ExpensesByImprint.__table__.create(db.engine) Expenses.__table__.create(db.engine) insert_mock_data(mock_data) yield db.session.commit() ExpensesByArtist.__table__.drop(db.engine) ExpensesByImprint.__table__.drop(db.engine) Expenses.__table__.drop(db.engine) db.session.close() @contextmanager def _using_mock_account_statements_data(mock_data: dict): """Create the necessary mock tables and fills them with the data. Args: mock_data (dict): Data to enter. """ Payments.__table__.drop(db.engine, checkfirst=True) db.session.commit() Payments.__table__.create(db.engine) insert_mock_data(mock_data) yield db.session.commit() Payments.__table__.drop(db.engine) db.session.close()