Jamhouston/source recharge add stream bundle selections (#49926)
Co-authored-by: Rita Filatova <rita.filatova@scentbird.com> Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
This commit is contained in:
@@ -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 = "bundle_selections"
|
||||
_CURSOR_FIELD = "updated_at"
|
||||
|
||||
|
||||
@freezegun.freeze_time(NOW.isoformat())
|
||||
class TestFullRefresh(StreamTestCase):
|
||||
_STREAM_NAME = "bundle_selections"
|
||||
|
||||
@HttpMocker()
|
||||
def test_given_one_page_when_read_then_return_records(self, http_mocker: HttpMocker) -> None:
|
||||
http_mocker.get(
|
||||
self.stream_request().with_limit(250).with_updated_at_min(START_DATE).build(),
|
||||
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_updated_at_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 = "bundle_selections"
|
||||
|
||||
@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_updated_at_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_updated_at_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
|
||||
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"next_cursor": null,
|
||||
"previous_cursor": null,
|
||||
"bundle_selections": [
|
||||
{
|
||||
"id": 1,
|
||||
"bundle_variant_id": 1,
|
||||
"charge_id": null,
|
||||
"order_id": null,
|
||||
"purchase_item_id": 1,
|
||||
"created_at": "2024-12-09T08:11:01+00:00",
|
||||
"external_product_id": "1234567890123",
|
||||
"external_variant_id": "12345",
|
||||
"is_fallback": false,
|
||||
"items": [
|
||||
{
|
||||
"id": 1,
|
||||
"collection_id": "2",
|
||||
"collection_source": "test",
|
||||
"created_at": "2024-12-09T08:11:01+00:00",
|
||||
"external_product_id": "1",
|
||||
"external_variant_id": "2",
|
||||
"price": "10.00",
|
||||
"quantity": 1,
|
||||
"updated_at": "2024-12-09T08:11:01+00:00"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"collection_id": "2",
|
||||
"collection_source": "test",
|
||||
"created_at": "2024-12-09T08:11:01+00:00",
|
||||
"external_product_id": "7625137913910",
|
||||
"external_variant_id": "42941000745014",
|
||||
"price": "11.00",
|
||||
"quantity": 1,
|
||||
"updated_at": "2024-12-09T08:11:01+00:00"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"collection_id": "1",
|
||||
"collection_source": "test",
|
||||
"created_at": "2024-12-09T08:11:01+00:00",
|
||||
"external_product_id": "1",
|
||||
"external_variant_id": "2",
|
||||
"price": "12.00",
|
||||
"quantity": 2,
|
||||
"updated_at": "2024-12-09T08:11:01+00:00"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"collection_id": "3",
|
||||
"collection_source": "test",
|
||||
"created_at": "2024-12-09T08:11:01+00:00",
|
||||
"external_product_id": "4",
|
||||
"external_variant_id": "2",
|
||||
"price": "13.00",
|
||||
"quantity": 2,
|
||||
"updated_at": "2024-12-09T08:11:01+00:00"
|
||||
}
|
||||
],
|
||||
"updated_at": "2024-12-09T08:11:01+00:00"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"bundle_variant_id": 3,
|
||||
"charge_id": null,
|
||||
"order_id": null,
|
||||
"purchase_item_id": 4,
|
||||
"created_at": "2024-12-09T08:08:34+00:00",
|
||||
"external_product_id": "1",
|
||||
"external_variant_id": "2",
|
||||
"is_fallback": false,
|
||||
"items": [
|
||||
{
|
||||
"id": 6,
|
||||
"collection_id": "4",
|
||||
"collection_source": "test",
|
||||
"created_at": "2024-12-09T08:08:34+00:00",
|
||||
"external_product_id": "2",
|
||||
"external_variant_id": "5",
|
||||
"price": "14.00",
|
||||
"quantity": 1,
|
||||
"updated_at": "2024-12-09T08:08:34+00:00"
|
||||
}
|
||||
],
|
||||
"updated_at": "2024-12-09T08:08:34+00:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -31,7 +31,7 @@ def test_get_auth_header(config) -> None:
|
||||
|
||||
def test_streams(config) -> None:
|
||||
streams = SourceRecharge().streams(config)
|
||||
assert len(streams) == 12
|
||||
assert len(streams) == 13
|
||||
|
||||
|
||||
class TestCommon:
|
||||
|
||||
Reference in New Issue
Block a user