本文整理汇总了Python中shoppingcart.models.CourseRegistrationCode.save方法的典型用法代码示例。如果您正苦于以下问题:Python CourseRegistrationCode.save方法的具体用法?Python CourseRegistrationCode.save怎么用?Python CourseRegistrationCode.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shoppingcart.models.CourseRegistrationCode
的用法示例。
在下文中一共展示了CourseRegistrationCode.save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_course_registration_features
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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]
)
示例2: add_reg_code
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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()
示例3: test_student_used_invoice_unpaid_enrollment_code_for_course_enrollment
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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
# 需要导入模块: from shoppingcart.models import CourseRegistrationCode [as 别名]
# 或者: from shoppingcart.models.CourseRegistrationCode import save [as 别名]
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
)