Skip to content

Commit

Permalink
[ISSUE #32871] source-stripe streams integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxi297 committed Dec 11, 2023
1 parent 3ede97c commit 60e7cdd
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 2 deletions.
3 changes: 2 additions & 1 deletion airbyte-integrations/connectors/source-stripe/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from setuptools import find_packages, setup

MAIN_REQUIREMENTS = ["airbyte-cdk==0.53.6", "stripe==2.56.0", "pendulum==2.1.2"]
# FIXME update to the version released following https://github.com/airbytehq/airbyte/pull/33305
MAIN_REQUIREMENTS = ["airbyte-cdk==0.55.5", "stripe==2.56.0", "pendulum==2.1.2"]

TEST_REQUIREMENTS = ["pytest-mock~=3.6.1", "pytest~=6.1", "requests-mock", "requests_mock~=1.8", "freezegun==1.2.2"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
streams[0].logger.info(f"Using concurrent cdk with concurrency level {concurrency_level}")

return [
StreamFacade.create_from_stream(stream, self, entrypoint_logger, concurrency_level, self._create_empty_state(), NoopCursor())
# Should hopefully align with https://github.com/airbytehq/airbyte/pull/32908
StreamFacade.create_from_stream(stream, self, entrypoint_logger, self._create_empty_state(), NoopCursor())
if stream.name in self._streams_configured_as_full_refresh
else stream
for stream in streams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

STRIPE_API_VERSION = "2022-11-15"
CACHE_DISABLED = os.environ.get("CACHE_DISABLED")
IS_TESTING = os.environ.get("IS_TESTING")
USE_CACHE = not CACHE_DISABLED


Expand Down Expand Up @@ -197,6 +198,12 @@ def request_headers(self, **kwargs) -> Mapping[str, Any]:
headers["Stripe-Account"] = self.account_id
return headers

def retry_factor(self) -> float:
"""
Override for testing purposes
"""
return 0.001 if IS_TESTING else super().retry_factor()


class IStreamSelector(ABC):
@abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator

os.environ["CACHE_DISABLED"] = "true"
os.environ["IS_TESTING"] = "true"


@pytest.fixture(name="config")
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from datetime import datetime
from typing import Any, Dict


class ConfigBuilder:
def __init__(self) -> None:
self._config: Dict[str, Any] = {
"client_secret": "ConfigBuilder default client secret",
"account_id": "ConfigBuilder default account id",
"start_date": "2020-05-01T00:00:00Z"
}

def with_account_id(self, account_id: str) -> "ConfigBuilder":
self._config["account_id"] = account_id
return self

def with_client_secret(self, client_secret: str) -> "ConfigBuilder":
self._config["client_secret"] = client_secret
return self

def with_start_date(self, start_datetime: datetime) -> "ConfigBuilder":
self._config["start_date"] = start_datetime.isoformat()[:-13]+"Z"
return self

def with_lookback_window_in_days(self, number_of_days: int) -> "ConfigBuilder":
self._config["lookback_window_days"] = number_of_days
return self

def with_slice_range_in_days(self, number_of_days: int) -> "ConfigBuilder":
self._config["slice_range"] = number_of_days
return self

def build(self) -> Dict[str, Any]:
return self._config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Any, Dict

from airbyte_cdk.test.mock_http.response_builder import PaginationStrategy


class StripePaginationStrategy(PaginationStrategy):
@staticmethod
def update(response: Dict[str, Any]) -> None:
response["has_more"] = True

0 comments on commit 60e7cdd

Please sign in to comment.