"""Unit tests for the Peloton StageLoader.""" from unittest.mock import MagicMock from feed_ingestion.flows.peloton.stage_loader import PelotonSL def test_load_staging_raw_table_loads_whole_stage_once(): """The load runs a single INSERT over the whole stage directory. All country files sit in one archive directory, so - unlike the per-file loop of the base class - the loader executes the load query exactly once, regardless of how many files are reported. """ executor = MagicMock() executor.sf_config = {'db': 'MYDB', 'schema': 'MYSCHEMA'} loader = PelotonSL(executor, sql_loader=MagicMock()) loader.resolve_sql_loader_and_execute = MagicMock() source_files_dict = {'files': [ {'file_name': 'PMY5_M_US_20260501_20260531.txt', 'found': True}, {'file_name': 'PMY5_M_GB_20260501_20260531.txt', 'found': True}, ]} loader.load_staging_raw_table( 'staging_raw_peloton_monthly', source_files_dict, '2026-05-01', 'peloton_stage_20260501') loader.resolve_sql_loader_and_execute.assert_called_once_with( 'load_staging_raw', params=dict( db='MYDB', schema='MYSCHEMA', stage='peloton_stage_20260501', staging_raw_table='staging_raw_peloton_monthly', download_date='2026-05-01'))