Skip to content

🐛 Source Klaviyo: have region also be a number #44930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:
definitionId: 95e8cffd-b8c4-4039-968e-d32fb4a69bde
connectorBuildOptions:
baseImage: docker.io/airbyte/python-connector-base:2.0.0@sha256:c44839ba84406116e8ba68722a0f30e8f6e7056c726f447681bb9e9ece8bd916
dockerImageTag: 2.10.1
dockerImageTag: 2.10.2
dockerRepository: airbyte/source-klaviyo
githubIssueLabel: source-klaviyo
icon: klaviyo.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "2.10.1"
version = "2.10.2"
name = "source-klaviyo"
description = "Source implementation for Klaviyo."
authors = [ "Airbyte <[email protected]>",]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ definitions:
schema_loader:
type: InlineSchemaLoader
schema: "#/definitions/profiles_schema"
retriever: "#/definitions/profiles_retriever"
retriever:
$ref: "#/definitions/profiles_retriever"
record_selector:
$ref: "#/definitions/selector"
schema_normalization: Default
$parameters:
path: "profiles"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.

from typing import Any, Dict


class KlaviyoConfigBuilder:
def __init__(self) -> None:
self._config = {"api_key":"an_api_key","start_date":"2021-01-01T00:00:00Z"}

def build(self) -> Dict[str, Any]:
return self._config
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.

from typing import Any, Dict, Optional
from unittest import TestCase

from airbyte_cdk.test.catalog_builder import CatalogBuilder
from airbyte_cdk.test.entrypoint_wrapper import EntrypointOutput, read
from airbyte_cdk.test.mock_http import HttpMocker, HttpRequest
from airbyte_cdk.test.mock_http.request import ANY_QUERY_PARAMS
from airbyte_cdk.test.mock_http.response_builder import (
FieldPath,
HttpResponseBuilder,
NestedPath,
RecordBuilder,
create_record_builder,
create_response_builder,
find_template,
)
from airbyte_protocol.models import ConfiguredAirbyteCatalog, SyncMode
from integration.config import KlaviyoConfigBuilder
from source_klaviyo import SourceKlaviyo

_ENDPOINT_TEMPLATE_NAME = "profiles"
_STREAM_NAME = "profiles"
_RECORDS_PATH = FieldPath("data")


def _config() -> KlaviyoConfigBuilder:
return KlaviyoConfigBuilder()


def _catalog(sync_mode: SyncMode) -> ConfiguredAirbyteCatalog:
return CatalogBuilder().with_stream(_STREAM_NAME, sync_mode).build()


def _a_profile_request() -> HttpRequest:
return HttpRequest(
url=f"https://a.klaviyo.com/api/profiles",
query_params=ANY_QUERY_PARAMS
)


def _a_profile() -> RecordBuilder:
return create_record_builder(
find_template(_ENDPOINT_TEMPLATE_NAME, __file__),
_RECORDS_PATH,
record_id_path=FieldPath("id"),
record_cursor_path=NestedPath(["attributes", "updated"]),
)


def _profiles_response() -> HttpResponseBuilder:
return create_response_builder(
find_template(_ENDPOINT_TEMPLATE_NAME, __file__),
_RECORDS_PATH,
)


def _read(
config_builder: KlaviyoConfigBuilder, sync_mode: SyncMode, state: Optional[Dict[str, Any]] = None, expecting_exception: bool = False
) -> EntrypointOutput:
catalog = _catalog(sync_mode)
config = config_builder.build()
return read(SourceKlaviyo(), config, catalog, state, expecting_exception)


class FullRefreshTest(TestCase):
@HttpMocker()
def test_when_read_then_extract_records(self, http_mocker: HttpMocker) -> None:
http_mocker.get(
_a_profile_request(),
_profiles_response().with_record(_a_profile()).build(),
)

output = _read(_config(), SyncMode.full_refresh)

assert len(output.records) == 1

@HttpMocker()
def test_given_region_is_number_when_read_then_cast_as_string(self, http_mocker: HttpMocker) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

http_mocker.get(
_a_profile_request(),
_profiles_response().with_record(_a_profile().with_field(NestedPath(["attributes", "location", "region"]), 10)).build(),
)

output = _read(_config(), SyncMode.full_refresh)

assert len(output.records) == 1
assert isinstance(output.records[0].record.data["attributes"]["location"]["region"], str)
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"data": [
{
"type": "profile",
"id": "01G4CDTEP140TDXZ0692XSA61K",
"attributes": {
"email": "[email protected]",
"phone_number": "+13523772689",
"external_id": null,
"anonymous_id": null,
"first_name": "Tracey",
"last_name": "Witting",
"organization": null,
"locale": null,
"title": null,
"image": null,
"created": "2022-05-31T06:46:01+00:00",
"updated": "2022-05-31T06:46:01+00:00",
"last_event_date": null,
"location": {
"address1": "2088 Rempel Road",
"region": null,
"zip": null,
"country": "United States",
"address2": null,
"longitude": null,
"city": null,
"latitude": null,
"timezone": null,
"ip": null
},
"properties": {
"Accepts Marketing": false,
"Shopify Tags": ["developer-tools-generator"]
},
"subscriptions": {
"email": {
"marketing": {
"consent": "NEVER_SUBSCRIBED",
"timestamp": null,
"method": null,
"method_detail": null,
"custom_method_detail": null,
"double_optin": null,
"suppressions": [],
"list_suppressions": []
}
},
"sms": {
"marketing": {
"consent": "NEVER_SUBSCRIBED",
"timestamp": null,
"method": null,
"method_detail": null
}
}
},
"predictive_analytics": {
"historic_clv": null,
"predicted_clv": null,
"total_clv": null,
"historic_number_of_orders": null,
"predicted_number_of_orders": null,
"average_days_between_orders": null,
"average_order_value": null,
"churn_probability": null,
"expected_date_of_next_order": null
}
},
"relationships": {
"lists": {
"links": {
"self": "https://a.klaviyo.com/api/profiles/01G4CDTEP140TDXZ0692XSA61K/relationships/lists/",
"related": "https://a.klaviyo.com/api/profiles/01G4CDTEP140TDXZ0692XSA61K/lists/"
}
},
"segments": {
"links": {
"self": "https://a.klaviyo.com/api/profiles/01G4CDTEP140TDXZ0692XSA61K/relationships/segments/",
"related": "https://a.klaviyo.com/api/profiles/01G4CDTEP140TDXZ0692XSA61K/segments/"
}
}
},
"links": {
"self": "https://a.klaviyo.com/api/profiles/01G4CDTEP140TDXZ0692XSA61K/"
}
}
],
"links": {
"self": "https://a.klaviyo.com/api/profiles?additional-fields%5Bprofile%5D=predictive_analytics&page%5Bsize%5D=100&filter=greater-than%28updated%2C2021-01-01T00%3A00%3A00%2B0000%29&sort=updated&page%5Bcursor%5D=bmV4dDo6dXBkYXRlZDo6MjAyMi0wNS0zMSAwNjo0NjowMSswMDowMDo6aWQ6OjAxRzRDRFRFTTZKMjBHRzVRNU41Q0Q4V0pW",
"next": null,
"prev": null
}
}
Loading
Loading