-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Source Recharge: add new stream Events (#48382)
Co-authored-by: Marcos Marx <[email protected]>
- Loading branch information
1 parent
d93f6f7
commit f9c3c18
Showing
14 changed files
with
282 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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
13 changes: 13 additions & 0 deletions
13
airbyte-integrations/connectors/source-recharge/integration_tests/configured_catalog.json
This file contains 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 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 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 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.4.15" | ||
version = "2.5.0" | ||
name = "source-recharge" | ||
description = "Source implementation for Recharge." | ||
authors = [ "Airbyte <[email protected]>",] | ||
|
This file contains 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 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
57 changes: 57 additions & 0 deletions
57
airbyte-integrations/connectors/source-recharge/source_recharge/schemas/events.json
This file contains 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,57 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": ["null", "integer"] | ||
}, | ||
"customer_id": { | ||
"type": ["null", "integer"] | ||
}, | ||
"object_id": { | ||
"type": ["null", "integer"] | ||
}, | ||
"created_at": { | ||
"type": ["null", "string"], | ||
"format": "date-time" | ||
}, | ||
"custom_attributes": { | ||
"type": ["null", "array"] | ||
}, | ||
"description": { | ||
"type": ["null", "string"] | ||
}, | ||
"object_type": { | ||
"type": ["null", "string"] | ||
}, | ||
"source": { | ||
"type": ["null", "object"], | ||
"properties": { | ||
"account_id": { | ||
"type": ["null", "integer"] | ||
}, | ||
"api_token_id": { | ||
"type": ["null", "integer"] | ||
}, | ||
"account_email": { | ||
"type": ["null", "string"] | ||
}, | ||
"api_token_name": { | ||
"type": ["null", "string"] | ||
}, | ||
"origin": { | ||
"type": ["null", "string"] | ||
}, | ||
"user_type": { | ||
"type": ["null", "string"] | ||
} | ||
} | ||
}, | ||
"updated_attributes": { | ||
"type": ["null", "array"] | ||
}, | ||
"verb": { | ||
"type": ["null", "string"] | ||
} | ||
} | ||
} |
This file contains 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
88 changes: 88 additions & 0 deletions
88
...yte-integrations/connectors/source-recharge/unit_tests/integration/streams/test_events.py
This file contains 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,88 @@ | ||
# | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
|
||
from unittest import TestCase | ||
|
||
import freezegun | ||
from airbyte_cdk.test.mock_http import HttpMocker | ||
|
||
from ..config import NOW, START_DATE | ||
from ..response_builder import NEXT_PAGE_TOKEN, get_stream_record, get_stream_response | ||
from ..utils import StreamTestCase, config, get_cursor_value_from_state_message, read_full_refresh, read_incremental | ||
|
||
_STREAM_NAME = "events" | ||
_CURSOR_FIELD = "created_at" | ||
|
||
|
||
@freezegun.freeze_time(NOW.isoformat()) | ||
class TestFullRefresh(StreamTestCase): | ||
_STREAM_NAME = "events" | ||
|
||
@HttpMocker() | ||
def test_given_one_page_when_read_then_return_records(self, http_mocker: HttpMocker) -> None: | ||
req = self.stream_request().with_limit(250).with_created_min(START_DATE).build() | ||
http_mocker.get( | ||
req, | ||
get_stream_response(_STREAM_NAME).with_record(get_stream_record(_STREAM_NAME, "id", _CURSOR_FIELD)).build(), | ||
) | ||
output = read_full_refresh(self._config, _STREAM_NAME) | ||
assert len(output.records) == 1 | ||
|
||
@HttpMocker() | ||
def test_given_multiple_pages_when_read_then_return_records(self, http_mocker: HttpMocker) -> None: | ||
|
||
http_mocker.get( | ||
self.stream_request().with_limit(250).with_next_page_token(NEXT_PAGE_TOKEN).build(), | ||
get_stream_response(_STREAM_NAME).with_record(get_stream_record(_STREAM_NAME, "id", _CURSOR_FIELD)).build(), | ||
) | ||
http_mocker.get( | ||
self.stream_request().with_limit(250).with_created_min(START_DATE).build(), | ||
get_stream_response(_STREAM_NAME).with_pagination().with_record(get_stream_record(_STREAM_NAME, "id", _CURSOR_FIELD)).build(), | ||
) | ||
|
||
output = read_full_refresh(self._config, _STREAM_NAME) | ||
assert len(output.records) == 2 | ||
|
||
|
||
@freezegun.freeze_time(NOW.isoformat()) | ||
class TestIncremental(StreamTestCase): | ||
_STREAM_NAME = "events" | ||
|
||
@HttpMocker() | ||
def test_state_message_produced_while_read_and_state_match_latest_record(self, http_mocker: HttpMocker) -> None: | ||
min_cursor_value = "2024-01-01T00:00:00+00:00" | ||
max_cursor_value = "2024-02-01T00:00:00+00:00" | ||
|
||
http_mocker.get( | ||
self.stream_request().with_limit(250).with_created_min(START_DATE).build(), | ||
get_stream_response(_STREAM_NAME) | ||
.with_record(get_stream_record(_STREAM_NAME, "id", _CURSOR_FIELD).with_cursor(min_cursor_value)) | ||
.with_record(get_stream_record(_STREAM_NAME, "id", _CURSOR_FIELD).with_cursor(max_cursor_value)) | ||
.build(), | ||
) | ||
|
||
output = read_incremental(self._config, _STREAM_NAME) | ||
test_cursor_value = get_cursor_value_from_state_message(output, _CURSOR_FIELD) | ||
assert test_cursor_value == max_cursor_value | ||
|
||
@HttpMocker() | ||
def test_given_multiple_pages_when_read_then_return_records_with_state(self, http_mocker: HttpMocker) -> None: | ||
min_cursor_value = "2024-01-01T00:00:00+00:00" | ||
max_cursor_value = "2024-02-01T00:00:00+00:00" | ||
http_mocker.get( | ||
self.stream_request().with_limit(250).with_next_page_token(NEXT_PAGE_TOKEN).build(), | ||
get_stream_response(_STREAM_NAME).with_record(get_stream_record(_STREAM_NAME, "id", _CURSOR_FIELD)).build(), | ||
) | ||
http_mocker.get( | ||
self.stream_request().with_limit(250).with_created_min(START_DATE).build(), | ||
get_stream_response(_STREAM_NAME) | ||
.with_pagination() | ||
.with_record(get_stream_record(_STREAM_NAME, "id", _CURSOR_FIELD).with_cursor(min_cursor_value)) | ||
.with_record(get_stream_record(_STREAM_NAME, "id", _CURSOR_FIELD).with_cursor(max_cursor_value)) | ||
.build(), | ||
) | ||
|
||
output = read_incremental(self._config, _STREAM_NAME) | ||
assert len(output.records) == 3 |
63 changes: 63 additions & 0 deletions
63
...yte-integrations/connectors/source-recharge/unit_tests/resource/http/response/events.json
This file contains 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,63 @@ | ||
{ | ||
"next_cursor": null, | ||
"previous_cursor": null, | ||
"events": [ | ||
{ | ||
"id": 1, | ||
"customer_id": 1, | ||
"object_id": 1, | ||
"created_at": "2024-10-28T12:56:16", | ||
"custom_attributes": [], | ||
"description": "Cancelled subscription for Something from Customer", | ||
"object_type": "subscription", | ||
"source": { | ||
"account_id": null, | ||
"api_token_id": null, | ||
"account_email": null, | ||
"api_token_name": null, | ||
"origin": null, | ||
"user_type": null | ||
}, | ||
"updated_attributes": [], | ||
"verb": "cancelled" | ||
}, | ||
{ | ||
"id": 2, | ||
"customer_id": 2, | ||
"object_id": 2, | ||
"created_at": "2024-10-28T14:41:32", | ||
"custom_attributes": [], | ||
"description": "Deleted charge #2", | ||
"object_type": "charge", | ||
"source": { | ||
"account_id": null, | ||
"api_token_id": null, | ||
"account_email": null, | ||
"api_token_name": null, | ||
"origin": "somewhere", | ||
"user_type": "customer" | ||
}, | ||
"updated_attributes": [], | ||
"verb": "deleted" | ||
}, | ||
{ | ||
"id": 3, | ||
"customer_id": 3, | ||
"object_id": 3, | ||
"created_at": "2024-10-28T15:41:02", | ||
"custom_attributes": [], | ||
"description": "Failed charge #3", | ||
"object_type": "charge", | ||
"source": { | ||
"account_id": null, | ||
"api_token_id": null, | ||
"account_email": null, | ||
"api_token_name": null, | ||
"origin": "api", | ||
"user_type": null | ||
}, | ||
"updated_attributes": [], | ||
"verb": "failed" | ||
} | ||
] | ||
} |
This file contains 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 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