Don't try to purchase the same order twice

This commit is contained in:
Diana Huang
2013-09-18 09:41:27 -04:00
parent 0e2d833a2e
commit 67af3d5ced
2 changed files with 10 additions and 1 deletions

View File

@@ -105,6 +105,8 @@ class Order(models.Model):
`processor_reply_dump` - all the parameters returned by the processor
"""
if self.status == 'purchased':
return
self.status = 'purchased'
self.purchase_time = datetime.now(pytz.utc)
self.bill_to_first = first

View File

@@ -103,6 +103,14 @@ class OrderTest(ModuleStoreTestCase):
# verify that e-mail wasn't sent
self.assertEquals(len(mail.outbox), 0)
def test_purchase_twice(self):
cart = Order.get_cart_for_user(self.user)
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'honor')
# purchase the cart more than once
cart.purchase()
cart.purchase()
self.assertEquals(len(mail.outbox), 1)
def purchase_with_data(self, cart):
""" purchase a cart with billing information """
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'honor')
@@ -136,7 +144,6 @@ class OrderTest(ModuleStoreTestCase):
@patch.dict(settings.MITX_FEATURES, {'STORE_BILLING_INFO': False})
def test_billing_info_storage_off(self):
cart = Order.get_cart_for_user(self.user)
cart = Order.get_cart_for_user(self.user)
self.purchase_with_data(cart)
self.assertNotEqual(cart.bill_to_first, '')