1
0
mirror of synced 2025-12-23 21:03:15 -05:00

Source Stripe: prepare for the next stage certification (#29950)

Co-authored-by: davydov-d <davydov-d@users.noreply.github.com>
This commit is contained in:
Denys Davydov
2023-09-08 15:52:25 +03:00
committed by GitHub
parent bddcba3f5c
commit 2f3cb59c23
29 changed files with 554 additions and 212 deletions

View File

@@ -35,8 +35,8 @@ def incremental_args_fixture(stream_args):
@pytest.fixture(name="invoices")
def invoices_fixture(incremental_stream_args):
def mocker(incremental_args=incremental_stream_args):
def invoices_fixture(stream_args):
def mocker(args=stream_args):
return IncrementalStripeStream(
name="invoices",
path="invoices",
@@ -55,7 +55,7 @@ def invoices_fixture(incremental_stream_args):
"invoice.updated",
"invoice.voided",
],
**incremental_stream_args
**args
)
return mocker

View File

@@ -3,26 +3,38 @@
#
import logging
from unittest.mock import Mock, patch
from contextlib import nullcontext as does_not_raise
from unittest.mock import patch
import pytest
import source_stripe
from airbyte_cdk.utils import AirbyteTracedException
from source_stripe import SourceStripe
logger = logging.getLogger("airbyte")
@patch.object(source_stripe.source, "stripe")
def test_source_check_connection_ok(config):
def test_source_check_connection_ok(mocked_client, config):
assert SourceStripe().check_connection(logger, config=config) == (True, None)
@patch.object(source_stripe.source, "stripe")
def test_source_check_connection_failure(mocked_client, config):
exception = Exception("Test")
mocked_client.Account.retrieve = Mock(side_effect=exception)
assert SourceStripe().check_connection(logger, config=config) == (False, exception)
def test_streams_are_unique(config):
stream_names = [s.name for s in SourceStripe().streams(config=config)]
assert len(stream_names) == len(set(stream_names)) == 46
@pytest.mark.parametrize(
"input_config, is_success, expected_error_msg",
(
({"lookback_window_days": "month"}, False, "Invalid lookback window month. Please use only positive integer values or 0."),
({"start_date": "January First, 2022"}, False, "Invalid start date January First, 2022. Please use YYYY-MM-DDTHH:MM:SSZ format."),
({"slice_range": -10}, False, "Invalid slice range value -10. Please use positive integer values only."),
({"account_id": 1, "client_secret": "secret"}, True, None)
)
)
@patch.object(source_stripe.source, "stripe")
def test_config_validation(mocked_client, input_config, is_success, expected_error_msg):
context = pytest.raises(AirbyteTracedException, match=expected_error_msg) if expected_error_msg else does_not_raise()
with context:
SourceStripe().check_connection(logger, config=input_config)

View File

@@ -34,8 +34,8 @@ def balance_transactions(incremental_stream_args):
@pytest.fixture()
def credit_notes(incremental_stream_args):
def mocker(args=incremental_stream_args):
def credit_notes(stream_args):
def mocker(args=stream_args):
return UpdatedCursorIncrementalStripeStream(
name="credit_notes",
path="credit_notes",
@@ -46,8 +46,8 @@ def credit_notes(incremental_stream_args):
@pytest.fixture()
def customers(incremental_stream_args):
def mocker(args=incremental_stream_args):
def customers(stream_args):
def mocker(args=stream_args):
return IncrementalStripeStream(
name="customers",
path="customers",
@@ -59,8 +59,8 @@ def customers(incremental_stream_args):
@pytest.fixture()
def bank_accounts(customers, incremental_stream_args):
def mocker(args=incremental_stream_args):
def bank_accounts(customers, stream_args):
def mocker(args=stream_args):
return UpdatedCursorIncrementalStripeLazySubStream(
name="bank_accounts",
path=lambda self, stream_slice, *args, **kwargs: f"customers/{stream_slice[self.parent_id]}/sources",
@@ -78,8 +78,8 @@ def bank_accounts(customers, incremental_stream_args):
@pytest.fixture()
def external_bank_accounts(incremental_stream_args):
def mocker(args=incremental_stream_args):
def external_bank_accounts(stream_args):
def mocker(args=stream_args):
return UpdatedCursorIncrementalStripeStream(
name="external_account_bank_accounts",
path=lambda self, *args, **kwargs: f"accounts/{self.account_id}/external_accounts",
@@ -98,7 +98,7 @@ def test_request_headers(accounts):
assert headers["Stripe-Version"] == "2022-11-15"
def test_lazy_sub_stream(requests_mock, invoice_line_items, invoices, stream_args, incremental_stream_args):
def test_lazy_sub_stream(requests_mock, invoice_line_items, invoices, stream_args):
# First initial request to parent stream
requests_mock.get(
"https://api.stripe.com/v1/invoices",
@@ -153,8 +153,7 @@ def test_lazy_sub_stream(requests_mock, invoice_line_items, invoices, stream_arg
# make start date a recent date so there's just one slice in a parent stream
stream_args["start_date"] = pendulum.today().subtract(days=3).int_timestamp
incremental_stream_args["start_date"] = pendulum.today().subtract(days=3).int_timestamp
parent_stream = invoices(incremental_stream_args)
parent_stream = invoices(stream_args)
stream = invoice_line_items(stream_args, parent_stream=parent_stream)
records = []
@@ -402,12 +401,12 @@ def test_setup_attempts(requests_mock, incremental_stream_args):
]
def test_persons_wo_state(requests_mock, incremental_stream_args):
def test_persons_wo_state(requests_mock, stream_args):
requests_mock.get(
"/v1/accounts",
json={"data": [{"id": 1, "object": "account", "created": 111}]}
)
stream = Persons(**incremental_stream_args)
stream = Persons(**stream_args)
slices = list(stream.stream_slices("full_refresh"))
assert slices == [{"parent": {"id": 1, "object": "account", "created": 111}}]
requests_mock.get(
@@ -422,7 +421,7 @@ def test_persons_wo_state(requests_mock, incremental_stream_args):
@freezegun.freeze_time("2023-08-23T15:00:15")
def test_persons_w_state(requests_mock, incremental_stream_args):
def test_persons_w_state(requests_mock, stream_args):
requests_mock.get(
"/v1/events",
json={
@@ -439,7 +438,7 @@ def test_persons_w_state(requests_mock, incremental_stream_args):
"has_more": False
}
)
stream = Persons(**incremental_stream_args)
stream = Persons(**stream_args)
slices = list(stream.stream_slices("incremental", stream_state={"updated": pendulum.parse("2023-08-20T00:00:00").int_timestamp}))
assert slices == [{}]
records = [