Skip to content

Commit

Permalink
Fix stripe import error, fix random failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
BerglundDaniel committed Dec 12, 2023
1 parent 02f0dd4 commit bbc0bc9
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion api/src/shop/stripe_charge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from logging import getLogger

import stripe
from stripe.error import InvalidRequestError, CardError, StripeError
from stripe import StripeError, InvalidRequestError, CardError

from service.error import InternalServerError, EXCEPTION
from shop.models import Transaction
Expand Down
2 changes: 1 addition & 1 deletion api/src/shop/stripe_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import stripe

from stripe.error import InvalidRequestError
from stripe import InvalidRequestError
from shop.stripe_util import retry, are_metadata_dicts_equivalent
from service.db import db_session
from service.error import NotFound, InternalServerError
Expand Down
2 changes: 1 addition & 1 deletion api/src/shop/stripe_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, Dict, List, Optional

import stripe
from stripe.error import SignatureVerificationError, RateLimitError
from stripe import SignatureVerificationError, RateLimitError
from datetime import timezone
from shop import stripe_subscriptions
import shop.transactions
Expand Down
2 changes: 1 addition & 1 deletion api/src/shop/stripe_payment_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing_extensions import Never
from dataclasses_json import DataClassJsonMixin
import stripe
from stripe.error import InvalidRequestError, StripeError, CardError
from stripe import InvalidRequestError, CardError

from stripe import PaymentIntent
from membership.models import Member
Expand Down
4 changes: 2 additions & 2 deletions api/src/shop/stripe_product_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_stripe_product(makeradmin_product: Product) -> stripe.Product | None:
id = get_stripe_product_id(makeradmin_product)
try:
return retry(lambda: stripe.Product.retrieve(id=id))
except stripe.error.InvalidRequestError as e:
except stripe.InvalidRequestError as e:
logger.warning(
f"failed to retrive product from stripe for makeradmin product with id {makeradmin_product.id}, {e}"
)
Expand All @@ -60,7 +60,7 @@ def get_stripe_prices(
) -> list[stripe.Price] | None:
try:
return list(retry(lambda: stripe.Price.list(product=stripe_product.stripe_id, lookup_keys=lookup_keys)))
except stripe.error.InvalidRequestError as e:
except stripe.InvalidRequestError as e:
logger.warning(f"failed to retrive prices from stripe for stripe product with id {stripe_product.id}, {e}")
return None

Expand Down
2 changes: 1 addition & 1 deletion api/src/shop/stripe_setup_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from shop.stripe_payment_intent import PaymentAction
from shop.transactions import PaymentFailed
from stripe import SetupIntent
from stripe.error import CardError
from stripe import CardError


class SetupIntentResult(str, Enum):
Expand Down
10 changes: 5 additions & 5 deletions api/src/shop/stripe_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import stripe

from datetime import datetime, timezone, date, time, timedelta
from stripe.error import InvalidRequestError
from stripe import InvalidRequestError
from shop.stripe_util import are_metadata_dicts_equivalent, retry, convert_from_stripe_amount
from shop.stripe_customer import get_and_sync_stripe_customer
from basic_types.enums import PriceLevel
Expand All @@ -53,7 +53,7 @@
CURRENCY,
)
from shop.stripe_constants import SubscriptionStatus
import stripe.error
import stripe


