Skip to content

Commit

Permalink
🐛 Source Stripe: handle PermissionError as non breaking during check_…
Browse files Browse the repository at this point in the history
…connection (#30800)
  • Loading branch information
maxi297 authored Sep 27, 2023
1 parent 8681027 commit e82178f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-stripe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]


LABEL io.airbyte.version=4.3.0
LABEL io.airbyte.version=4.3.1
LABEL io.airbyte.name=airbyte/source-stripe
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: e094cb9a-26de-4645-8761-65c0c425d1de
dockerImageTag: 4.3.0
dockerImageTag: 4.3.1
dockerRepository: airbyte/source-stripe
githubIssueLabel: source-stripe
icon: stripe.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
stripe.api_key = config["client_secret"]
try:
stripe.Account.retrieve(config["account_id"])
except stripe.error.AuthenticationError as e:
except (stripe.error.AuthenticationError, stripe.error.PermissionError) as e:
return False, str(e)
return True, None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

import pytest
import source_stripe
import stripe
from airbyte_cdk.utils import AirbyteTracedException
from source_stripe import SourceStripe

logger = logging.getLogger("airbyte")


def _a_valid_config():
return {"account_id": 1, "client_secret": "secret"}


@patch.object(source_stripe.source, "stripe")
def test_source_check_connection_ok(mocked_client, config):
assert SourceStripe().check_connection(logger, config=config) == (True, None)
Expand All @@ -25,16 +30,30 @@ def test_streams_are_unique(config):


@pytest.mark.parametrize(
"input_config, is_success, expected_error_msg",
"input_config, 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)
({"lookback_window_days": "month"}, "Invalid lookback window month. Please use only positive integer values or 0."),
({"start_date": "January First, 2022"}, "Invalid start date January First, 2022. Please use YYYY-MM-DDTHH:MM:SSZ format."),
({"slice_range": -10}, "Invalid slice range value -10. Please use positive integer values only."),
(_a_valid_config(), None)
)
)
@patch.object(source_stripe.source, "stripe")
def test_config_validation(mocked_client, input_config, is_success, expected_error_msg):
@patch.object(source_stripe.source.stripe, "Account")
def test_config_validation(mocked_client, input_config, 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)


@pytest.mark.parametrize(
"exception",
(
stripe.error.AuthenticationError,
stripe.error.PermissionError,
)
)
@patch.object(source_stripe.source.stripe, "Account")
def test_given_stripe_error_when_check_connection_then_connection_not_available(mocked_client, exception):
mocked_client.retrieve.side_effect = exception
is_available, _ = SourceStripe().check_connection(logger, config=_a_valid_config())
assert not is_available
1 change: 1 addition & 0 deletions docs/integrations/sources/stripe.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ The Stripe connector should not run into Stripe API limitations under normal usa

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
| 4.3.1 | 2023-09-27 | [30800](https://github.com/airbytehq/airbyte/pull/30800) | Handle permission issues a non breaking |
| 4.3.0 | 2023-09-26 | [30752](https://github.com/airbytehq/airbyte/pull/30752) | Do not sync upcoming invoices, extend stream schemas |
| 4.2.0 | 2023-09-21 | [30660](https://github.com/airbytehq/airbyte/pull/30660) | Fix updated state for the incremental syncs |
| 4.1.1 | 2023-09-15 | [30494](https://github.com/airbytehq/airbyte/pull/30494) | Fix datatype of invoices.lines property |
Expand Down

0 comments on commit e82178f

Please sign in to comment.