当前位置: 首页>>代码示例>>Python>>正文


Python CourseRegCodeItem.add_to_order方法代码示例

本文整理汇总了Python中shoppingcart.models.CourseRegCodeItem.add_to_order方法的典型用法代码示例。如果您正苦于以下问题:Python CourseRegCodeItem.add_to_order方法的具体用法?Python CourseRegCodeItem.add_to_order怎么用?Python CourseRegCodeItem.add_to_order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shoppingcart.models.CourseRegCodeItem的用法示例。


在下文中一共展示了CourseRegCodeItem.add_to_order方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_regcode_multi_redemptions

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
    def test_regcode_multi_redemptions(self):
        """
        Asserts the data model around RegistrationCodeRedemption and
        what happens when we do multiple redemptions by same user
        """
        self.cart.order_type = 'business'
        self.cart.save()
        CourseRegCodeItem.add_to_order(self.cart, self.course_key, 2)
        self.cart.purchase()

        reg_codes = CourseRegistrationCode.objects.filter(order=self.cart)

        self.assertEqual(len(reg_codes), 2)

        enrollment = CourseEnrollment.enroll(self.user, self.course_key)

        ids = []
        for reg_code in reg_codes:
            redemption = RegistrationCodeRedemption(
                registration_code=reg_code,
                redeemed_by=self.user,
                course_enrollment=enrollment
            )
            redemption.save()
            ids.append(redemption.id)  # pylint: disable=no-member

        test_redemption = RegistrationCodeRedemption.registration_code_used_for_enrollment(enrollment)

        self.assertIn(test_redemption.id, ids)  # pylint: disable=no-member
开发者ID:inares,项目名称:edx-platform,代码行数:31,代码来源:test_models.py

示例2: test_lookup_valid_redeemed_registration_code

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
    def test_lookup_valid_redeemed_registration_code(self):
        """
        test to lookup for the valid and redeemed registration code
        and then mark that registration code as un_redeemed
        which will unenroll the user and delete the redemption
        entry from the database.
        """
        student = UserFactory()
        self.client.login(username=student.username, password='test')
        cart = Order.get_cart_for_user(student)
        cart.order_type = 'business'
        cart.save()
        CourseRegCodeItem.add_to_order(cart, self.course.id, 2)
        cart.purchase()

        reg_code = CourseRegistrationCode.objects.filter(order=cart)[0]

        enrollment = CourseEnrollment.enroll(student, self.course.id)

        RegistrationCodeRedemption.objects.create(
            registration_code=reg_code,
            redeemed_by=student,
            course_enrollment=enrollment
        )
        self.client.login(username=self.instructor.username, password='test')
        data = {
            'registration_code': reg_code.code
        }
        response = self.client.get(self.lookup_code_url, data)
        self.assertEqual(response.status_code, 200)
        json_dict = json.loads(response.content)
        self.assertTrue(json_dict['is_registration_code_valid'])
        self.assertTrue(json_dict['is_registration_code_redeemed'])

        # now mark the registration code as unredeemed
        # this will unenroll the user and removed the redemption entry from
        # the database.

        data = {
            'registration_code': reg_code.code,
            'action_type': 'unredeem_registration_code'
        }
        response = self.client.post(self.registration_code_detail_url, data)
        self.assertEqual(response.status_code, 200)

        json_dict = json.loads(response.content)
        message = _('This enrollment code has been marked as unused.')
        self.assertEqual(message, json_dict['message'])

        redemption = RegistrationCodeRedemption.get_registration_code_redemption(reg_code.code, self.course.id)
        self.assertIsNone(redemption)

        # now the student course enrollment should be false.
        enrollment = CourseEnrollment.get_enrollment(student, self.course.id)
        self.assertEqual(enrollment.is_active, False)
开发者ID:edx-solutions,项目名称:edx-platform,代码行数:57,代码来源:test_registration_codes.py

示例3: test_sale_order_features

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
    def test_sale_order_features(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'),
            ('codes', 'Registration Codes'),
            ('course_id', 'Course Id')
        ]

        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)
        order.purchase()

        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['total_used_codes'], order.registrationcoderedemption_set.all().count())
            self.assertEqual(sale_order_record['total_codes'], len(CourseRegistrationCode.objects.filter(order=order)))
开发者ID:CDOT-EDX,项目名称:edx-platform,代码行数:52,代码来源:test_basic.py

示例4: test_cart_type_business

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
 def test_cart_type_business(self):
     self.cart.order_type = 'business'
     self.cart.save()
     item = CourseRegCodeItem.add_to_order(self.cart, self.course_key, 2)
     self.cart.purchase()
     self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_key))
     # check that the registration codes are generated against the order
     self.assertEqual(len(CourseRegistrationCode.objects.filter(order=self.cart)), item.qty)
开发者ID:alexmerser,项目名称:lms,代码行数:10,代码来源:test_models.py

示例5: test_regcode_redemptions

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
    def test_regcode_redemptions(self):
        """
        Asserts the data model around RegistrationCodeRedemption
        """
        self.cart.order_type = 'business'
        self.cart.save()
        CourseRegCodeItem.add_to_order(self.cart, self.course_key, 2)
        self.cart.purchase()

        reg_code = CourseRegistrationCode.objects.filter(order=self.cart)[0]

        enrollment = CourseEnrollment.enroll(self.user, self.course_key)

        redemption = RegistrationCodeRedemption(
            registration_code=reg_code,
            redeemed_by=self.user,
            course_enrollment=enrollment
        )
        redemption.save()

        test_redemption = RegistrationCodeRedemption.registration_code_used_for_enrollment(enrollment)

        self.assertEqual(test_redemption.id, redemption.id)  # pylint: disable=no-member
