本文整理汇总了Python中shoppingcart.models.Coupon类的典型用法代码示例。如果您正苦于以下问题:Python Coupon类的具体用法?Python Coupon怎么用?Python Coupon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Coupon类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_update_coupon
def test_update_coupon(self):
"""
Test Update Coupon Info Scenarios. Handle all the HttpResponses return by update_coupon view
"""
coupon = Coupon(
code='AS452', description='asdsadsa', course_id=text_type(self.course.id),
percentage_discount=10, created_by=self.instructor
)
coupon.save()
response = self.client.post(self.url)
self.assertIn('<td>AS452</td>', response.content)
data = {
'coupon_id': coupon.id, 'code': 'AS452', 'discount': '10', 'description': 'updated_description',
'course_id': text_type(coupon.course_id)
}
# URL for update_coupon
update_coupon_url = reverse('update_coupon', kwargs={'course_id': text_type(self.course.id)})
response = self.client.post(update_coupon_url, data=data)
self.assertIn(
'coupon with the coupon id ({coupon_id}) updated Successfully'.format(coupon_id=coupon.id),
response.content
)
response = self.client.post(self.url)
self.assertIn('<td>updated_description</td>', response.content)
data['coupon_id'] = 1000 # Coupon Not Exist with this ID
response = self.client.post(update_coupon_url, data=data)
self.assertIn('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=1000), response.content)
data['coupon_id'] = '' # Coupon id is not provided
response = self.client.post(update_coupon_url, data=data)
self.assertIn('coupon id not found', response.content)
开发者ID:EDUlib,项目名称:edx-platform,代码行数:33,代码来源:test_ecommerce.py
示例2: add_coupon
def add_coupon(request, course_id): # pylint: disable=W0613
"""
add coupon in the Coupons Table
"""
code = request.POST.get('code')
# check if the code is already in the Coupons Table and active
try:
course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
coupon = Coupon.objects.get(is_active=True, code=code, course_id=course_id)
except Coupon.DoesNotExist:
# check if the coupon code is in the CourseRegistrationCode Table
course_registration_code = CourseRegistrationCode.objects.filter(code=code)
if course_registration_code:
return HttpResponseNotFound(_(
"The code ({code}) that you have tried to define is already in use as a registration code").format(code=code)
)
description = request.POST.get('description')
course_id = request.POST.get('course_id')
try:
discount = int(request.POST.get('discount'))
except ValueError:
return HttpResponseNotFound(_("Please Enter the Integer Value for Coupon Discount"))
if discount > 100 or discount < 0:
return HttpResponseNotFound(_("Please Enter the Coupon Discount Value Less than or Equal to 100"))
coupon = Coupon(
code=code, description=description, course_id=course_id,
percentage_discount=discount, created_by_id=request.user.id
)
coupon.save()
return HttpResponse(_("coupon with the coupon code ({code}) added successfully").format(code=code))
if coupon:
return HttpResponseNotFound(_("coupon with the coupon code ({code}) already exists for this course").format(code=code))
开发者ID:DevCode1,项目名称:edx-platform,代码行数:35,代码来源:coupons.py
示例3: add_coupon
def add_coupon(request, course_id): # pylint: disable=W0613
"""
add coupon in the Coupons Table
"""
code = request.POST.get('code')
# check if the code is already in the Coupons Table and active
coupon = Coupon.objects.filter(is_active=True, code=code)
if coupon:
return HttpResponseNotFound(_("coupon with the coupon code ({code}) already exist").format(code=code))
description = request.POST.get('description')
course_id = request.POST.get('course_id')
try:
discount = int(request.POST.get('discount'))
except ValueError:
return HttpResponseNotFound(_("Please Enter the Integer Value for Coupon Discount"))
if discount > 100:
return HttpResponseNotFound(_("Please Enter the Coupon Discount Value Less than or Equal to 100"))
coupon = Coupon(
code=code, description=description, course_id=course_id,
percentage_discount=discount, created_by_id=request.user.id
)
coupon.save()
return HttpResponse(_("coupon with the coupon code ({code}) added successfully").format(code=code))
开发者ID:AsylumCorp,项目名称:edx-platform,代码行数:26,代码来源:coupons.py
示例4: add_coupon
def add_coupon(self, course_key, is_active):
"""
add dummy coupon into models
"""
coupon = Coupon(code=self.coupon_code, description='testing code', course_id=course_key,
percentage_discount=self.percentage_discount, created_by=self.user, is_active=is_active)
coupon.save()
开发者ID:Appius,项目名称:edx-platform,代码行数:7,代码来源:test_views.py
示例5: add_coupon
def add_coupon(request, course_id): # pylint: disable=unused-argument
"""
add coupon in the Coupons Table
"""
code = request.POST.get('code')
# check if the code is already in the Coupons Table and active
try:
course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
coupon = Coupon.objects.get(is_active=True, code=code, course_id=course_id)
except Coupon.DoesNotExist:
# check if the coupon code is in the CourseRegistrationCode Table
course_registration_code = CourseRegistrationCode.objects.filter(code=code)
if course_registration_code:
return JsonResponse(
{'message': _("The code ({code}) that you have tried to define is already in use as a registration code").format(code=code)},
status=400) # status code 400: Bad Request
description = request.POST.get('description')
course_id = request.POST.get('course_id')
try:
discount = int(request.POST.get('discount'))
except ValueError:
return JsonResponse({
'message': _("Please Enter the Integer Value for Coupon Discount")
}, status=400) # status code 400: Bad Request
if discount > 100 or discount < 0:
return JsonResponse({
'message': _("Please Enter the Coupon Discount Value Less than or Equal to 100")
}, status=400) # status code 400: Bad Request
expiration_date = None
if request.POST.get('expiration_date'):
expiration_date = request.POST.get('expiration_date')
try:
expiration_date = datetime.datetime.strptime(expiration_date, "%m/%d/%Y").replace(tzinfo=pytz.UTC) + datetime.timedelta(days=1)
except ValueError:
return JsonResponse({
'message': _("Please enter the date in this format i-e month/day/year")
}, status=400) # status code 400: Bad Request
coupon = Coupon(
code=code, description=description,
course_id=course_id,
percentage_discount=discount,
created_by_id=request.user.id,
expiration_date=expiration_date
)
coupon.save()
return JsonResponse(
{'message': _("coupon with the coupon code ({code}) added successfully").format(code=code)}
)
if coupon:
return JsonResponse(
{'message': _("coupon with the coupon code ({code}) already exists for this course").format(code=code)},
status=400) # status code 400: Bad Request
开发者ID:189140879,项目名称:edx-platform,代码行数:57,代码来源:coupons.py
示例6: test_soft_delete_coupon
def test_soft_delete_coupon(self): # pylint: disable=E1101
self.add_coupon(self.course_key, True)
coupon = Coupon(code='TestCode', description='testing', course_id=self.course_key,
percentage_discount=12, created_by=self.user, is_active=True)
coupon.save()
self.assertEquals(coupon.__unicode__(), '[Coupon] code: TestCode course: MITx/999/Robot_Super_Course')
admin = User.objects.create_user('Mark', '[email protected]', 'foo')
admin.is_staff = True
get_coupon = Coupon.objects.get(id=1)
request = HttpRequest()
request.user = admin
setattr(request, 'session', 'session') # pylint: disable=E1101
messages = FallbackStorage(request) # pylint: disable=E1101
setattr(request, '_messages', messages) # pylint: disable=E1101
coupon_admin = SoftDeleteCouponAdmin(Coupon, AdminSite())
test_query_set = coupon_admin.queryset(request)
test_actions = coupon_admin.get_actions(request)
self.assertTrue('really_delete_selected' in test_actions['really_delete_selected'])
self.assertEqual(get_coupon.is_active, True)
coupon_admin.really_delete_selected(request, test_query_set) # pylint: disable=E1101
for coupon in test_query_set:
self.assertEqual(coupon.is_active, False)
coupon_admin.delete_model(request, get_coupon) # pylint: disable=E1101
self.assertEqual(get_coupon.is_active, False)
coupon = Coupon(code='TestCode123', description='testing123', course_id=self.course_key,
percentage_discount=22, created_by=self.user, is_active=True)
coupon.save()
test_query_set = coupon_admin.queryset(request)
coupon_admin.really_delete_selected(request, test_query_set) # pylint: disable=E1101
for coupon in test_query_set:
self.assertEqual(coupon.is_active, False)
开发者ID:Appius,项目名称:edx-platform,代码行数:32,代码来源:test_views.py
示例7: test_update_coupon
def test_update_coupon(self):
"""
Test Update Coupon Info Scenarios. Handle all the HttpResponses return by update_coupon view
"""
coupon = Coupon(
code="AS452",
description="asdsadsa",
course_id=self.course.id.to_deprecated_string(),
percentage_discount=10,
created_by=self.instructor,
)
coupon.save()
response = self.client.post(self.url)
self.assertTrue("<td>AS452</td>" in response.content)
data = {
"coupon_id": coupon.id,
"code": "AS452",
"discount": "10",
"description": "updated_description", # pylint: disable=no-member
"course_id": coupon.course_id.to_deprecated_string(),
}
# URL for update_coupon
update_coupon_url = reverse("update_coupon", kwargs={"course_id": self.course.id.to_deprecated_string()})
response = self.client.post(update_coupon_url, data=data)
self.assertTrue(
"coupon with the coupon id ({coupon_id}) updated Successfully".format(coupon_id=coupon.id)
in response.content
)
response = self.client.post(self.url)
self.assertTrue("<td>updated_description</td>" in response.content)
data["coupon_id"] = 1000 # Coupon Not Exist with this ID
response = self.client.post(update_coupon_url, data=data)
self.assertTrue(
"coupon with the coupon id ({coupon_id}) DoesNotExist".format(coupon_id=1000) in response.content
)
data["coupon_id"] = "" # Coupon id is not provided
response = self.client.post(update_coupon_url, data=data)
self.assertTrue("coupon id not found" in response.content)
开发者ID:dmohrC,项目名称:edx-platform,代码行数:41,代码来源:test_ecommerce.py
示例8: add_coupon
def add_coupon(request, course_id): # pylint: disable=W0613
"""
add coupon in the Coupons Table
"""
code = request.POST.get('code')
# check if the code is already in the Coupons Table and active
coupon = Coupon.objects.filter(is_active=True, code=code)
if coupon:
return HttpResponseNotFound(_("coupon with the coupon code ({code}) already exist").format(code=code))
description = request.POST.get('description')
course_id = request.POST.get('course_id')
discount = request.POST.get('discount')
coupon = Coupon(
code=code, description=description, course_id=course_id,
percentage_discount=discount, created_by_id=request.user.id
)
coupon.save()
return HttpResponse(_("coupon with the coupon code ({code}) added successfully").format(code=code))
开发者ID:AshWilliams,项目名称:edx-platform,代码行数:21,代码来源:coupons.py
示例9: test_coupon_codes_features
def test_coupon_codes_features(self):
query_features = [
'course_id', 'percentage_discount', 'code_redeemed_count', 'description'
]
for i in range(10):
coupon = Coupon(
code='test_code{0}'.format(i), description='test_description', course_id=self.course.id,
percentage_discount='{0}'.format(i), created_by=self.instructor, is_active=True
)
coupon.save()
active_coupons = Coupon.objects.filter(course_id=self.course.id, is_active=True)
active_coupons_list = coupon_codes_features(query_features, active_coupons)
self.assertEqual(len(active_coupons_list), len(active_coupons))
for active_coupon in active_coupons_list:
self.assertEqual(set(active_coupon.keys()), set(query_features))
self.assertIn(active_coupon['percentage_discount'], [coupon.percentage_discount for coupon in active_coupons])
self.assertIn(active_coupon['description'], [coupon.description for coupon in active_coupons])
self.assertIn(
active_coupon['course_id'],
[coupon.course_id.to_deprecated_string() for coupon in active_coupons]
)
开发者ID:adlnet-archive,项目名称:edx-platform,代码行数:21,代码来源:test_basic.py
示例10: test_get_coupon_info
def test_get_coupon_info(self):
"""
Test Edit Coupon Info Scenarios. Handle all the HttpResponses return by edit_coupon_info view
"""
coupon = Coupon(
code='AS452', description='asdsadsa', course_id=self.course.id.to_deprecated_string(),
percentage_discount=10, created_by=self.instructor
)
coupon.save()
# URL for edit_coupon_info
edit_url = reverse('get_coupon_info', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(edit_url, {'id': coupon.id})
self.assertTrue('coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id) in response.content)
response = self.client.post(edit_url, {'id': 444444})
self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=444444) in response.content)
response = self.client.post(edit_url, {'id': ''})
self.assertTrue('coupon id not found"' in response.content)
coupon.is_active = False
coupon.save()
response = self.client.post(edit_url, {'id': coupon.id})
self.assertTrue("coupon with the coupon id ({coupon_id}) is already inactive".format(coupon_id=coupon.id) in response.content)
开发者ID:victorchi2009,项目名称:edx-platform,代码行数:25,代码来源:test_ecommerce.py
示例11: test_delete_coupon
def test_delete_coupon(self):
"""
Test Delete Coupon Scenarios. Handle all the HttpResponses return by remove_coupon view
"""
coupon = Coupon(
code='AS452', description='asdsadsa', course_id=self.course.id.to_deprecated_string(),
percentage_discount=10, created_by=self.instructor
)
coupon.save()
response = self.client.post(self.url)
self.assertTrue('<td>AS452</td>' in response.content)
# URL for remove_coupon
delete_coupon_url = reverse('remove_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(delete_coupon_url, {'id': coupon.id})
self.assertTrue('coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id) in response.content)
coupon.is_active = False
coupon.save()
response = self.client.post(delete_coupon_url, {'id': coupon.id})
self.assertTrue('coupon with the coupon id ({coupon_id}) is already inactive'.format(coupon_id=coupon.id) in response.content)
response = self.client.post(delete_coupon_url, {'id': 24454})
self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=24454) in response.content)
response = self.client.post(delete_coupon_url, {'id': ''})
self.assertTrue('coupon id is None' in response.content)
开发者ID:victorchi2009,项目名称:edx-platform,代码行数:30,代码来源:test_ecommerce.py
示例12: test_update_coupon
def test_update_coupon(self):
"""
Test Update Coupon Info Scenarios. Handle all the HttpResponses return by update_coupon view
"""
coupon = Coupon(
code='AS452', description='asdsadsa', course_id=self.course.id.to_deprecated_string(),
percentage_discount=10, created_by=self.instructor
)
coupon.save()
response = self.client.post(self.url)
self.assertTrue('<td>AS452</td>' in response.content)
data = {
'coupon_id': coupon.id, 'code': 'update_code', 'discount': '12',
'course_id': coupon.course_id.to_deprecated_string()
}
# URL for update_coupon
update_coupon_url = reverse('update_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon with the coupon id ({coupon_id}) updated Successfully'.format(coupon_id=coupon.id)in response.content)
response = self.client.post(self.url)
self.assertTrue('<td>update_code</td>' in response.content)
self.assertTrue('<td>12</td>' in response.content)
data['coupon_id'] = 1000 # Coupon Not Exist with this ID
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=1000) in response.content)
data['coupon_id'] = coupon.id
data['discount'] = 123
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('Please Enter the Coupon Discount Value Less than or Equal to 100' in response.content)
data['discount'] = '25%'
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content)
data['coupon_id'] = '' # Coupon id is not provided
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon id not found' in response.content)
coupon1 = Coupon(
code='11111', description='coupon', course_id=self.course.id.to_deprecated_string(),
percentage_discount=20, created_by=self.instructor
)
coupon1.save()
data = {'coupon_id': coupon.id, 'code': '11111', 'discount': '12'}
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon with the coupon id ({coupon_id}) already exist'.format(coupon_id=coupon.id) in response.content)
开发者ID:AsylumCorp,项目名称:edx-platform,代码行数:49,代码来源:test_ecommerce.py
示例13: test_coupon_codes_features
def test_coupon_codes_features(self):
query_features = [
'course_id', 'percentage_discount', 'code_redeemed_count', 'description', 'expiration_date',
'total_discounted_amount', 'total_discounted_seats'
]
for i in range(10):
coupon = Coupon(
code='test_code{0}'.format(i),
description='test_description',
course_id=self.course.id, percentage_discount='{0}'.format(i),
created_by=self.instructor,
is_active=True
)
coupon.save()
#now create coupons with the expiration dates
for i in range(5):
coupon = Coupon(
code='coupon{0}'.format(i), description='test_description', course_id=self.course.id,
percentage_discount='{0}'.format(i), created_by=self.instructor, is_active=True,
expiration_date=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2)
)
coupon.save()
active_coupons = Coupon.objects.filter(
Q(course_id=self.course.id),
Q(is_active=True),
Q(expiration_date__gt=datetime.datetime.now(pytz.UTC)) |
Q(expiration_date__isnull=True)
)
active_coupons_list = coupon_codes_features(query_features, active_coupons, self.course.id)
self.assertEqual(len(active_coupons_list), len(active_coupons))
for active_coupon in active_coupons_list:
self.assertEqual(set(active_coupon.keys()), set(query_features))
self.assertIn(active_coupon['percentage_discount'], [coupon.percentage_discount for coupon in active_coupons])
self.assertIn(active_coupon['description'], [coupon.description for coupon in active_coupons])
if active_coupon['expiration_date']:
self.assertIn(active_coupon['expiration_date'], [coupon.display_expiry_date for coupon in active_coupons])
self.assertIn(
active_coupon['course_id'],
[text_type(coupon.course_id) for coupon in active_coupons]
)
开发者ID:luisvasq,项目名称:edx-platform,代码行数:41,代码来源:test_basic.py
示例14: test_get_coupon_info
def test_get_coupon_info(self):
"""
Test Edit Coupon Info Scenarios. Handle all the HttpResponses return by edit_coupon_info view
"""
coupon = Coupon(
code="AS452",
description="asdsadsa",
course_id=self.course.id.to_deprecated_string(),
percentage_discount=10,
created_by=self.instructor,
expiration_date=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2),
)
coupon.save()
# URL for edit_coupon_info
edit_url = reverse("get_coupon_info", kwargs={"course_id": self.course.id.to_deprecated_string()})
response = self.client.post(edit_url, {"id": coupon.id})
self.assertTrue(
"coupon with the coupon id ({coupon_id}) updated successfully".format(coupon_id=coupon.id)
in response.content
)
self.assertIn(coupon.display_expiry_date, response.content)
response = self.client.post(edit_url, {"id": 444444})
self.assertTrue(
"coupon with the coupon id ({coupon_id}) DoesNotExist".format(coupon_id=444444) in response.content
)
response = self.client.post(edit_url, {"id": ""})
self.assertTrue('coupon id not found"' in response.content)
coupon.is_active = False
coupon.save()
response = self.client.post(edit_url, {"id": coupon.id})
self.assertTrue(
"coupon with the coupon id ({coupon_id}) is already inactive".format(coupon_id=coupon.id)
in response.content
)
开发者ID:dmohrC,项目名称:edx-platform,代码行数:38,代码来源:test_ecommerce.py
示例15: test_get_coupon_info
def test_get_coupon_info(self):
"""
Test Edit Coupon Info Scenarios. Handle all the HttpResponses return by edit_coupon_info view
"""
coupon = Coupon(
code='AS452', description='asdsadsa', course_id=text_type(self.course.id),
percentage_discount=10, created_by=self.instructor,
expiration_date=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2)
)
coupon.save()
# URL for edit_coupon_info
edit_url = reverse('get_coupon_info', kwargs={'course_id': text_type(self.course.id)})
response = self.client.post(edit_url, {'id': coupon.id})
self.assertIn(
'coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id),
response.content
)
self.assertIn(coupon.display_expiry_date, response.content)
response = self.client.post(edit_url, {'id': 444444})
self.assertIn(
'coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=444444),
response.content
)
response = self.client.post(edit_url, {'id': ''})
self.assertIn('coupon id not found"', response.content)
coupon.is_active = False
coupon.save()
response = self.client.post(edit_url, {'id': coupon.id})
self.assertIn(
"coupon with the coupon id ({coupon_id}) is already inactive".format(coupon_id=coupon.id),
response.content
)
开发者ID:EDUlib,项目名称:edx-platform,代码行数:36,代码来源:test_ecommerce.py
示例16: test_sale_order_features_with_discount
def test_sale_order_features_with_discount(self):
"""
Test Order Sales Report CSV
"""
query_features = [
('id', 'Order Id'),
('company_name', 'Company Name'),
('company_contact_name', 'Company Contact Name'),
('company_contact_email', 'Company Contact Email'),
('total_amount', 'Total Amount'),
('total_codes', 'Total Codes'),
('total_used_codes', 'Total Used Codes'),
('logged_in_username', 'Login Username'),
('logged_in_email', 'Login User Email'),
('purchase_time', 'Date of Sale'),
('customer_reference_number', 'Customer Reference Number'),
('recipient_name', 'Recipient Name'),
('recipient_email', 'Recipient Email'),
('bill_to_street1', 'Street 1'),
('bill_to_street2', 'Street 2'),
('bill_to_city', 'City'),
('bill_to_state', 'State'),
('bill_to_postalcode', 'Postal Code'),
('bill_to_country', 'Country'),
('order_type', 'Order Type'),
('status', 'Order Item Status'),
('coupon_code', 'Coupon Code'),
('unit_cost', 'Unit Price'),
('list_price', 'List Price'),
('codes', 'Registration Codes'),
('course_id', 'Course Id')
]
# add the coupon code for the course
coupon = Coupon(
code='test_code',
description='test_description',
course_id=self.course.id,
percentage_discount='10',
created_by=self.instructor,
is_active=True
)
coupon.save()
order = Order.get_cart_for_user(self.instructor)
order.order_type = 'business'
order.save()
order.add_billing_details(
company_name='Test Company',
company_contact_name='Test',
company_contact_email='[email protected]',
recipient_name='R1', recipient_email='',
customer_reference_number='PO#23'
)
CourseRegCodeItem.add_to_order(order, self.course.id, 4)
# apply the coupon code to the item in the cart
resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': coupon.code})
self.assertEqual(resp.status_code, 200)
order.purchase()
# get the updated item
item = order.orderitem_set.all().select_subclasses()[0]
# get the redeemed coupon information
coupon_redemption = CouponRedemption.objects.select_related('coupon').filter(order=order)
db_columns = [x[0] for x in query_features]
sale_order_records_list = sale_order_record_features(self.course.id, db_columns)
for sale_order_record in sale_order_records_list:
self.assertEqual(sale_order_record['recipient_email'], order.recipient_email)
self.assertEqual(sale_order_record['recipient_name'], order.recipient_name)
self.assertEqual(sale_order_record['company_name'], order.company_name)
self.assertEqual(sale_order_record['company_contact_name'], order.company_contact_name)
self.assertEqual(sale_order_record['company_contact_email'], order.company_contact_email)
self.assertEqual(sale_order_record['customer_reference_number'], order.customer_reference_number)
self.assertEqual(sale_order_record['unit_cost'], item.unit_cost)
self.assertEqual(sale_order_record['list_price'], item.list_price)
self.assertEqual(sale_order_record['status'], item.status)
self.assertEqual(sale_order_record['coupon_code'], coupon_redemption[0].coupon.code)
开发者ID:luisvasq,项目名称:edx-platform,代码行数:77,代码来源:test_basic.py
示例17: test_update_coupon
def test_update_coupon(self):
"""
Test Update Coupon Info Scenarios. Handle all the HttpResponses return by update_coupon view
"""
coupon = Coupon(
code="AS452",
description="asdsadsa",
course_id=self.course.id.to_deprecated_string(),
percentage_discount=10,
created_by=self.instructor,
)
coupon.save()
response = self.client.post(self.url)
self.assertTrue("<td>AS452</td>" in response.content)
data = {
"coupon_id": coupon.id,
"code": "update_code",
"discount": "12",
"course_id": coupon.course_id.to_deprecated_string(),
}
# URL for update_coupon
update_coupon_url = reverse("update_coupon", kwargs={"course_id": self.course.id.to_deprecated_string()})
response = self.client.post(update_coupon_url, data=data)
self.assertTrue(
"coupon with the coupon id ({coupon_id}) updated Successfully".format(coupon_id=coupon.id)
in response.content
)
response = self.client.post(self.url)
self.assertTrue("<td>update_code</td>" in response.content)
self.assertTrue("<td>12</td>" in response.content)
data["coupon_id"] = 1000 # Coupon Not Exist with this ID
response = self.client.post(update_coupon_url, data=data)
self.assertTrue(
"coupon with the coupon id ({coupon_id}) DoesNotExist".format(coupon_id=1000) in response.content
)
data["coupon_id"] = coupon.id
data["discount"] = 123
response = self.client.post(update_coupon_url, data=data)
self.assertTrue("Please Enter the Coupon Discount Value Less than or Equal to 100" in response.content)
data["discount"] = "25%"
response = self.client.post(update_coupon_url, data=data)
self.assertTrue("Please Enter the Integer Value for Coupon Discount" in response.content)
data["coupon_id"] = "" # Coupon id is not provided
response = self.client.post(update_coupon_url, data=data)
self.assertTrue("coupon id not found" in response.content)
coupon1 = Coupon(
code="11111",
description="coupon",
course_id=self.course.id.to_deprecated_string(),
percentage_discount=20,
created_by=self.instructor,
)
coupon1.save()
data = {"coupon_id": coupon.id, "code": "11111", "discount": "12"} # pylint: disable=E1101
response = self.client.post(update_coupon_url, data=data)
self.assertTrue(
"coupon with the coupon id ({coupon_id}) already exist".format(coupon_id=coupon.id) in response.content
) # pylint: disable=E1101
course_registration = CourseRegistrationCode(
code="Vs23Ws4j",
course_id=self.course.id.to_deprecated_string(),
transaction_group_name="Test Group",
created_by=self.instructor,
)
course_registration.save()
data = {
"coupon_id": coupon.id,
"code": "Vs23Ws4j", # pylint: disable=E1101
"discount": "6",
"course_id": coupon.course_id.to_deprecated_string(),
} # pylint: disable=E1101
response = self.client.post(update_coupon_url, data=data)
self.assertTrue(
"The code ({code}) that you have tried to define is already in use as a registration code".format(
code=data["code"]
)
in response.content
)
开发者ID:AdityaKashyap,项目名称:edx-platform,代码行数:86,代码来源:test_ecommerce.py
注:本文中的shoppingcart.models.Coupon类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论