diff --git a/tests/base.py b/tests/base.py index daf51f5..150173a 100644 --- a/tests/base.py +++ b/tests/base.py @@ -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', []) @@ -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.)""" - 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)) diff --git a/tests/test_all_fields.py b/tests/test_all_fields.py index a646f61..f44a183 100644 --- a/tests/test_all_fields.py +++ b/tests/test_all_fields.py @@ -16,7 +16,7 @@ # Original Ticket [https://stitchdata.atlassian.net/browse/SRCE-4736] KNOWN_MISSING_FIELDS = { 'customers': { - 'default_currency', + 'default_currency' }, 'subscriptions': { 'automatic_tax', @@ -26,7 +26,7 @@ 'on_behalf_of', 'payment_settings', 'pending_update', - 'trial_settings', + 'trial_settings' }, 'products': { 'features', @@ -47,7 +47,7 @@ }, 'plans': set(), 'invoice_line_items': { - 'margins', + 'margins' }, 'invoices': { 'amount_shipping', @@ -56,7 +56,7 @@ 'latest_revision', 'rendering', 'shipping_cost', - 'shipping_details', + 'shipping_details' }, 'payment_intents': { 'excluded_payment_method_types', @@ -76,7 +76,7 @@ 'currency', 'description', 'invoice_settings', - 'test_clock', + 'test_clock' }, 'products': { 'default_price' @@ -103,7 +103,7 @@ 'rendering_options', 'subtotal_excluding_tax', 'test_clock', - 'total_excluding_tax' + 'total_excluding_tax', }, 'payment_intents': { 'amount_details', @@ -217,7 +217,8 @@ 'invoice_item' }, 'payment_intents': { - 'charges' + 'charges', + 'customer_account' } } diff --git a/tests/utils.py b/tests/utils.py index 2ee63c7..0a830bd 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -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 @@ -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,