Skip to content

Commit aed54c4

Browse files
committed
move test_spec to connector base, clean up imports
1 parent e423959 commit aed54c4

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

airbyte_cdk/test/standard_tests/connector_base.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,39 @@ def create_docker_connector(
137137
docker_image=docker_image,
138138
)
139139

140-
# Test Definitions
140+
# Test Definitions (Generic for all connectors)
141+
142+
def test_spec(
143+
self,
144+
*,
145+
use_docker_image: str | bool,
146+
) -> None:
147+
"""Standard test for `spec`.
148+
149+
This test does not require a `scenario` input, since `spec`
150+
does not require any inputs.
151+
152+
We assume `spec` should always succeed and it should always generate
153+
a valid `SPEC` message.
154+
155+
Note: the parsing of messages by type also implicitly validates that
156+
the generated `SPEC` message is valid JSON.
157+
"""
158+
scenario = ConnectorTestScenario() # Empty scenario, empty config
159+
result = run_test_job(
160+
verb="spec",
161+
test_scenario=scenario,
162+
connector=self.create_connector(
163+
scenario=scenario,
164+
use_docker_image=use_docker_image,
165+
),
166+
)
167+
# If an error occurs, it will be raised above.
168+
169+
assert len(result.spec_messages) == 1, (
170+
"Expected exactly 1 spec message but got {len(result.spec_messages)}",
171+
result.errors,
172+
)
141173

142174
def test_check(
143175
self,

airbyte_cdk/test/standard_tests/source_base.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
SyncMode,
1313
Type,
1414
)
15-
from airbyte_cdk.test import entrypoint_wrapper
15+
from airbyte_cdk.test.entrypoint_wrapper import EntrypointOutput
1616
from airbyte_cdk.test.standard_tests._job_runner import run_test_job
1717
from airbyte_cdk.test.standard_tests.connector_base import (
1818
ConnectorTestSuiteBase,
@@ -41,7 +41,7 @@ def test_check(
4141
This test is designed to validate the connector's ability to establish a connection
4242
and return its status with the expected message type.
4343
"""
44-
result: entrypoint_wrapper.EntrypointOutput = run_test_job(
44+
result: EntrypointOutput = run_test_job(
4545
connector=self.create_connector(
4646
scenario=scenario,
4747
use_docker_image=use_docker_image,
@@ -74,30 +74,6 @@ def test_discover(
7474
test_scenario=scenario,
7575
)
7676

77-
def test_spec(self) -> None:
78-
"""Standard test for `spec`.
79-
80-
This test does not require a `scenario` input, since `spec`
81-
does not require any inputs.
82-
83-
We assume `spec` should always succeed and it should always generate
84-
a valid `SPEC` message.
85-
86-
Note: the parsing of messages by type also implicitly validates that
87-
the generated `SPEC` message is valid JSON.
88-
"""
89-
result = run_test_job(
90-
verb="spec",
91-
test_scenario=None,
92-
connector=self.create_connector(scenario=None),
93-
)
94-
# If an error occurs, it will be raised above.
95-
96-
assert len(result.spec_messages) == 1, (
97-
"Expected exactly 1 spec message but got {len(result.spec_messages)}",
98-
result.errors,
99-
)
100-
10177
def test_basic_read(
10278
self,
10379
scenario: ConnectorTestScenario,
@@ -111,7 +87,7 @@ def test_basic_read(
11187
obtain the catalog of streams, and then it runs a `read` job to fetch
11288
records from those streams.
11389
"""
114-
discover_result = run_test_job(
90+
discover_result: EntrypointOutput = run_test_job(
11591
self.create_connector(
11692
scenario,
11793
use_docker_image=use_docker_image,
@@ -133,7 +109,7 @@ def test_basic_read(
133109
for stream in discover_result.catalog.catalog.streams # type: ignore [reportOptionalMemberAccess, union-attr]
134110
]
135111
)
136-
result = run_test_job(
112+
result: EntrypointOutput = run_test_job(
137113
self.create_connector(
138114
scenario,
139115
use_docker_image=use_docker_image,
@@ -174,7 +150,7 @@ def test_fail_read_with_bad_catalog(
174150
)
175151
# Set expected status to "failed" to ensure the test fails if the connector.
176152
scenario.status = "failed"
177-
result: entrypoint_wrapper.EntrypointOutput = run_test_job(
153+
result: EntrypointOutput = run_test_job(
178154
self.create_connector(
179155
scenario,
180156
use_docker_image=use_docker_image,

0 commit comments

Comments
 (0)