本文整理汇总了Python中shoppingcart.models.CourseRegistrationCode类的典型用法代码示例。如果您正苦于以下问题:Python CourseRegistrationCode类的具体用法?Python CourseRegistrationCode怎么用?Python CourseRegistrationCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CourseRegistrationCode类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_reg_code
def add_reg_code(self, course_key):
"""
add dummy registration code into models
"""
course_reg_code = CourseRegistrationCode(code=self.reg_code, course_id=course_key,
transaction_group_name='A', created_by=self.user)
course_reg_code.save()
示例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_student_used_invoice_unpaid_enrollment_code_for_course_enrollment
def test_student_used_invoice_unpaid_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')
course_registration_code = CourseRegistrationCode(
code='abcde',
course_id=self.course.id.to_deprecated_string(),
created_by=self.instructor,
invoice=self.sale_invoice_1,
invoice_item=self.invoice_item,
mode_slug='honor'
)
course_registration_code.save()
redeem_url = reverse('register_code_redemption', args=['abcde'])
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', 'Invoice Outstanding')
示例4: test_add_coupon
def test_add_coupon(self):
"""
Test Add Coupon Scenarios. Handle all the HttpResponses return by add_coupon view
"""
# URL for add_coupon
add_coupon_url = reverse("add_coupon", kwargs={"course_id": self.course.id.to_deprecated_string()})
data = {
"code": "A2314",
"course_id": self.course.id.to_deprecated_string(),
"description": "ADSADASDSAD",
"created_by": self.instructor,
"discount": 5,
}
response = self.client.post(add_coupon_url, data)
self.assertTrue(
"coupon with the coupon code ({code}) added successfully".format(code=data["code"]) in response.content
)
data = {
"code": "A2314",
"course_id": self.course.id.to_deprecated_string(),
"description": "asdsasda",
"created_by": self.instructor,
"discount": 99,
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) already exist".format(code="A2314") in response.content)
response = self.client.post(self.url)
self.assertTrue("<td>ADSADASDSAD</td>" in response.content)
self.assertTrue("<td>A2314</td>" in response.content)
self.assertFalse("<td>111</td>" in response.content)
data = {
"code": "A2345314",
"course_id": self.course.id.to_deprecated_string(),
"description": "asdsasda",
"created_by": self.instructor,
"discount": 199,
}
response = self.client.post(add_coupon_url, 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(add_coupon_url, data=data)
self.assertTrue("Please Enter the Integer Value for Coupon Discount" in response.content)
course_registration = CourseRegistrationCode(
code="Vs23Ws4j", course_id=self.course.id.to_deprecated_string(), created_by=self.instructor
)
course_registration.save()
data["code"] = "Vs23Ws4j"
response = self.client.post(add_coupon_url, 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
)
示例5: test_add_coupon
def test_add_coupon(self):
"""
Test Add Coupon Scenarios. Handle all the HttpResponses return by add_coupon view
"""
# URL for add_coupon
add_coupon_url = reverse('add_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()})
expiration_date = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2)
data = {
'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'ADSADASDSAD', 'created_by': self.instructor, 'discount': 5,
'expiration_date': '{month}/{day}/{year}'.format(month=expiration_date.month, day=expiration_date.day, year=expiration_date.year)
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) added successfully".format(code=data['code']) in response.content)
#now add the coupon with the wrong value in the expiration_date
# server will through the ValueError Exception in the expiration_date field
data = {
'code': '213454', 'course_id': self.course.id.to_deprecated_string(),
'description': 'ADSADASDSAD', 'created_by': self.instructor, 'discount': 5,
'expiration_date': expiration_date.strftime('"%d/%m/%Y')
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("Please enter the date in this format i-e month/day/year" in response.content)
data = {
'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'asdsasda', 'created_by': self.instructor, 'discount': 99
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) already exist".format(code='A2314') in response.content)
response = self.client.post(self.url)
self.assertTrue('<td>ADSADASDSAD</td>' in response.content)
self.assertTrue('<td>A2314</td>' in response.content)
self.assertFalse('<td>111</td>' in response.content)
data = {
'code': 'A2345314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'asdsasda', 'created_by': self.instructor, 'discount': 199
}
response = self.client.post(add_coupon_url, 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(add_coupon_url, data=data)
self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content)
course_registration = CourseRegistrationCode(
code='Vs23Ws4j', course_id=unicode(self.course.id), created_by=self.instructor,
mode_slug='honor'
)
course_registration.save()
data['code'] = 'Vs23Ws4j'
response = self.client.post(add_coupon_url, 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)
示例6: test_add_coupon
def test_add_coupon(self):
"""
Test Add Coupon Scenarios. Handle all the HttpResponses return by add_coupon view
"""
# URL for add_coupon
add_coupon_url = reverse('add_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()})
data = {
'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'ADSADASDSAD', 'created_by': self.instructor, 'discount': 5
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) added successfully".format(code=data['code']) in response.content)
data = {
'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'asdsasda', 'created_by': self.instructor, 'discount': 99
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) already exist".format(code='A2314') in response.content)
response = self.client.post(self.url)
self.assertTrue('<td>ADSADASDSAD</td>' in response.content)
self.assertTrue('<td>A2314</td>' in response.content)
self.assertFalse('<td>111</td>' in response.content)
data = {
'code': 'A2345314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'asdsasda', 'created_by': self.instructor, 'discount': 199
}
response = self.client.post(add_coupon_url, 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(add_coupon_url, data=data)
self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content)
course_registration = CourseRegistrationCode(
code='Vs23Ws4j', course_id=self.course.id.to_deprecated_string(), created_by=self.instructor
)
course_registration.save()
data['code'] = 'Vs23Ws4j'
response = self.client.post(add_coupon_url, 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)
示例7: test_course_sale_features
def test_course_sale_features(self):
query_features = [
'company_name', 'company_contact_name', 'company_contact_email', 'total_codes', 'total_used_codes',
'total_amount', 'created', 'customer_reference_number', 'recipient_name', 'recipient_email',
'created_by', 'internal_reference', 'invoice_number', 'codes', 'course_id'
]
#create invoice
sale_invoice = Invoice.objects.create(
total_amount=1234.32, company_name='Test1', company_contact_name='TestName',
company_contact_email='[email protected]', recipient_name='Testw_1', recipient_email='[email protected]',
customer_reference_number='2Fwe23S', internal_reference="ABC", course_id=self.course.id
)
invoice_item = CourseRegistrationCodeInvoiceItem.objects.create(
invoice=sale_invoice,
qty=1,
unit_price=1234.32,
course_id=self.course.id
)
for i in range(5):
course_code = CourseRegistrationCode(
code="test_code{}".format(i), course_id=text_type(self.course.id),
created_by=self.instructor, invoice=sale_invoice, invoice_item=invoice_item, mode_slug='honor'
)
course_code.save()
course_sale_records_list = sale_record_features(self.course.id, query_features)
for sale_record in course_sale_records_list:
self.assertEqual(sale_record['total_amount'], sale_invoice.total_amount)
self.assertEqual(sale_record['recipient_email'], sale_invoice.recipient_email)
self.assertEqual(sale_record['recipient_name'], sale_invoice.recipient_name)
self.assertEqual(sale_record['company_name'], sale_invoice.company_name)
self.assertEqual(sale_record['company_contact_name'], sale_invoice.company_contact_name)
self.assertEqual(sale_record['company_contact_email'], sale_invoice.company_contact_email)
self.assertEqual(sale_record['internal_reference'], sale_invoice.internal_reference)
self.assertEqual(sale_record['customer_reference_number'], sale_invoice.customer_reference_number)
self.assertEqual(sale_record['invoice_number'], sale_invoice.id)
self.assertEqual(sale_record['created_by'], self.instructor)
self.assertEqual(sale_record['total_used_codes'], 0)
self.assertEqual(sale_record['total_codes'], 5)
示例8: test_add_coupon
def test_add_coupon(self):
"""
Test Add Coupon Scenarios. Handle all the HttpResponses return by add_coupon view
"""
# URL for add_coupon
add_coupon_url = reverse("add_coupon", kwargs={"course_id": self.course.id.to_deprecated_string()})
expiration_date = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2)
data = {
"code": "A2314",
"course_id": self.course.id.to_deprecated_string(),
"description": "ADSADASDSAD",
"created_by": self.instructor,
"discount": 5,
"expiration_date": "{month}/{day}/{year}".format(
month=expiration_date.month, day=expiration_date.day, year=expiration_date.year
),
}
response = self.client.post(add_coupon_url, data)
self.assertTrue(
"coupon with the coupon code ({code}) added successfully".format(code=data["code"]) in response.content
)
# now add the coupon with the wrong value in the expiration_date
# server will through the ValueError Exception in the expiration_date field
data = {
"code": "213454",
"course_id": self.course.id.to_deprecated_string(),
"description": "ADSADASDSAD",
"created_by": self.instructor,
"discount": 5,
"expiration_date": expiration_date.strftime('"%d/%m/%Y'),
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("Please enter the date in this format i-e month/day/year" in response.content)
data = {
"code": "A2314",
"course_id": self.course.id.to_deprecated_string(),
"description": "asdsasda",
"created_by": self.instructor,
"discount": 99,
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) already exist".format(code="A2314") in response.content)
response = self.client.post(self.url)
self.assertTrue("<td>ADSADASDSAD</td>" in response.content)
self.assertTrue("<td>A2314</td>" in response.content)
self.assertFalse("<td>111</td>" in response.content)
data = {
"code": "A2345314",
"course_id": self.course.id.to_deprecated_string(),
"description": "asdsasda",
"created_by": self.instructor,
"discount": 199,
}
response = self.client.post(add_coupon_url, 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(add_coupon_url, data=data)
self.assertTrue("Please Enter the Integer Value for Coupon Discount" in response.content)
course_registration = CourseRegistrationCode(
code="Vs23Ws4j", course_id=unicode(self.course.id), created_by=self.instructor, mode_slug="honor"
)
course_registration.save()
data["code"] = "Vs23Ws4j"
response = self.client.post(add_coupon_url, 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
)
示例9: 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
)
示例10: get_executive_report
def get_executive_report(course_id):
"""
Returns dict containing information about the course executive summary.
"""
single_purchase_total = PaidCourseRegistration.get_total_amount_of_purchased_item(course_id)
bulk_purchase_total = CourseRegCodeItem.get_total_amount_of_purchased_item(course_id)
paid_invoices_total = InvoiceTransaction.get_total_amount_of_paid_course_invoices(course_id)
gross_paid_revenue = single_purchase_total + bulk_purchase_total + paid_invoices_total
all_invoices_total = Invoice.get_invoice_total_amount_for_course(course_id)
gross_pending_revenue = all_invoices_total - float(paid_invoices_total)
gross_revenue = float(gross_paid_revenue) + float(gross_pending_revenue)
refunded_self_purchased_seats = PaidCourseRegistration.get_self_purchased_seat_count(
course_id, status='refunded'
)
refunded_bulk_purchased_seats = CourseRegCodeItem.get_bulk_purchased_seat_count(
course_id, status='refunded'
)
total_seats_refunded = refunded_self_purchased_seats + refunded_bulk_purchased_seats
self_purchased_refunds = PaidCourseRegistration.get_total_amount_of_purchased_item(
course_id,
status='refunded'
)
bulk_purchase_refunds = CourseRegCodeItem.get_total_amount_of_purchased_item(course_id, status='refunded')
total_amount_refunded = self_purchased_refunds + bulk_purchase_refunds
top_discounted_codes = CouponRedemption.get_top_discount_codes_used(course_id)
total_coupon_codes_purchases = CouponRedemption.get_total_coupon_code_purchases(course_id)
bulk_purchased_codes = CourseRegistrationCode.order_generated_registration_codes(course_id)
unused_registration_codes = 0
for registration_code in bulk_purchased_codes:
if not RegistrationCodeRedemption.is_registration_code_redeemed(registration_code.code):
unused_registration_codes += 1
self_purchased_seat_count = PaidCourseRegistration.get_self_purchased_seat_count(course_id)
bulk_purchased_seat_count = CourseRegCodeItem.get_bulk_purchased_seat_count(course_id)
total_invoiced_seats = CourseRegistrationCode.invoice_generated_registration_codes(course_id).count()
total_seats = self_purchased_seat_count + bulk_purchased_seat_count + total_invoiced_seats
self_purchases_percentage = 0.0
bulk_purchases_percentage = 0.0
invoice_purchases_percentage = 0.0
avg_price_paid = 0.0
if total_seats != 0:
self_purchases_percentage = (float(self_purchased_seat_count) / float(total_seats)) * 100
bulk_purchases_percentage = (float(bulk_purchased_seat_count) / float(total_seats)) * 100
invoice_purchases_percentage = (float(total_invoiced_seats) / float(total_seats)) * 100
avg_price_paid = gross_revenue / total_seats
course = get_course_by_id(course_id, depth=0)
currency = settings.PAID_COURSE_REGISTRATION_CURRENCY[1]
return {
'display_name': course.display_name,
'start_date': course.start.strftime("%Y-%m-%d") if course.start is not None else 'N/A',
'end_date': course.end.strftime("%Y-%m-%d") if course.end is not None else 'N/A',
'total_seats': total_seats,
'currency': currency,
'gross_revenue': float(gross_revenue),
'gross_paid_revenue': float(gross_paid_revenue),
'gross_pending_revenue': gross_pending_revenue,
'total_seats_refunded': total_seats_refunded,
'total_amount_refunded': float(total_amount_refunded),
'average_paid_price': float(avg_price_paid),
'discount_codes_data': top_discounted_codes,
'total_seats_using_discount_codes': total_coupon_codes_purchases,
'total_self_purchase_seats': self_purchased_seat_count,
'total_bulk_purchase_seats': bulk_purchased_seat_count,
'total_invoiced_seats': total_invoiced_seats,
'unused_bulk_purchase_code_count': unused_registration_codes,
'self_purchases_percentage': self_purchases_percentage,
'bulk_purchases_percentage': bulk_purchases_percentage,
'invoice_purchases_percentage': invoice_purchases_percentage,
}