"""Seed data builders for custom_reports lambda integration tests.""" from datetime import datetime from pathlib import Path from typing import Any from tests import config # tests must run from the tests/ directory FIXTURE_REPORTS_DIR = Path('src/fixture_reports') def _make_seed( *, account_id: int, contract_id: int | None, statement_period_ids: str, revenue_type: str, dimension_row: str, dimension_column: str, file_type: str = 'csv', subaccount_id: int | None = None, filters: str | None = None, number_format: str = 'us', fixture_file_path: Path | None = None, expected_filename: str | None = None, ) -> dict[str, Any]: resolved_filename = expected_filename or ( fixture_file_path.stem if fixture_file_path else None ) data: dict[str, Any] = { 'account_id': account_id, 'contract_id': contract_id, 'subaccount_id': subaccount_id, 'statement_period_ids': statement_period_ids, 'revenue_type': revenue_type, 'dimension_row': dimension_row, 'dimension_column': dimension_column, 'filters': filters, 'number_format': number_format, 'fixture_file_path': fixture_file_path, 'expected_filename': resolved_filename, 'file_type': file_type, 'report_custom_status': 'in_progress', 'created_by': config.TEST_USER, 'created_at': datetime.now(), } return data def seed_data_distribution_by_territory() -> dict[str, Any]: """Distribution report grouped by territory × statement_period (get_report_data, REVENUE_DISTRO_DBT).""" filename = 'report_7378_323332_may-to-dec2025_territory_statement_period' return _make_seed( account_id=7378, contract_id=323332, statement_period_ids='317,318,319,320,321,322,323,324', revenue_type='distribution', dimension_row='statement_period', dimension_column='territory', file_type='csv', fixture_file_path=(FIXTURE_REPORTS_DIR / 'custom_reports' / f'{filename}.csv'), ) def seed_data_distribution_track_by_statement_period() -> dict[str, Any]: """Distribution report grouped by track × statement_period.""" filename = 'report_7378_323332_may-to-dec2025_statement_period_track' return _make_seed( account_id=7378, contract_id=323332, statement_period_ids='317,318,319,320,321,322,323,324', revenue_type='distribution', dimension_row='track', dimension_column='statement_period', file_type='csv', fixture_file_path=(FIXTURE_REPORTS_DIR / 'custom_reports' / f'{filename}.csv'), ) def seed_data_nr_financial_detail() -> dict[str, Any]: """NR report using financial_detail × territory (get_report_data_financial_detail, REVENUE_NR_DBT).""" filename = 'report_68273_533767_may-to-dec2025_financial_detail_territory' return _make_seed( account_id=68273, contract_id=533767, statement_period_ids='317,318,319,320,321,322,323,324', revenue_type='neighbouring_rights', dimension_row='territory', dimension_column='financial_detail', file_type='csv', fixture_file_path=(FIXTURE_REPORTS_DIR / 'custom_reports' / f'{filename}.csv'), ) def seed_data_nr_territory_statement_period() -> dict[str, Any]: """NR report grouped by territory × statement_period (get_report_data, REVENUE_NR_DBT).""" filename = 'report_68273_533767_may-to-dec2025_territory_statement_period' return _make_seed( account_id=68273, contract_id=533767, statement_period_ids='317,318,319,320,321,322,323,324', revenue_type='neighbouring_rights', dimension_row='statement_period', dimension_column='territory', file_type='csv', fixture_file_path=(FIXTURE_REPORTS_DIR / 'custom_reports' / f'{filename}.csv'), ) def seed_data_invalid_statement_periods() -> dict[str, Any]: """Error case: statement_period_ids that don't exist, so get_statement_periods_parsed() returns None and raises CustomReportException.""" return _make_seed( account_id=7378, contract_id=323332, statement_period_ids='999999998,999999999', revenue_type='distribution', dimension_row='statement_period', dimension_column='territory', file_type='csv', )