88from datetime import datetime , timedelta , timezone
99from pathlib import Path
1010from typing import Any , Iterable , Mapping , Optional , Union
11+ from unittest .mock import Mock
1112
1213import freezegun
1314import pytest
170171)
171172from airbyte_cdk .sources .declarative .yaml_declarative_source import YamlDeclarativeSource
172173from airbyte_cdk .sources .message .repository import StateFilteringMessageRepository
173- from airbyte_cdk .sources .streams .call_rate import MovingWindowCallRatePolicy
174+ from airbyte_cdk .sources .streams .call_rate import APIBudget , MovingWindowCallRatePolicy
174175from airbyte_cdk .sources .streams .concurrent .clamping import (
175176 ClampingEndProvider ,
176177 DayClampingStrategy ,
@@ -744,7 +745,26 @@ def test_create_substream_partition_router():
744745 "" , resolved_manifest ["partition_router" ], {}
745746 )
746747
747- partition_router = factory .create_component (
748+ model_to_component_factory = ModelToComponentFactory ()
749+ model_to_component_factory .set_api_budget (
750+ {
751+ "type" : "HTTPAPIBudget" ,
752+ "policies" : [
753+ {
754+ "type" : "MovingWindowCallRatePolicy" ,
755+ "rates" : [
756+ {
757+ "limit" : 1 ,
758+ "interval" : "PT60S" ,
759+ }
760+ ],
761+ "matchers" : [],
762+ }
763+ ],
764+ },
765+ input_config ,
766+ )
767+ partition_router = model_to_component_factory .create_component (
748768 model_type = SubstreamPartitionRouterModel ,
749769 component_definition = partition_router_manifest ,
750770 config = input_config ,
@@ -757,7 +777,14 @@ def test_create_substream_partition_router():
757777 assert isinstance (parent_stream_configs [0 ].stream , DefaultStream )
758778 assert isinstance (parent_stream_configs [1 ].stream , DefaultStream )
759779
760- assert partition_router .parent_stream_configs [0 ].parent_key .eval ({}) == "id"
780+ # ensure api budget
781+ assert get_retriever (
782+ parent_stream_configs [0 ].stream
783+ ).requester ._http_client ._api_budget ._policies
784+ assert get_retriever (
785+ parent_stream_configs [1 ].stream
786+ ).requester ._http_client ._api_budget ._policies
787+
761788 assert partition_router .parent_stream_configs [0 ].partition_field .eval ({}) == "repository_id"
762789 assert (
763790 partition_router .parent_stream_configs [0 ].request_option .inject_into
0 commit comments