Skip to content

Commit 5f5c6b1

Browse files
author
Oleksandr Bazarnov
committed
attempt to fix the Connector Builder tests
1 parent acdecdb commit 5f5c6b1

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

airbyte_cdk/connector_builder/connector_builder_handler.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
from dataclasses import asdict, dataclass, field
7-
from typing import Any, Dict, List, Mapping
7+
from typing import Any, Dict, List, Mapping, Optional
88

99
from airbyte_cdk.connector_builder.test_reader import TestReader
1010
from airbyte_cdk.models import (
@@ -54,12 +54,17 @@ def get_limits(config: Mapping[str, Any]) -> TestLimits:
5454
return TestLimits(max_records, max_pages_per_slice, max_slices, max_streams)
5555

5656

57-
def create_source(config: Mapping[str, Any], limits: TestLimits) -> ManifestDeclarativeSource:
57+
def create_source(
58+
config: Mapping[str, Any],
59+
limits: TestLimits,
60+
post_resolve_manifest: Optional[bool] = False,
61+
) -> ManifestDeclarativeSource:
5862
manifest = config["__injected_declarative_manifest"]
5963
return ManifestDeclarativeSource(
6064
config=config,
6165
emit_connector_builder_messages=True,
6266
source_config=manifest,
67+
post_resolve_manifest=post_resolve_manifest,
6368
component_factory=ModelToComponentFactory(
6469
emit_connector_builder_messages=True,
6570
limit_pages_fetched_per_slice=limits.max_pages_per_slice,

airbyte_cdk/connector_builder/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ def handle_connector_builder_request(
8888
raise ValueError(f"Unrecognized command {command}.")
8989

9090

91-
def handle_request(args: List[str]) -> str:
91+
def handle_request(args: List[str], post_resolve_manifest: Optional[bool] = False) -> str:
9292
command, config, catalog, state = get_config_and_catalog_from_args(args)
9393
limits = get_limits(config)
94-
source = create_source(config, limits)
94+
source = create_source(config, limits, post_resolve_manifest=post_resolve_manifest)
9595
return orjson.dumps(
9696
AirbyteMessageSerializer.dump(
9797
handle_connector_builder_request(source, command, config, catalog, state, limits)

airbyte_cdk/sources/declarative/manifest_declarative_source.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def __init__(
9191
debug: bool = False,
9292
emit_connector_builder_messages: bool = False,
9393
component_factory: Optional[ModelToComponentFactory] = None,
94+
post_resolve_manifest: Optional[bool] = False,
9495
) -> None:
9596
"""
9697
Args:
@@ -129,6 +130,13 @@ def __init__(
129130
self._declarative_component_schema,
130131
).normalize()
131132

133+
# The manifest is now in a format that the Connector Builder UI can use.
134+
# however, the local tests may depend on the completely resolved manifest.
135+
if post_resolve_manifest:
136+
propagated_source_config = ManifestReferenceResolver().preprocess_manifest(
137+
propagated_source_config
138+
)
139+
132140
self._source_config = propagated_source_config
133141
self._debug = debug
134142
self._emit_connector_builder_messages = emit_connector_builder_messages

airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import copy
66
import typing
7-
from typing import Any, Mapping, Optional
7+
from typing import Any, Dict, Mapping, Optional
88

99
PARAMETERS_STR = "$parameters"
1010

@@ -95,7 +95,7 @@ def propagate_types_and_parameters(
9595
declarative_component: Mapping[str, Any],
9696
parent_parameters: Mapping[str, Any],
9797
use_parent_parameters: Optional[bool] = None,
98-
) -> Mapping[str, Any]:
98+
) -> Dict[str, Any]:
9999
"""
100100
Recursively transforms the specified declarative component and subcomponents to propagate parameters and insert the
101101
default component type if it was not already present. The resulting transformed components are a deep copy of the input

unit_tests/connector_builder/test_connector_builder_handler.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ def test_handle_resolve_manifest(valid_resolve_manifest_config_file, dummy_catal
503503
str(valid_resolve_manifest_config_file),
504504
"--catalog",
505505
str(dummy_catalog),
506-
]
506+
],
507+
post_resolve_manifest=True,
507508
)
508509
assert patched_handle.call_count == 1
509510

@@ -515,7 +516,14 @@ def test_handle_test_read(valid_read_config_file, configured_catalog):
515516
return_value=AirbyteMessage(type=MessageType.RECORD),
516517
) as patch:
517518
handle_request(
518-
["read", "--config", str(valid_read_config_file), "--catalog", str(configured_catalog)]
519+
[
520+
"read",
521+
"--config",
522+
str(valid_read_config_file),
523+
"--catalog",
524+
str(configured_catalog),
525+
],
526+
post_resolve_manifest=True,
519527
)
520528
assert patch.call_count == 1
521529

@@ -867,7 +875,7 @@ def test_handle_429_response():
867875

868876
config = TEST_READ_CONFIG
869877
limits = TestLimits()
870-
source = create_source(config, limits)
878+
source = create_source(config, limits, post_resolve_manifest=True)
871879

872880
with patch("requests.Session.send", return_value=response) as mock_send:
873881
response = handle_connector_builder_request(
@@ -919,7 +927,14 @@ def test_missing_config(valid_resolve_manifest_config_file):
919927
def test_invalid_config_command(invalid_config_file, dummy_catalog):
920928
with pytest.raises(ValueError):
921929
handle_request(
922-
["read", "--config", str(invalid_config_file), "--catalog", str(dummy_catalog)]
930+
[
931+
"read",
932+
"--config",
933+
str(invalid_config_file),
934+
"--catalog",
935+
str(dummy_catalog),
936+
],
937+
post_resolve_manifest=True,
923938
)
924939

925940

@@ -987,7 +1002,7 @@ def test_create_source():
9871002

9881003
config = {"__injected_declarative_manifest": MANIFEST}
9891004

990-
source = create_source(config, limits)
1005+
source = create_source(config, limits, post_resolve_manifest=True)
9911006

9921007
assert isinstance(source, ManifestDeclarativeSource)
9931008
assert source._constructor._limit_pages_fetched_per_slice == limits.max_pages_per_slice
@@ -1081,7 +1096,7 @@ def test_read_source(mock_http_stream):
10811096

10821097
config = {"__injected_declarative_manifest": MANIFEST}
10831098

1084-
source = create_source(config, limits)
1099+
source = create_source(config, limits, post_resolve_manifest=True)
10851100

10861101
output_data = read_stream(source, config, catalog, _A_PER_PARTITION_STATE, limits).record.data
10871102
slices = output_data["slices"]
@@ -1128,7 +1143,7 @@ def test_read_source_single_page_single_slice(mock_http_stream):
11281143

11291144
config = {"__injected_declarative_manifest": MANIFEST}
11301145

1131-
source = create_source(config, limits)
1146+
source = create_source(config, limits, post_resolve_manifest=True)
11321147

11331148
output_data = read_stream(source, config, catalog, _A_PER_PARTITION_STATE, limits).record.data
11341149
slices = output_data["slices"]
@@ -1214,7 +1229,7 @@ def test_handle_read_external_requests(deployment_mode, url_base, expected_error
12141229
test_manifest["streams"][0]["$parameters"]["url_base"] = url_base
12151230
config = {"__injected_declarative_manifest": test_manifest}
12161231

1217-
source = create_source(config, limits)
1232+
source = create_source(config, limits, post_resolve_manifest=True)
12181233

12191234
with mock.patch.dict(os.environ, {"DEPLOYMENT_MODE": deployment_mode}, clear=False):
12201235
output_data = read_stream(
@@ -1310,7 +1325,7 @@ def test_handle_read_external_oauth_request(deployment_mode, token_url, expected
13101325
)
13111326
config = {"__injected_declarative_manifest": test_manifest}
13121327

1313-
source = create_source(config, limits)
1328+
source = create_source(config, limits, post_resolve_manifest=True)
13141329

13151330
with mock.patch.dict(os.environ, {"DEPLOYMENT_MODE": deployment_mode}, clear=False):
13161331
output_data = read_stream(

0 commit comments

Comments
 (0)