开发者ID:inares,项目名称:edx-platform,代码行数:25,代码来源:test_models.py

示例6: test_purchased_callback_exception

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
    def test_purchased_callback_exception(self):
        reg1 = PaidCourseRegistration.add_to_order(self.cart, self.course_key)
        reg1.course_id = CourseLocator(org="changed", course="forsome", run="reason")
        reg1.save()
        with self.assertRaises(PurchasedCallbackException):
            reg1.purchased_callback()
        self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_key))

        reg1.course_id = CourseLocator(org="abc", course="efg", run="hij")
        reg1.save()
        with self.assertRaises(PurchasedCallbackException):
            reg1.purchased_callback()
        self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_key))

        course_reg_code_item = CourseRegCodeItem.add_to_order(self.cart, self.course_key, 2)
        course_reg_code_item.course_id = CourseLocator(org="changed1", course="forsome1", run="reason1")
        course_reg_code_item.save()
        with self.assertRaises(PurchasedCallbackException):
            course_reg_code_item.purchased_callback()
开发者ID:alexmerser,项目名称:lms,代码行数:21,代码来源:test_models.py

示例7: test_add_with_default_mode

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
    def test_add_with_default_mode(self):
        """
        Tests add_to_cart where the mode specified in the argument is NOT in the database
        and NOT the default "honor".  In this case it just adds the user in the CourseMode.DEFAULT_MODE, 0 price
        """
        reg1 = PaidCourseRegistration.add_to_order(self.cart, self.course_key, mode_slug="DNE")

        self.assertEqual(reg1.unit_cost, 0)
        self.assertEqual(reg1.line_cost, 0)
        self.assertEqual(reg1.mode, "honor")
        self.assertEqual(reg1.user, self.user)
        self.assertEqual(reg1.status, "cart")
        self.assertEqual(self.cart.total_cost, 0)
        self.assertTrue(PaidCourseRegistration.contained_in_order(self.cart, self.course_key))

        course_reg_code_item = CourseRegCodeItem.add_to_order(self.cart, self.course_key, 2, mode_slug="DNE")

        self.assertEqual(course_reg_code_item.unit_cost, 0)
        self.assertEqual(course_reg_code_item.line_cost, 0)
        self.assertEqual(course_reg_code_item.mode, "honor")
        self.assertEqual(course_reg_code_item.user, self.user)
        self.assertEqual(course_reg_code_item.status, "cart")
        self.assertEqual(self.cart.total_cost, 0)
        self.assertTrue(CourseRegCodeItem.contained_in_order(self.cart, self.course_key))
开发者ID:alexmerser,项目名称:lms,代码行数:26,代码来源:test_models.py

示例8: test_sale_order_features_without_discount

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
    def test_sale_order_features_without_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'),
            ('quantity', 'Quantity'),
            ('total_discount', 'Total Discount'),
            ('total_amount', 'Total Amount Paid'),
        ]
        # add the coupon code for the course
        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)
        order.purchase()

        # get the updated item
        item = order.orderitem_set.all().select_subclasses()[0]

        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)
            # Make sure list price is not None and matches the unit price since no discount was applied.
            self.assertIsNotNone(sale_order_record['list_price'])
            self.assertEqual(sale_order_record['list_price'], item.unit_cost)
            self.assertEqual(sale_order_record['status'], item.status)
            self.assertEqual(sale_order_record['coupon_code'], 'N/A')
            self.assertEqual(sale_order_record['total_amount'], item.unit_cost * item.qty)
            self.assertEqual(sale_order_record['total_discount'], 0)
            self.assertEqual(sale_order_record['quantity'], item.qty)
开发者ID:luisvasq,项目名称:edx-platform,代码行数:73,代码来源:test_basic.py

示例9: test_sale_order_features_with_discount

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
    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,代码行数:79,代码来源:test_basic.py

示例10: test_course_reg_item_already_enrolled_in_course

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
 def test_course_reg_item_already_enrolled_in_course(self):
     CourseEnrollment.enroll(self.user, self.course_key)
     with self.assertRaises(AlreadyEnrolledInCourseException):
         CourseRegCodeItem.add_to_order(self.cart, self.course_key, 2)
开发者ID:alexmerser,项目名称:lms,代码行数:6,代码来源:test_models.py

示例11: test_course_reg_item_already_in_cart

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
 def test_course_reg_item_already_in_cart(self):
     CourseRegCodeItem.add_to_order(self.cart, self.course_key, 2)
     with self.assertRaises(ItemAlreadyInCartException):
         CourseRegCodeItem.add_to_order(self.cart, self.course_key, 2)
开发者ID:alexmerser,项目名称:lms,代码行数:6,代码来源:test_models.py

示例12: test_add_course_reg_item_with_no_course_item

# 需要导入模块: from shoppingcart.models import CourseRegCodeItem [as 别名]
# 或者: from shoppingcart.models.CourseRegCodeItem import add_to_order [as 别名]
 def test_add_course_reg_item_with_no_course_item(self):
     fake_course_id = CourseLocator(org="edx", course="fake", run="course")
     with self.assertRaises(CourseDoesNotExistException):
         CourseRegCodeItem.add_to_order(self.cart, fake_course_id, 2)
开发者ID:alexmerser,项目名称:lms,代码行数:6,代码来源:test_models.py


注:本文中的shoppingcart.models.CourseRegCodeItem.add_to_order方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。