class SubscriptionType(str, Enum):
Expand Down Expand Up @@ -592,7 +592,7 @@ def pause_subscription(
return True
else:
assert False
except stripe.error.InvalidRequestError as e:
except stripe.InvalidRequestError as e:
if e.code == "resource_missing":
# The subscription was already deleted
# We might have missed the webhook to delete the reference from the member.
Expand Down Expand Up @@ -649,7 +649,7 @@ def cancel_subscription(
stripe.Subscription.delete(subscription_id)
else:
assert False
except stripe.error.InvalidRequestError as e:
except stripe.InvalidRequestError as e:
if e.code == "resource_missing":
# The subscription was already deleted.
# We might have missed the webhook to delete the reference from the member.
Expand Down Expand Up @@ -709,7 +709,7 @@ def get_subscription_info_from_subscription(sub_type: SubscriptionType, sub_id:
amount_due=Decimal(upcoming["amount_due"]) / STRIPE_CURRENTY_BASE,
),
)
except stripe.error.InvalidRequestError as e:
except stripe.InvalidRequestError as e:
if e.code == "invoice_upcoming_none":
return SubscriptionInfo(
type=sub_type,
Expand Down
2 changes: 1 addition & 1 deletion api/src/shop/stripe_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def retry(f: Callable[[], T]) -> T:
while True:
try:
return f()
except stripe.error.RateLimitError:
except stripe.RateLimitError:
its += 1
if its > MAX_TRIES:
raise
Expand Down
8 changes: 4 additions & 4 deletions api/src/shop/test/stripe_product_price_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def test_get_sync_product(self) -> None:
makeradmin_test_product = self.db.create_product(
name="test update product",
price=100.0,
id=self.base_stripe_id + 6,
id=self.base_stripe_id + 8,
unit="mån",
smallest_multiple=1,
category_id=self.subscription_category.id,
Expand All @@ -319,7 +319,7 @@ def test_get_sync_price(self) -> None:
makeradmin_test_product = self.db.create_product(
name="test update price",
price=100.0,
id=self.base_stripe_id + 7,
id=self.base_stripe_id + 9,
unit="mån",
smallest_multiple=1,
category_id=self.not_subscription_category.id,
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_equal_product(self) -> None:
makeradmin_test_eq_product = self.db.create_product(
name="test eq price",
price=200.0,
id=self.base_stripe_id + 8,
id=self.base_stripe_id + 10,
unit="mån",
smallest_multiple=1,
category_id=self.subscription_category.id,
Expand Down Expand Up @@ -381,7 +381,7 @@ def test_equal_price(self) -> None:
makeradmin_test_eq_product = self.db.create_product(
name="test eq price",
price=200.0,
id=self.base_stripe_id + 9,
id=self.base_stripe_id + 11,
unit="mån",
smallest_multiple=1,
category_id=self.subscription_category.id,
Expand Down
4 changes: 2 additions & 2 deletions api/src/shop/test/subscriptions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from shop.transactions import ship_orders
from test_aid.test_base import FlaskTestBase
import stripe
import stripe.error
import stripe
from shop import stripe_event
from shop import stripe_constants

Expand Down Expand Up @@ -221,7 +221,7 @@ def test_clock_for_event(event: Any) -> Optional[str]:
logger.info("Clock is ready. Waiting a bit to make sure we have received all events...")
done = 1
break
except stripe.error.RateLimitError:
except stripe.RateLimitError:
logger.warning("Exceeded Stripe API rate limit. Waiting a bit...")
# This is most likely because we are running tests in parallel.
# Add some jitter to avoid the stripe tests from running so much in parallel.
Expand Down
4 changes: 2 additions & 2 deletions api/src/systest/api/member_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def test_create_member_gives_new_member_numbers_and_ids(self):
self.assertNotEqual(number1, number2)

def test_create_password_using_unhashed_password(self):
pwd = random_str(8)
pwd = random_str(16)
member = self.api.create_member(password=None, unhashed_password=pwd)
self.post("/oauth/token", {"grant_type": "password", "username": member["email"], "password": pwd}).expect(
code=200
)

def test_update_password_using_unhashed_password(self):
pwd = random_str(8)
pwd = random_str(16)
member = self.db.create_member()
self.put(f"/membership/member/{member.member_id}", dict(unhashed_password=pwd)).expect(200)
self.post("/oauth/token", {"grant_type": "password", "username": member.email, "password": pwd}).expect(
Expand Down

0 comments on commit bbc0bc9

Please sign in to comment.