Skip to content

Commit 9726755

Browse files
devin-ai-integration[bot]bot_apk
andcommitted
test: add unit tests for CsvParser skip_rows and fix ruff formatting
Co-Authored-By: bot_apk <apk@cognition.ai>
1 parent 27f1735 commit 9726755

3 files changed

Lines changed: 141 additions & 88 deletions

File tree

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 58 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -928,28 +928,24 @@ class OAuthConfigSpecification(BaseModel):
928928
class Config:
929929
extra = Extra.allow
930930

931-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
932-
Field(
933-
None,
934-
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
935-
examples=[
936-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
937-
{
938-
"app_id": {
939-
"type": "string",
940-
"path_in_connector_config": ["info", "app_id"],
941-
}
942-
},
943-
],
944-
title="OAuth user input",
945-
)
931+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
932+
None,
933+
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
934+
examples=[
935+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
936+
{
937+
"app_id": {
938+
"type": "string",
939+
"path_in_connector_config": ["info", "app_id"],
940+
}
941+
},
942+
],
943+
title="OAuth user input",
946944
)
947-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
948-
Field(
949-
None,
950-
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
951-
title="DeclarativeOAuth Connector Specification",
952-
)
945+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
946+
None,
947+
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
948+
title="DeclarativeOAuth Connector Specification",
953949
)
954950
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
955951
None,
@@ -967,9 +963,7 @@ class Config:
967963
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
968964
None,
969965
description="OAuth specific blob. This is a Json Schema used to validate Json configurations persisted as Airbyte Server configurations.\nMust be a valid non-nested JSON describing additional fields configured by the Airbyte Instance or Workspace Admins to be used by the\nserver when completing an OAuth flow (typically exchanging an auth code for refresh token).\nExamples:\n complete_oauth_server_input_specification={\n client_id: {\n type: string\n },\n client_secret: {\n type: string\n }\n }",
970-
examples=[
971-
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
972-
],
966+
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
973967
title="OAuth input specification",
974968
)
975969
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1483,9 +1477,7 @@ class CustomConfigTransformation(BaseModel):
14831477
class_name: str = Field(
14841478
...,
14851479
description="Fully-qualified name of the class that will be implementing the custom config transformation. The format is `source_<name>.<package>.<class_name>`.",
1486-
examples=[
1487-
"source_declarative_manifest.components.MyCustomConfigTransformation"
1488-
],
1480+
examples=["source_declarative_manifest.components.MyCustomConfigTransformation"],
14891481
)
14901482
parameters: Optional[Dict[str, Any]] = Field(
14911483
None,
@@ -1913,9 +1905,7 @@ class OAuthAuthenticator(BaseModel):
19131905
scopes: Optional[List[str]] = Field(
19141906
None,
19151907
description="List of scopes that should be granted to the access token.",
1916-
examples=[
1917-
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
1918-
],
1908+
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
19191909
title="Scopes",
19201910
)
19211911
token_expiry_date: Optional[str] = Field(
@@ -2142,9 +2132,7 @@ class RecordSelector(BaseModel):
21422132
description="Responsible for filtering records to be emitted by the Source.",
21432133
title="Record Filter",
21442134
)
2145-
schema_normalization: Optional[
2146-
Union[SchemaNormalization, CustomSchemaNormalization]
2147-
] = Field(
2135+
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
21482136
None,
21492137
description="Responsible for normalization according to the schema.",
21502138
title="Schema Normalization",
@@ -2186,12 +2174,10 @@ class DpathValidator(BaseModel):
21862174
],
21872175
title="Field Path",
21882176
)
2189-
validation_strategy: Union[ValidateAdheresToSchema, CustomValidationStrategy] = (
2190-
Field(
2191-
...,
2192-
description="The condition that the specified config value will be evaluated against",
2193-
title="Validation Strategy",
2194-
)
2177+
validation_strategy: Union[ValidateAdheresToSchema, CustomValidationStrategy] = Field(
2178+
...,
2179+
description="The condition that the specified config value will be evaluated against",
2180+
title="Validation Strategy",
21952181
)
21962182

21972183

@@ -2208,12 +2194,10 @@ class PredicateValidator(BaseModel):
22082194
],
22092195
title="Value",
22102196
)
2211-
validation_strategy: Union[ValidateAdheresToSchema, CustomValidationStrategy] = (
2212-
Field(
2213-
...,
2214-
description="The validation strategy to apply to the value.",
2215-
title="Validation Strategy",
2216-
)
2197+
validation_strategy: Union[ValidateAdheresToSchema, CustomValidationStrategy] = Field(
2198+
...,
2199+
description="The validation strategy to apply to the value.",
2200+
title="Validation Strategy",
22172201
)
22182202

22192203

@@ -2238,12 +2222,12 @@ class ConfigAddFields(BaseModel):
22382222

22392223
class CompositeErrorHandler(BaseModel):
22402224
type: Literal["CompositeErrorHandler"]
2241-
error_handlers: List[
2242-
Union[CompositeErrorHandler, DefaultErrorHandler, CustomErrorHandler]
2243-
] = Field(
2244-
...,
2245-
description="List of error handlers to iterate on to determine how to handle a failed response.",
2246-
title="Error Handlers",
2225+
error_handlers: List[Union[CompositeErrorHandler, DefaultErrorHandler, CustomErrorHandler]] = (
2226+
Field(
2227+
...,
2228+
description="List of error handlers to iterate on to determine how to handle a failed response.",
2229+
title="Error Handlers",
2230+
)
22472231
)
22482232
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
22492233

@@ -2405,9 +2389,9 @@ class Config:
24052389

24062390
type: Literal["DeclarativeSource"]
24072391
check: Union[CheckStream, CheckDynamicStream]
2408-
streams: Optional[
2409-
List[Union[ConditionalStreams, DeclarativeStream, StateDelegatingStream]]
2410-
] = None
2392+
streams: Optional[List[Union[ConditionalStreams, DeclarativeStream, StateDelegatingStream]]] = (
2393+
None
2394+
)
24112395
dynamic_streams: List[DynamicDeclarativeStream]
24122396
version: str = Field(
24132397
...,
@@ -2532,20 +2516,16 @@ class Config:
25322516
extra = Extra.allow
25332517

25342518
type: Literal["DeclarativeStream"]
2535-
name: Optional[str] = Field(
2536-
"", description="The stream name.", example=["Users"], title="Name"
2537-
)
2519+
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
25382520
retriever: Union[SimpleRetriever, AsyncRetriever, CustomRetriever] = Field(
25392521
...,
25402522
description="Component used to coordinate how records are extracted across stream slices and request pages.",
25412523
title="Retriever",
25422524
)
2543-
incremental_sync: Optional[Union[DatetimeBasedCursor, IncrementingCountCursor]] = (
2544-
Field(
2545-
None,
2546-
description="Component used to fetch data incrementally based on a time field in the data.",
2547-
title="Incremental Sync",
2548-
)
2525+
incremental_sync: Optional[Union[DatetimeBasedCursor, IncrementingCountCursor]] = Field(
2526+
None,
2527+
description="Component used to fetch data incrementally based on a time field in the data.",
2528+
title="Incremental Sync",
25492529
)
25502530
primary_key: Optional[PrimaryKey] = Field("", title="Primary Key")
25512531
schema_loader: Optional[
@@ -2719,20 +2699,18 @@ class HttpRequester(BaseModelWithDeprecations):
27192699
description="For APIs that require explicit specification of the properties to query for, this component will take a static or dynamic set of properties (which can be optionally split into chunks) and allow them to be injected into an outbound request by accessing stream_partition.extra_fields.",
27202700
title="Query Properties",
27212701
)
2722-
request_parameters: Optional[Union[Dict[str, Union[str, QueryProperties]], str]] = (
2723-
Field(
2724-
None,
2725-
description="Specifies the query parameters that should be set on an outgoing HTTP request given the inputs.",
2726-
examples=[
2727-
{"unit": "day"},
2728-
{
2729-
"query": 'last_event_time BETWEEN TIMESTAMP "{{ stream_interval.start_time }}" AND TIMESTAMP "{{ stream_interval.end_time }}"'
2730-
},
2731-
{"searchIn": "{{ ','.join(config.get('search_in', [])) }}"},
2732-
{"sort_by[asc]": "updated_at"},
2733-
],
2734-
title="Query Parameters",
2735-
)
2702+
request_parameters: Optional[Union[Dict[str, Union[str, QueryProperties]], str]] = Field(
2703+
None,
2704+
description="Specifies the query parameters that should be set on an outgoing HTTP request given the inputs.",
2705+
examples=[
2706+
{"unit": "day"},
2707+
{
2708+
"query": 'last_event_time BETWEEN TIMESTAMP "{{ stream_interval.start_time }}" AND TIMESTAMP "{{ stream_interval.end_time }}"'
2709+
},
2710+
{"searchIn": "{{ ','.join(config.get('search_in', [])) }}"},
2711+
{"sort_by[asc]": "updated_at"},
2712+
],
2713+
title="Query Parameters",
27362714
)
27372715
request_headers: Optional[Union[Dict[str, str], str]] = Field(
27382716
None,
@@ -2904,9 +2882,7 @@ class QueryProperties(BaseModel):
29042882

29052883
class StateDelegatingStream(BaseModel):
29062884
type: Literal["StateDelegatingStream"]
2907-
name: str = Field(
2908-
..., description="The stream name.", example=["Users"], title="Name"
2909-
)
2885+
name: str = Field(..., description="The stream name.", example=["Users"], title="Name")
29102886
full_refresh_stream: DeclarativeStream = Field(
29112887
...,
29122888
description="Component used to coordinate how records are extracted across stream slices and request pages when the state is empty or not provided.",
@@ -2993,17 +2969,13 @@ class AsyncRetriever(BaseModel):
29932969
status_extractor: Union[DpathExtractor, CustomRecordExtractor] = Field(
29942970
..., description="Responsible for fetching the actual status of the async job."
29952971
)
2996-
download_target_extractor: Optional[
2997-
Union[DpathExtractor, CustomRecordExtractor]
2998-
] = Field(
2972+
download_target_extractor: Optional[Union[DpathExtractor, CustomRecordExtractor]] = Field(
29992973
None,
30002974
description="Responsible for fetching the final result `urls` provided by the completed / finished / ready async job.",
30012975
)
30022976
download_extractor: Optional[
30032977
Union[DpathExtractor, CustomRecordExtractor, ResponseToFileExtractor]
3004-
] = Field(
3005-
None, description="Responsible for fetching the records from provided urls."
3006-
)
2978+
] = Field(None, description="Responsible for fetching the records from provided urls.")
30072979
creation_requester: Union[HttpRequester, CustomRequester] = Field(
30082980
...,
30092981
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,8 +2672,12 @@ def _get_parser(model: BaseModel, config: Config) -> Parser:
26722672
encoding=model.encoding,
26732673
delimiter=model.delimiter,
26742674
set_values_to_none=model.set_values_to_none,
2675-
skip_rows_before_header=model.skip_rows_before_header if model.skip_rows_before_header else 0,
2676-
skip_rows_after_header=model.skip_rows_after_header if model.skip_rows_after_header else 0,
2675+
skip_rows_before_header=model.skip_rows_before_header
2676+
if model.skip_rows_before_header
2677+
else 0,
2678+
skip_rows_after_header=model.skip_rows_after_header
2679+
if model.skip_rows_after_header
2680+
else 0,
26772681
)
26782682
elif isinstance(model, GzipDecoderModel):
26792683
return GzipParser(

0 commit comments

Comments
 (0)