Skip to content

Commit 7669864

Browse files
committed
Add tests for the prices API.
1 parent 8d9b94c commit 7669864

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

localstripe/resources.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,8 +2581,8 @@ class Price(StripeObject):
25812581
_id_prefix = 'price_'
25822582

25832583
def __init__(self, id=None, active=None, currency=None, metadata=None,
2584-
nickname=None, product=None, recurring=None, unit_amount=None,
2585-
**kwargs):
2584+
nickname=None, product=None, product_data=None,
2585+
recurring=None, unit_amount=None, **kwargs):
25862586
if kwargs:
25872587
raise UserError(400, 'Unexpected ' + ', '.join(kwargs.keys()))
25882588

@@ -2609,6 +2609,10 @@ def __init__(self, id=None, active=None, currency=None, metadata=None,
26092609
# TODO: Add support for "meter" and "usage_type".
26102610
if product is not None:
26112611
Product._api_retrieve(product) # to return 404 if not existant
2612+
if product_data is not None:
2613+
assert isinstance(product_data, dict)
2614+
assert 'name' in product_data
2615+
product = Product(name=product_data['name']).id
26122616

26132617
super().__init__(id)
26142618

@@ -3357,8 +3361,10 @@ def _update(self, metadata=None, items=None, trial_end=None,
33573361
) or (
33583362
self.price and
33593363
(
3360-
self.price.interval != old_price.interval or
3361-
self.price.interval_count != old_price.interval_count
3364+
self.price.recurring.get('interval') !=
3365+
old_price.recurring.get('interval') or
3366+
self.price.recurring.get('interval_count') !=
3367+
old_price.recurring.get('interval_count')
33623368
)
33633369
)
33643370
if create_an_invoice:
@@ -3458,7 +3464,7 @@ def _current_period(self):
34583464
'week': timedelta(weeks=1),
34593465
'month': relativedelta(months=1),
34603466
'year': relativedelta(years=1)
3461-
}[self.price.interval]
3467+
}[self.price.recurring['interval']]
34623468
if self.price is None:
34633469
assert self.plan is not None
34643470
if self.plan.interval == 'day':

test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,3 +1279,24 @@ inv=$(curl -sSfg -u $SK: $HOST/v1/subscriptions \
12791279
total=$(curl -sSfg -u $SK: $HOST/v1/invoices/$inv \
12801280
| grep -oP '"total": \K([0-9]+)' )
12811281
[ "$total" -eq 16383 ]
1282+
1283+
# Create a price under an existing product.
1284+
curl -sSfg -u $SK: $HOST/v1/prices \
1285+
-d id=price_abc001 \
1286+
-d currency=usd \
1287+
-d unit_amount=1000 \
1288+
-d recurring[interval]=month \
1289+
-d product=PRODUCT1234
1290+
1291+
# Create a price and create a new product as a side-effect.
1292+
curl -sSfg -u $SK: $HOST/v1/prices \
1293+
-d id=price_abc002 \
1294+
-d currency=usd \
1295+
-d unit_amount=10000 \
1296+
-d recurring[interval]=year \
1297+
-d product_data[name]=Gold\ Plan
1298+
1299+
# Subscribe a user to an existing price.
1300+
curl -sSfg -u $SK: $HOST/v1/subscriptions \
1301+
-d customer=$cus \
1302+
-d items[0][price]=price_abc001

0 commit comments

Comments
 (0)