Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,13 @@ def expected_full_table_streams(self):
self.expected_replication_method().items()
if rep_meth == self.FULL)

def ensure_available_balance(self):
if not self.get_credentials().get('client_secret'):
@classmethod
def ensure_available_balance(cls):
if not cls.get_credentials().get('client_secret'):
raise RuntimeError("No or invalid API key provided.")

stripe_client.api_version = '2022-11-15'
stripe_client.api_key = BaseTapTest.get_credentials()["client_secret"]
stripe_client.api_key = cls.get_credentials()["client_secret"]

balance_information = stripe_client.Balance.retrieve()
available_balances = balance_information.get('available', [])
Expand All @@ -202,18 +203,29 @@ def ensure_available_balance(self):
for balance in available_balances:
if balance.get('currency') == 'usd' and balance.get('amount', 0) + pending_amount_usd <= 100000:
stripe_client.PaymentIntent.create(
amount=100000,
amount=1000000,
currency="usd",
customer="cus_LAXuu6qTrq8LSf",
confirm=True,
)
break


@classmethod
def setUpClass(cls):
"""Run the class-level balance ensure (so setUpClass-level creates are safe)."""
# run the existing ensure_available_balance logic early
cls.ensure_available_balance()

# call parent setUpClass if present
try:
super(BaseTapTest, cls).setUpClass()
except AttributeError:
pass

def setUp(self):
"""Verify that you have set the prerequisites to run the tap (creds, etc.)"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to call it in both places right?

Copy link
Contributor Author

@nk7up nk7up Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mainly kept as a safety net kind of to check if the classmethod works or not. I can remove it.

env_keys = {'TAP_STRIPE_CLIENT_SECRET'}
self.ensure_available_balance()
env_keys = {'TAP_STRIPE_CLIENT_SECRET'}
missing_envs = [x for x in env_keys if os.getenv(x) is None]
if missing_envs:
raise Exception("Set environment variables: {}".format(missing_envs))
Expand Down
15 changes: 8 additions & 7 deletions tests/test_all_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Original Ticket [https://stitchdata.atlassian.net/browse/SRCE-4736]
KNOWN_MISSING_FIELDS = {
'customers': {
'default_currency',
'default_currency'
},
'subscriptions': {
'automatic_tax',
Expand All @@ -26,7 +26,7 @@
'on_behalf_of',
'payment_settings',
'pending_update',
'trial_settings',
'trial_settings'
},
'products': {
'features',
Expand All @@ -47,7 +47,7 @@
},
'plans': set(),
'invoice_line_items': {
'margins',
'margins'
},
'invoices': {
'amount_shipping',
Expand All @@ -56,7 +56,7 @@
'latest_revision',
'rendering',
'shipping_cost',
'shipping_details',
'shipping_details'
},
'payment_intents': {
'excluded_payment_method_types',
Expand All @@ -76,7 +76,7 @@
'currency',
'description',
'invoice_settings',
'test_clock',
'test_clock'
},
'products': {
'default_price'
Expand All @@ -103,7 +103,7 @@
'rendering_options',
'subtotal_excluding_tax',
'test_clock',
'total_excluding_tax'
'total_excluding_tax',
},
'payment_intents': {
'amount_details',
Expand Down Expand Up @@ -217,7 +217,8 @@
'invoice_item'
},
'payment_intents': {
'charges'
'charges',
'customer_account'
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def get_catalogs(conn_id, streams: list = None):

return found_catalogs


def activate_tracking():
"""
Start tracking objects that are created in util_stripe but
Expand Down Expand Up @@ -564,6 +563,8 @@ def create_object(stream):
# transfer_group=, # CONNECT only
)

BaseTapTest.ensure_available_balance()

if stream == 'transfers':
return client[stream].create(
amount=1,
Expand Down
Loading