本文整理汇总了Python中shoppingcart.models.Order类的典型用法代码示例。如果您正苦于以下问题:Python Order类的具体用法?Python Order怎么用?Python Order使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Order类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_course_registration_features
def test_course_registration_features(self):
query_features = [
'code', 'redeem_code_url', 'course_id', 'company_name', 'created_by',
'redeemed_by', 'invoice_id', 'purchaser', 'customer_reference_number', 'internal_reference'
]
order = Order(user=self.instructor, status='purchased')
order.save()
registration_code_redemption = RegistrationCodeRedemption(
registration_code_id=1, redeemed_by=self.instructor
)
registration_code_redemption.save()
registration_codes = CourseRegistrationCode.objects.all()
course_registration_list = course_registration_features(query_features, registration_codes, csv_type='download')
self.assertEqual(len(course_registration_list), len(registration_codes))
for course_registration in course_registration_list:
self.assertEqual(set(course_registration.keys()), set(query_features))
self.assertIn(course_registration['code'], [registration_code.code for registration_code in registration_codes])
self.assertIn(
course_registration['course_id'],
[registration_code.course_id.to_deprecated_string() for registration_code in registration_codes]
)
self.assertIn(
course_registration['company_name'],
[getattr(registration_code.invoice, 'company_name') for registration_code in registration_codes]
)
self.assertIn(
course_registration['invoice_id'],
[registration_code.invoice_id for registration_code in registration_codes]
)
示例2: test_course_registration_features
def test_course_registration_features(self):
query_features = ['code', 'course_id', 'transaction_group_name', 'created_by', 'redeemed_by']
for i in range(5):
course_code = CourseRegistrationCode(
code="test_code{}".format(i), course_id=self.course_key.to_deprecated_string(),
transaction_group_name='TestName', created_by=self.users[0]
)
course_code.save()
order = Order(user=self.users[0], status='purchased')
order.save()
registration_code_redemption = RegistrationCodeRedemption(
order=order, registration_code_id=1, redeemed_by=self.users[0]
)
registration_code_redemption.save()
registration_codes = CourseRegistrationCode.objects.all()
course_registration_list = course_registration_features(query_features, registration_codes, csv_type='download')
self.assertEqual(len(course_registration_list), len(registration_codes))
for course_registration in course_registration_list:
self.assertEqual(set(course_registration.keys()), set(query_features))
self.assertIn(course_registration['code'], [registration_code.code for registration_code in registration_codes])
self.assertIn(
course_registration['course_id'],
[registration_code.course_id.to_deprecated_string() for registration_code in registration_codes]
)
self.assertIn(
course_registration['transaction_group_name'],
[registration_code.transaction_group_name for registration_code in registration_codes]
)
示例3: 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')
示例4: test_user_cart_has_items
def test_user_cart_has_items(self):
anon = AnonymousUser()
self.assertFalse(Order.user_cart_has_items(anon))
self.assertFalse(Order.user_cart_has_items(self.user))
cart = Order.get_cart_for_user(self.user)
item = OrderItem(order=cart, user=self.user)
item.save()
self.assertTrue(Order.user_cart_has_items(self.user))
示例5: 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)
示例6: checkout
def checkout(request):
store = Store.objects.get(subdomain=request.subdomain)
cart = get_cart(request)
if cart == {}:
return redirect("/products/")
try:
order = Order(user=request.session["user"], store=store)
order.save()
except KeyError:
return redirect("/home/", {"error_message": "Please sign in"}) #!!!
for product, key in cart.iteritems():
i = Item(product=product, quantity=key, order=order)
i.save()
request.session["cart"] = cart = {}
return render_to_response("checkout.html", {"store_name": store.name})
示例7: test_billing_info_storage_off
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, '')
示例8: _create_cart
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_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)
示例10: 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')
示例11: 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)
示例12: test_student_used_enrollment_code_for_course_enrollment
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')
示例13: 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")
示例14: 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()
示例15: 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')