本文整理汇总了Python中shoppingcart.models.Order.get_cart_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python Order.get_cart_for_user方法的具体用法?Python Order.get_cart_for_user怎么用?Python Order.get_cart_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shoppingcart.models.Order
的用法示例。
在下文中一共展示了Order.get_cart_for_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_start_purchase
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_start_purchase(self):
# Start the purchase, which will mark the cart as "paying"
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_key, self.cost, 'honor', currency='usd')
cart.start_purchase()
self.assertEqual(cart.status, 'paying')
for item in cart.orderitem_set.all():
self.assertEqual(item.status, 'paying')
# Starting the purchase should be idempotent
cart.start_purchase()
self.assertEqual(cart.status, 'paying')
for item in cart.orderitem_set.all():
self.assertEqual(item.status, 'paying')
# If we retrieve the cart for the user, we should get a different order
next_cart = Order.get_cart_for_user(user=self.user)
self.assertNotEqual(cart, next_cart)
self.assertEqual(next_cart.status, 'cart')
# Complete the first purchase
cart.purchase()
self.assertEqual(cart.status, 'purchased')
for item in cart.orderitem_set.all():
self.assertEqual(item.status, 'purchased')
# Starting the purchase again should be a no-op
cart.start_purchase()
self.assertEqual(cart.status, 'purchased')
for item in cart.orderitem_set.all():
self.assertEqual(item.status, 'purchased')
示例2: test_get_cart_for_user
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_get_cart_for_user(self):
# create a cart
cart = Order.get_cart_for_user(user=self.user)
# add something to it
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'verified')
# should return the same cart
cart2 = Order.get_cart_for_user(user=self.user)
self.assertEquals(cart2.orderitem_set.count(), 1)
示例3: test_billing_info_storage_off
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
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, '')
self.assertNotEqual(cart.bill_to_last, '')
self.assertNotEqual(cart.bill_to_city, '')
self.assertNotEqual(cart.bill_to_state, '')
self.assertNotEqual(cart.bill_to_country, '')
self.assertNotEqual(cart.bill_to_postalcode, '')
# things we expect to be missing when the feature is off
self.assertEqual(cart.bill_to_street1, '')
self.assertEqual(cart.bill_to_street2, '')
self.assertEqual(cart.bill_to_ccnum, '')
self.assertEqual(cart.bill_to_cardtype, '')
示例4: test_single_item_template
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_single_item_template(self):
cart = Order.get_cart_for_user(user=self.user)
cert_item = CertificateItem.add_to_order(cart, self.course_key, self.cost, 'verified')
self.assertEquals(cert_item.single_item_receipt_template, 'shoppingcart/receipt.html')
cert_item = CertificateItem.add_to_order(cart, self.course_key, self.cost, 'honor')
self.assertEquals(cert_item.single_item_receipt_template, 'shoppingcart/receipt.html')
示例5: test_confirmation_email_error
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_confirmation_email_error(self):
CourseMode.objects.create(
course_id=self.course_key,
mode_slug="verified",
mode_display_name="Verified",
min_price=self.cost
)
cart = Order.get_cart_for_user(self.user)
CertificateItem.add_to_order(cart, self.course_key, self.cost, 'verified')
# Simulate an error when sending the confirmation
# email. This should NOT raise an exception.
# If it does, then the implicit view-level
# transaction could cause a roll-back, effectively
# reversing order fulfillment.
with patch.object(mail.message.EmailMessage, 'send') as mock_send:
mock_send.side_effect = Exception("Kaboom!")
cart.purchase()
# Verify that the purchase completed successfully
self.assertEqual(cart.status, 'purchased')
# Verify that the user is enrolled as "verified"
mode, is_active = CourseEnrollment.enrollment_mode_for_user(self.user, self.course_key)
self.assertTrue(is_active)
self.assertEqual(mode, 'verified')
示例6: test_purchase_item_email_boto_failure
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_purchase_item_email_boto_failure(self, error_logger):
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_key, self.cost, 'honor')
with patch.object(EmailMessage, 'send') as mock_send:
mock_send.side_effect = BotoServerError("status", "reason")
cart.purchase()
self.assertTrue(error_logger.called)
示例7: test_student_used_enrollment_code_for_course_enrollment
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_student_used_enrollment_code_for_course_enrollment(self):
"""
test to check the user enrollment source and payment status in the
enrollment detailed report
"""
student = UserFactory()
self.client.login(username=student.username, password='test')
student_cart = Order.get_cart_for_user(student)
paid_course_reg_item = PaidCourseRegistration.add_to_order(student_cart, self.course.id)
# update the quantity of the cart item paid_course_reg_item
resp = self.client.post(reverse('shoppingcart.views.update_user_cart'),
{'ItemId': paid_course_reg_item.id, 'qty': '4'})
self.assertEqual(resp.status_code, 200)
student_cart.purchase()
course_reg_codes = CourseRegistrationCode.objects.filter(order=student_cart)
redeem_url = reverse('register_code_redemption', args=[course_reg_codes[0].code])
response = self.client.get(redeem_url)
self.assertEquals(response.status_code, 200)
# check button text
self.assertTrue('Activate Course Enrollment' in response.content)
response = self.client.post(redeem_url)
self.assertEquals(response.status_code, 200)
task_input = {'features': []}
with patch('instructor_task.tasks_helper._get_current_task'):
result = upload_enrollment_report(None, None, self.course.id, task_input, 'generating_enrollment_report')
self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result)
self._verify_cell_data_in_csv(student.username, 'Enrollment Source', 'Used Registration Code')
self._verify_cell_data_in_csv(student.username, 'Payment Status', 'purchased')
示例8: _create_cart
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def _create_cart(self):
"""Creates a cart and adds a CertificateItem to it"""
cart = Order.get_cart_for_user(UserFactory.create())
item = CertificateItem.add_to_order(
cart, self.course_key, 10, 'honor', currency='usd'
)
return cart, item
示例9: test_refund_cert_callback_before_expiration
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_refund_cert_callback_before_expiration(self):
# If the expiration date has not yet passed on a verified mode, the user can be refunded
many_days = datetime.timedelta(days=60)
course = CourseFactory.create()
self.course_key = course.id
course_mode = CourseMode(course_id=self.course_key,
mode_slug="verified",
mode_display_name="verified cert",
min_price=self.cost,
expiration_datetime=(datetime.datetime.now(pytz.utc) + many_days))
course_mode.save()
# need to prevent analytics errors from appearing in stderr
with patch('sys.stderr', sys.stdout.write):
CourseEnrollment.enroll(self.user, self.course_key, 'verified')
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_key, self.cost, 'verified')
cart.purchase()
CourseEnrollment.unenroll(self.user, self.course_key)
target_certs = CertificateItem.objects.filter(course_id=self.course_key, user_id=self.user, status='refunded', mode='verified')
self.assertTrue(target_certs[0])
self.assertTrue(target_certs[0].refund_requested_time)
self.assertEquals(target_certs[0].order.status, 'refunded')
self._assert_refund_tracked()
示例10: setUp
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def setUp(self):
patcher = patch('student.models.tracker')
self.mock_tracker = patcher.start()
self.user = UserFactory.create()
self.user.set_password('password')
self.user.save()
self.instructor = AdminFactory.create()
self.cost = 40
self.coupon_code = 'abcde'
self.reg_code = 'qwerty'
self.percentage_discount = 10
self.course = CourseFactory.create(org='MITx', number='999', display_name='Robot Super Course')
self.course_key = self.course.id
self.course_mode = CourseMode(course_id=self.course_key,
mode_slug="honor",
mode_display_name="honor cert",
min_price=self.cost)
self.course_mode.save()
#Saving another testing course mode
self.testing_cost = 20
self.testing_course = CourseFactory.create(org='edX', number='888', display_name='Testing Super Course')
self.testing_course_mode = CourseMode(course_id=self.testing_course.id,
mode_slug="honor",
mode_display_name="testing honor cert",
min_price=self.testing_cost)
self.testing_course_mode.save()
verified_course = CourseFactory.create(org='org', number='test', display_name='Test Course')
self.verified_course_key = verified_course.id
self.cart = Order.get_cart_for_user(self.user)
self.addCleanup(patcher.stop)
示例11: test_purchase_twice
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
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)
示例12: test_orderItem_purchased_callback
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_orderItem_purchased_callback(self):
"""
This tests that calling purchased_callback on the base OrderItem class raises NotImplementedError
"""
item = OrderItem(user=self.user, order=Order.get_cart_for_user(self.user))
with self.assertRaises(NotImplementedError):
item.purchased_callback()
示例13: checkout_with_shoppingcart
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def checkout_with_shoppingcart(request, user, course_key, course_mode, amount):
""" Create an order and trigger checkout using shoppingcart."""
cart = Order.get_cart_for_user(user)
cart.clear()
enrollment_mode = course_mode.slug
CertificateItem.add_to_order(cart, course_key, amount, enrollment_mode)
# Change the order's status so that we don't accidentally modify it later.
# We need to do this to ensure that the parameters we send to the payment system
# match what we store in the database.
# (Ordinarily we would do this client-side when the user submits the form, but since
# the JavaScript on this page does that immediately, we make the change here instead.
# This avoids a second AJAX call and some additional complication of the JavaScript.)
# If a user later re-enters the verification / payment flow, she will create a new order.
cart.start_purchase()
callback_url = request.build_absolute_uri(
reverse("shoppingcart.views.postpay_callback")
)
payment_data = {
'payment_processor_name': settings.CC_PROCESSOR_NAME,
'payment_page_url': get_purchase_endpoint(),
'payment_form_data': get_signed_purchase_params(
cart,
callback_url=callback_url,
extra_data=[unicode(course_key), course_mode.slug]
),
}
return payment_data
示例14: test_refund_cert_callback_before_expiration_email
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_refund_cert_callback_before_expiration_email(self):
""" Test that refund emails are being sent correctly. """
course = CourseFactory.create()
course_key = course.id
many_days = datetime.timedelta(days=60)
course_mode = CourseMode(course_id=course_key,
mode_slug="verified",
mode_display_name="verified cert",
min_price=self.cost,
expiration_datetime=datetime.datetime.now(pytz.utc) + many_days)
course_mode.save()
CourseEnrollment.enroll(self.user, course_key, 'verified')
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, course_key, self.cost, 'verified')
cart.purchase()
mail.outbox = []
with patch('shoppingcart.models.log.error') as mock_error_logger:
CourseEnrollment.unenroll(self.user, course_key)
self.assertFalse(mock_error_logger.called)
self.assertEquals(len(mail.outbox), 1)
self.assertEquals('[Refund] User-Requested Refund', mail.outbox[0].subject)
self.assertEquals(settings.PAYMENT_SUPPORT_EMAIL, mail.outbox[0].from_email)
self.assertIn('has requested a refund on Order', mail.outbox[0].body)
示例15: test_refund_cert_callback_before_expiration
# 需要导入模块: from shoppingcart.models import Order [as 别名]
# 或者: from shoppingcart.models.Order import get_cart_for_user [as 别名]
def test_refund_cert_callback_before_expiration(self):
# If the expiration date has not yet passed on a verified mode, the user can be refunded
many_days = datetime.timedelta(days=60)
course = CourseFactory.create(org="refund_before_expiration", number="test", display_name="one")
course_key = course.id
course_mode = CourseMode(
course_id=course_key,
mode_slug="verified",
mode_display_name="verified cert",
min_price=self.cost,
expiration_datetime=(datetime.datetime.now(pytz.utc) + many_days),
)
course_mode.save()
CourseEnrollment.enroll(self.user, course_key, "verified")
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, course_key, self.cost, "verified")
cart.purchase()
CourseEnrollment.unenroll(self.user, course_key)
target_certs = CertificateItem.objects.filter(
course_id=course_key, user_id=self.user, status="refunded", mode="verified"
)
self.assertTrue(target_certs[0])
self.assertTrue(target_certs[0].refund_requested_time)
self.assertEquals(target_certs[0].order.status, "refunded")