From 67af3d5ced3a95ff6e490e8ec5cd1fcb43357432 Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Wed, 18 Sep 2013 09:41:27 -0400 Subject: [PATCH] Don't try to purchase the same order twice --- lms/djangoapps/shoppingcart/models.py | 2 ++ lms/djangoapps/shoppingcart/tests/test_models.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index 65e25280ab..368a327fc9 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -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 diff --git a/lms/djangoapps/shoppingcart/tests/test_models.py b/lms/djangoapps/shoppingcart/tests/test_models.py index eeec58f47a..f145997145 100644 --- a/lms/djangoapps/shoppingcart/tests/test_models.py +++ b/lms/djangoapps/shoppingcart/tests/test_models.py @@ -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, '')