本文整理汇总了Python中ecommerce.courses.tests.factories.CourseFactory类的典型用法代码示例。如果您正苦于以下问题:Python CourseFactory类的具体用法?Python CourseFactory怎么用?Python CourseFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CourseFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VoucherRemoveMessagesViewTests
class VoucherRemoveMessagesViewTests(CouponMixin, CourseCatalogTestMixin, TestCase):
""" VoucherRemoveMessagesView view tests. """
def setUp(self):
super(VoucherRemoveMessagesViewTests, self).setUp()
self.user = self.create_user()
self.client.login(username=self.user.username, password=self.password)
self.course = CourseFactory()
self.course.create_or_update_seat('verified', True, 50, self.partner)
self.product = self.course.create_or_update_seat('verified', False, 0, self.partner)
self.voucher, __ = prepare_voucher(code=COUPON_CODE)
self.request = RequestFactory().request()
# Fallback storage is needed in tests with messages
setattr(self.request, 'session', 'session')
messages = FallbackStorage(self.request)
setattr(self.request, '_messages', messages)
self.request.user = self.user
basket = factories.BasketFactory(owner=self.user, site=self.site)
basket.add_product(self.product, 1)
self.request.basket = basket
self.voucher_remove_view = VoucherRemoveMessagesView()
def test_remove_voucher_pk_conversion(self):
""" Verify that voucher primary key is converted to integer """
self.voucher_remove_view.post(self.request, pk=self.voucher.id)
request_message = list(get_messages(self.request))[-1].message
self.assertEqual(
str(request_message),
"No voucher found with id '{0}'".format(self.voucher.id)
)
示例2: test_notify_purchaser
def test_notify_purchaser(self, mock_task):
""" Verify the notification is scheduled if the site has notifications enabled
and the refund is for a course seat.
"""
site_configuration = self.site.siteconfiguration
site_configuration.send_refund_notifications = True
user = UserFactory()
course = CourseFactory()
price = Decimal(100.00)
product = course.create_or_update_seat('verified', True, price, self.partner)
basket = create_basket(empty=True)
basket.site = self.site
basket.add_product(product)
order = create_order(basket=basket, user=user)
order_url = get_receipt_page_url(site_configuration, order.number)
refund = Refund.create_with_lines(order, order.lines.all())
with LogCapture(REFUND_MODEL_LOGGER_NAME) as l:
refund._notify_purchaser() # pylint: disable=protected-access
msg = 'Course refund notification scheduled for Refund [{}].'.format(refund.id)
l.check(
(REFUND_MODEL_LOGGER_NAME, 'INFO', msg)
)
amount = format_currency(order.currency, price)
mock_task.assert_called_once_with(
user.email, refund.id, amount, course.name, order.number, order_url, site_code=self.partner.short_code
)
示例3: setUp
def setUp(self):
super(CouponViewSetTest, self).setUp()
self.user = self.create_user(is_staff=True)
self.client.login(username=self.user.username, password=self.password)
course = CourseFactory(id='edx/Demo_Course/DemoX')
course.create_or_update_seat('verified', True, 50, self.partner)
self.catalog = Catalog.objects.create(partner=self.partner)
self.product_class, __ = ProductClass.objects.get_or_create(name='Coupon')
self.coupon_data = {
'title': 'Test Coupon',
'partner': self.partner,
'benefit_type': Benefit.PERCENTAGE,
'benefit_value': 100,
'catalog': self.catalog,
'end_date': '2020-1-1',
'code': '',
'quantity': 2,
'start_date': '2015-1-1',
'voucher_type': Voucher.ONCE_PER_CUSTOMER,
'categories': [self.category],
'note': None,
'max_uses': None,
}
示例4: setUp
def setUp(self):
super(CouponViewSetTest, self).setUp()
self.user = self.create_user(is_staff=True)
self.client.login(username=self.user.username, password=self.password)
course = CourseFactory(id='edx/Demo_Course/DemoX')
self.seat = course.create_or_update_seat('verified', True, 50, self.partner)
self.catalog = Catalog.objects.create(partner=self.partner)
self.coupon_data = {
'title': 'Tešt Čoupon',
'partner': self.partner,
'benefit_type': Benefit.PERCENTAGE,
'benefit_value': 100,
'catalog': self.catalog,
'end_datetime': str(now() + datetime.timedelta(days=10)),
'enterprise_customer': {'id': str(uuid4()).decode('utf-8')},
'code': '',
'quantity': 2,
'start_datetime': str(now() - datetime.timedelta(days=1)),
'voucher_type': Voucher.ONCE_PER_CUSTOMER,
'category': {'name': self.category.name},
'note': None,
'max_uses': None,
'catalog_query': None,
'course_seat_types': None,
'email_domains': None,
}
示例5: create_course_and_seat
def create_course_and_seat(
self, course_id=None, seat_type='verified', id_verification=False, price=10, partner=None
):
"""
Create a course and a seat from that course.
Arguments:
course_name (str): name of the course
seat_type (str): the seat type
id_verification (bool): if id verification is required
price (int): seat price
partner(Partner): the site partner
Returns:
The created course and seat.
"""
if not partner:
partner = PartnerFactory()
if not course_id:
course = CourseFactory()
else:
course = CourseFactory(id=course_id)
seat = course.create_or_update_seat(seat_type, id_verification, price, partner)
return course, seat
示例6: test_proper_code
def test_proper_code(self):
""" Verify that proper information is returned when a valid code is provided. """
course = CourseFactory()
seat = course.create_or_update_seat('verified', True, 50, self.partner)
sr = StockRecord.objects.get(product=seat)
catalog = Catalog.objects.create(name='Test catalog', partner=self.partner)
catalog.stock_records.add(sr)
range_ = RangeFactory(catalog=catalog)
self.prepare_voucher(range_=range_)
course_info = {
"media": {
"course_image": {
"uri": "/asset-v1:[email protected][email protected]_course_image.jpg"
}
},
"name": "edX Demonstration Course",
}
course_info_json = json.dumps(course_info)
course_url = get_lms_url('api/courses/v1/courses/{}/'.format(course.id))
httpretty.register_uri(httpretty.GET, course_url, body=course_info_json, content_type='application/json')
url = self.offer_url + '?code={}'.format('COUPONTEST')
response = self.client.get(url)
self.assertEqual(response.context['course']['name'], _('edX Demonstration Course'))
self.assertEqual(response.context['code'], _('COUPONTEST'))
示例7: setUp
def setUp(self):
super(CouponRedeemViewTests, self).setUp()
self.user = self.create_user()
self.client.login(username=self.user.username, password=self.password)
course = CourseFactory()
self.seat = course.create_or_update_seat('verified', True, 50, self.partner)
self.catalog = Catalog.objects.create(partner=self.partner)
self.catalog.stock_records.add(StockRecord.objects.get(product=self.seat))
示例8: test_restricted_course_mode
def test_restricted_course_mode(self, mode):
"""Test that an exception is raised when a black-listed course mode is used."""
course = CourseFactory(id='black/list/mode')
seat = course.create_or_update_seat(mode, False, 0, self.partner)
# Seats derived from a migrated "audit" mode do not have a certificate_type attribute.
if mode == 'audit':
seat = ProductFactory()
self.data.update({'stock_record_ids': [StockRecord.objects.get(product=seat).id]})
self.assert_post_response_status(self.data)
示例9: test_filter_product_class
def test_filter_product_class(self):
""" Verify the method supports filtering by product class or the parent product's class. """
course = CourseFactory()
seat = course.create_or_update_seat('verified', True, 1, self.partner)
parent = course.parent_seat_product
product_class_name = self.seat_product_class.name
queryset = Product.objects.all()
actual = list(self.filter.filter_product_class(queryset, product_class_name))
self.assertListEqual(actual, [seat, parent])
示例10: setUp
def setUp(self):
super(EnrollmentCodeFulfillmentModuleTests, self).setUp()
toggle_switch(ENROLLMENT_CODE_SWITCH, True)
course = CourseFactory()
course.create_or_update_seat('verified', True, 50, self.partner)
enrollment_code = Product.objects.get(product_class__name=ENROLLMENT_CODE_PRODUCT_CLASS_NAME)
user = UserFactory()
basket = BasketFactory()
basket.add_product(enrollment_code, self.QUANTITY)
self.order = factories.create_order(number=1, basket=basket, user=user)
示例11: prepare_course_information
def prepare_course_information(self):
""" Helper function to prepare an API endpoint that provides course information. """
course = CourseFactory(name='Test course')
seat = course.create_or_update_seat('verified', True, 50, self.partner)
stock_record = StockRecord.objects.get(product=seat)
catalog = Catalog.objects.create(name='Test catalog', partner=self.partner)
catalog.stock_records.add(stock_record)
_range = RangeFactory(catalog=catalog)
self.mock_course_api_response(course=course)
return _range
示例12: test_restricted_course_mode
def test_restricted_course_mode(self, mode):
"""Test that an exception is raised when a black-listed course mode is used."""
course = CourseFactory(id='black/list/mode')
seat = course.create_or_update_seat(mode, False, 0, self.partner)
# Seats derived from a migrated "audit" mode do not have a certificate_type attribute.
if mode == 'audit':
seat = ProductFactory()
self.data.update({'stock_record_ids': [StockRecord.objects.get(product=seat).id]})
response = self.client.post(COUPONS_LINK, data=self.data, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
示例13: setUp
def setUp(self):
super(BasketSingleItemViewTests, self).setUp()
self.user = self.create_user()
self.client.login(username=self.user.username, password=self.password)
course = CourseFactory()
course.create_or_update_seat('verified', True, 50, self.partner)
product = course.create_or_update_seat('verified', False, 0, self.partner)
self.stock_record = StockRecordFactory(product=product, partner=self.partner)
self.catalog = Catalog.objects.create(partner=self.partner)
self.catalog.stock_records.add(self.stock_record)
示例14: test_enrollment_code_seat_type
def test_enrollment_code_seat_type(self):
"""Verify the correct seat type attribute is retrieved."""
course = CourseFactory()
toggle_switch(ENROLLMENT_CODE_SWITCH, True)
course.create_or_update_seat('verified', False, 10, self.partner)
enrollment_code = Product.objects.get(product_class__name=ENROLLMENT_CODE_PRODUCT_CLASS_NAME)
self.create_basket_and_add_product(enrollment_code)
self.mock_course_api_response(course)
response = self.client.get(self.path)
self.assertEqual(response.status_code, 200)
line_data = response.context['formset_lines_data'][0][1]
self.assertEqual(line_data['seat_type'], _(enrollment_code.attr.seat_type.capitalize()))
示例15: test_get_transaction_parameters_with_quoted_product_title
def test_get_transaction_parameters_with_quoted_product_title(self):
""" Verify quotes are removed from item name """
course = CourseFactory(id='a/b/c/d', name='Course with "quotes"')
product = course.create_or_update_seat(self.CERTIFICATE_TYPE, False, 20, self.partner)
basket = factories.create_basket(empty=True)
basket.add_product(product)
basket.owner = factories.UserFactory()
basket.site = self.site
basket.save()
response = self.processor.get_transaction_parameters(basket)
self.assertEqual(response['item_0_name'], 'Seat in Course with quotes with test-certificate-type certificate')