本文整理汇总了Python中shoppingcart.models.CertificateItem类的典型用法代码示例。如果您正苦于以下问题:Python CertificateItem类的具体用法?Python CertificateItem怎么用?Python CertificateItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CertificateItem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_start_purchase
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')
开发者ID:alexmerser,项目名称:lms,代码行数:31,代码来源:test_models.py
示例2: test_single_item_template
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')
开发者ID:Cgruppo,项目名称:edx-platform,代码行数:7,代码来源:test_models.py
示例3: test_refund_cert_callback_before_expiration
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()
开发者ID:alexmerser,项目名称:lms,代码行数:26,代码来源:test_models.py
示例4: test_purchase_item_email_boto_failure
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)
开发者ID:Cgruppo,项目名称:edx-platform,代码行数:7,代码来源:test_models.py
示例5: test_confirmation_email_error
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')
开发者ID:Cgruppo,项目名称:edx-platform,代码行数:27,代码来源:test_models.py
示例6: checkout_with_shoppingcart
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
开发者ID:stvstnfrd,项目名称:edx-platform,代码行数:30,代码来源:views.py
示例7: test_refund_cert_callback_before_expiration_email
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)
开发者ID:alexmerser,项目名称:lms,代码行数:26,代码来源:test_models.py
示例8: test_purchase_twice
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)
开发者ID:DavidGrahamFL,项目名称:edx-platform,代码行数:7,代码来源:test_models.py
示例9: test_refund_cert_callback_before_expiration
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")
开发者ID:kriwil,项目名称:edx-platform,代码行数:27,代码来源:test_models.py
示例10: test_cart_clear
def test_cart_clear(self):
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'verified')
CertificateItem.add_to_order(cart, 'test/course1', self.cost, 'verified')
self.assertEquals(cart.orderitem_set.count(), 2)
cart.clear()
self.assertEquals(cart.orderitem_set.count(), 0)
开发者ID:obenseven,项目名称:edx-platform,代码行数:7,代码来源:test_models.py
示例11: test_get_cart_for_user
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)
开发者ID:obenseven,项目名称:edx-platform,代码行数:8,代码来源:test_models.py
示例12: test_retire_order_cart
def test_retire_order_cart(self):
"""Test that an order in cart can successfully be retired"""
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_key, self.cost, 'honor', currency='usd')
cart.retire()
self.assertEqual(cart.status, 'defunct-cart')
self.assertEqual(cart.orderitem_set.get().status, 'defunct-cart')
开发者ID:alexmerser,项目名称:lms,代码行数:8,代码来源:test_models.py
示例13: test_clear_cart
def test_clear_cart(self):
self.login_user()
PaidCourseRegistration.add_to_order(self.cart, self.course_key)
CertificateItem.add_to_order(self.cart, self.verified_course_key, self.cost, 'honor')
self.assertEquals(self.cart.orderitem_set.count(), 2)
resp = self.client.post(reverse('shoppingcart.views.clear_cart', args=[]))
self.assertEqual(resp.status_code, 200)
self.assertEquals(self.cart.orderitem_set.count(), 0)
开发者ID:Appius,项目名称:edx-platform,代码行数:8,代码来源:test_views.py
示例14: test_cart_clear
def test_cart_clear(self):
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_key, self.cost, 'honor')
CertificateItem.add_to_order(cart, SlashSeparatedCourseKey('org', 'test', 'Test_Course_1'), self.cost, 'honor')
self.assertEquals(cart.orderitem_set.count(), 2)
self.assertTrue(cart.has_items())
cart.clear()
self.assertEquals(cart.orderitem_set.count(), 0)
self.assertFalse(cart.has_items())
开发者ID:DevCode1,项目名称:edx-platform,代码行数:9,代码来源:test_models.py
示例15: test_user_cart_has_both_items
def test_user_cart_has_both_items(self):
"""
This test exists b/c having both CertificateItem and PaidCourseRegistration in an order used to break
PaidCourseRegistration.contained_in_order
"""
cart = Order.get_cart_for_user(self.user)
CertificateItem.add_to_order(cart, self.course_key, self.cost, 'honor')
PaidCourseRegistration.add_to_order(self.cart, self.course_key)
self.assertTrue(PaidCourseRegistration.contained_in_order(cart, self.course_key))
开发者ID:alexmerser,项目名称:lms,代码行数:9,代码来源:test_models.py
示例16: _enroll
def _enroll(self, purchase=True):
# pylint: disable=missing-docstring
CourseEnrollment.enroll(self.student, self.course_id, self.course_mode.mode_slug)
if purchase:
self.order = Order.get_cart_for_user(self.student)
CertificateItem.add_to_order(self.order, self.course_id, 1, self.course_mode.mode_slug)
self.order.purchase()
self.course_mode.expiration_datetime = datetime.datetime(1983, 4, 6, tzinfo=pytz.UTC)
self.course_mode.save()
开发者ID:edx,项目名称:edx-platform,代码行数:9,代码来源:test_refund.py
示例17: test_cart_clear
def test_cart_clear(self):
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'honor')
CertificateItem.add_to_order(cart, 'org/test/Test_Course_1', self.cost, 'honor')
self.assertEquals(cart.orderitem_set.count(), 2)
self.assertTrue(cart.has_items())
cart.clear()
self.assertEquals(cart.orderitem_set.count(), 0)
self.assertFalse(cart.has_items())
开发者ID:DavidGrahamFL,项目名称:edx-platform,代码行数:9,代码来源:test_models.py
示例18: test_existing_enrollment
def test_existing_enrollment(self):
CourseEnrollment.enroll(self.user, self.course_id)
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'verified')
# verify that we are still enrolled
self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_id))
cart.purchase()
enrollment = CourseEnrollment.objects.get(user=self.user, course_id=self.course_id)
self.assertEquals(enrollment.mode, u'verified')
开发者ID:obenseven,项目名称:edx-platform,代码行数:9,代码来源:test_models.py
示例19: create_order
def create_order(request):
"""
Submit PhotoVerification and create a new Order for this verified cert
"""
if not SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user):
attempt = SoftwareSecurePhotoVerification(user=request.user)
b64_face_image = request.POST['face_image'].split(",")[1]
b64_photo_id_image = request.POST['photo_id_image'].split(",")[1]
attempt.upload_face_image(b64_face_image.decode('base64'))
attempt.upload_photo_id_image(b64_photo_id_image.decode('base64'))
attempt.mark_ready()
attempt.save()
course_id = request.POST['course_id']
course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
donation_for_course = request.session.get('donation_for_course', {})
current_donation = donation_for_course.get(course_id, decimal.Decimal(0))
contribution = request.POST.get("contribution", donation_for_course.get(course_id, 0))
try:
amount = decimal.Decimal(contribution).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_DOWN)
except decimal.InvalidOperation:
return HttpResponseBadRequest(_("Selected price is not valid number."))
if amount != current_donation:
donation_for_course[course_id] = amount
request.session['donation_for_course'] = donation_for_course
# prefer professional mode over verified_mode
current_mode = CourseMode.verified_mode_for_course(course_id)
if current_mode.slug == 'professional':
amount = current_mode.min_price
# make sure this course has a verified mode
if not current_mode:
return HttpResponseBadRequest(_("This course doesn't support verified certificates"))
if amount < current_mode.min_price:
return HttpResponseBadRequest(_("No selected price or selected price is below minimum."))
# I know, we should check this is valid. All kinds of stuff missing here
cart = Order.get_cart_for_user(request.user)
cart.clear()
enrollment_mode = current_mode.slug
CertificateItem.add_to_order(cart, course_id, amount, enrollment_mode)
callback_url = request.build_absolute_uri(
reverse("shoppingcart.views.postpay_callback")
)
params = get_signed_purchase_params(
cart, callback_url=callback_url
)
return HttpResponse(json.dumps(params), content_type="text/json")
开发者ID:VeritasU,项目名称:edx-platform,代码行数:56,代码来源:views.py
示例20: test_refund_cert_callback_no_expiration
def test_refund_cert_callback_no_expiration(self):
# When there is no expiration date on a verified mode, the user can always get a refund
CourseEnrollment.enroll(self.user, self.course_id, 'verified')
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'verified')
cart.purchase()
CourseEnrollment.unenroll(self.user, self.course_id)
target_certs = CertificateItem.objects.filter(course_id=self.course_id, user_id=self.user, status='refunded', mode='verified')
self.assertTrue(target_certs[0])
开发者ID:CEIT-UQ,项目名称:edx-platform,代码行数:10,代码来源:test_models.py
注:本文中的shoppingcart.models.CertificateItem类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论