-
Notifications
You must be signed in to change notification settings - Fork 4.5k
🐛 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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]>",] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
11 changes: 11 additions & 0 deletions
11
airbyte-integrations/connectors/source-klaviyo/unit_tests/integration/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
89 changes: 89 additions & 0 deletions
89
airbyte-integrations/connectors/source-klaviyo/unit_tests/integration/test_profiles.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
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) |
94 changes: 94 additions & 0 deletions
94
...te-integrations/connectors/source-klaviyo/unit_tests/resource/http/response/profiles.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3