Ejemplo n.º 1
0
    def test_modes_for_course_expired(self):
        expired_mode, _status = self.create_mode('verified',
                                                 'Verified Certificate', 10)
        expired_mode.expiration_datetime = datetime.now(
            pytz.UTC) + timedelta(days=-1)
        expired_mode.save()
        modes = CourseMode.modes_for_course(self.course_key)
        self.assertEqual([CourseMode.DEFAULT_MODE], modes)

        mode1 = Mode(u'honor', u'Honor Code Certificate', 0, '', 'usd', None,
                     None, None, None)
        self.create_mode(mode1.slug, mode1.name, mode1.min_price,
                         mode1.suggested_prices)
        modes = CourseMode.modes_for_course(self.course_key)
        self.assertEqual([mode1], modes)

        expiration_datetime = datetime.now(pytz.UTC) + timedelta(days=1)
        expired_mode.expiration_datetime = expiration_datetime
        expired_mode.save()
        expired_mode_value = Mode(u'verified', u'Verified Certificate', 10, '',
                                  'usd', expiration_datetime, None, None, None)
        modes = CourseMode.modes_for_course(self.course_key)
        self.assertEqual([expired_mode_value, mode1], modes)

        modes = CourseMode.modes_for_course(
            CourseLocator('TestOrg', 'TestCourse', 'TestRun'))
        self.assertEqual([CourseMode.DEFAULT_MODE], modes)
Ejemplo n.º 2
0
    def test_multiple_mode_creation(self):
        # Create an honor mode
        base_url = reverse('create_mode', args=[unicode(self.course.id)])
        self.client.get(base_url)

        # Excluding the currency parameter implicitly tests the mode creation endpoint's ability to
        # use default values when parameters are partially missing.
        parameters = {}
        parameters['mode_slug'] = u'verified'
        parameters['mode_display_name'] = u'Verified Certificate'
        parameters['min_price'] = 10
        parameters['suggested_prices'] = '10,20'

        # Create a verified mode
        url = reverse('create_mode', args=[unicode(self.course.id)])
        self.client.get(url, parameters)

        honor_mode = Mode(u'honor', u'Honor Code Certificate', 0, '', 'usd',
                          None, None, None, None)
        verified_mode = Mode(u'verified', u'Verified Certificate', 10, '10,20',
                             'usd', None, None, None, None)
        expected_modes = [honor_mode, verified_mode]
        course_modes = CourseMode.modes_for_course(self.course.id)

        self.assertEquals(course_modes, expected_modes)
Ejemplo n.º 3
0
    def test_modes_for_course_expired(self):
        expired_mode, _status = self.create_mode('verified',
                                                 'Verified Certificate')
        expired_mode.expiration_date = datetime.now(
            pytz.UTC) + timedelta(days=-1)
        expired_mode.save()
        modes = CourseMode.modes_for_course(self.course_id)
        self.assertEqual([CourseMode.DEFAULT_MODE], modes)

        mode1 = Mode(u'honor', u'Honor Code Certificate', 0, '', 'usd')
        self.create_mode(mode1.slug, mode1.name, mode1.min_price,
                         mode1.suggested_prices)
        modes = CourseMode.modes_for_course(self.course_id)
        self.assertEqual([mode1], modes)

        expired_mode.expiration_date = datetime.now(
            pytz.UTC) + timedelta(days=1)
        expired_mode.save()
        expired_mode_value = Mode(u'verified', u'Verified Certificate', 0, '',
                                  'usd')
        modes = CourseMode.modes_for_course(self.course_id)
        self.assertEqual([expired_mode_value, mode1], modes)

        modes = CourseMode.modes_for_course('second_test_course')
        self.assertEqual([CourseMode.DEFAULT_MODE], modes)
Ejemplo n.º 4
0
    def test_min_course_price_for_currency(self):
        """
        Get the min course price for a course according to currency
        """
        # no modes, should get 0
        self.assertEqual(
            0,
            CourseMode.min_course_price_for_currency(self.course_key, 'usd'))

        # create some modes
        mode1 = Mode(u'honor', u'Honor Code Certificate', 10, '', 'usd', None,
                     None, None, None)
        mode2 = Mode(u'verified', u'Verified Certificate', 20, '', 'usd', None,
                     None, None, None)
        mode3 = Mode(u'honor', u'Honor Code Certificate', 80, '', 'cny', None,
                     None, None, None)
        set_modes = [mode1, mode2, mode3]
        for mode in set_modes:
            self.create_mode(mode.slug, mode.name, mode.min_price,
                             mode.suggested_prices, mode.currency)

        self.assertEqual(
            10,
            CourseMode.min_course_price_for_currency(self.course_key, 'usd'))
        self.assertEqual(
            80,
            CourseMode.min_course_price_for_currency(self.course_key, 'cny'))
Ejemplo n.º 5
0
    def test_modes_for_course_multiple(self):
        """
        Finding the modes when there's multiple modes
        """
        mode1 = Mode(u'honor', u'Honor Code Certificate', 0, '', 'usd')
        mode2 = Mode(u'verified', u'Verified Certificate', 0, '', 'usd')
        set_modes = [mode1, mode2]
        for mode in set_modes:
            self.create_mode(mode.slug, mode.name, mode.min_price, mode.suggested_prices)

        modes = CourseMode.modes_for_course(self.course_id)
        self.assertEqual(modes, set_modes)
Ejemplo n.º 6
0
    def test_verified_mode_creation(self, mode_slug, mode_display_name, min_price, suggested_prices, currency):
        parameters = {}
        parameters['mode_slug'] = mode_slug
        parameters['mode_display_name'] = mode_display_name
        parameters['min_price'] = min_price
        parameters['suggested_prices'] = suggested_prices
        parameters['currency'] = currency

        url = reverse('create_mode', args=[unicode(self.course.id)])
        response = self.client.get(url, parameters)

        self.assertEquals(response.status_code, 200)

        expected_mode = [
            Mode(
                mode_slug,
                mode_display_name,
                min_price,
                suggested_prices,
                currency,
                None,
                None,
                None,
                None
            )
        ]
        course_mode = CourseMode.modes_for_course(self.course.id)

        self.assertEquals(course_mode, expected_mode)
Ejemplo n.º 7
0
    def test_nodes_for_course_single(self):
        """
        Find the modes for a course with only one mode
        """

        self.create_mode('verified', 'Verified Certificate')
        modes = CourseMode.modes_for_course(self.course_id)
        self.assertEqual([Mode(u'verified', u'Verified Certificate', 0, '', 'usd')], modes)
Ejemplo n.º 8
0
    def test_default_mode_creation(self):
        # Hit the mode creation endpoint with no querystring params, to create an honor mode
        url = reverse('create_mode', args=[unicode(self.course.id)])
        response = self.client.get(url)

        self.assertEquals(response.status_code, 200)

        expected_mode = [Mode(u'honor', u'Honor Code Certificate', 0, '', 'usd', None, None, None, None)]
        course_mode = CourseMode.modes_for_course(self.course.id)

        self.assertEquals(course_mode, expected_mode)
Ejemplo n.º 9
0
    def test_nodes_for_course_single(self):
        """
        Find the modes for a course with only one mode
        """

        self.create_mode('verified', 'Verified Certificate')
        modes = CourseMode.modes_for_course(self.course_key)
        mode = Mode(u'verified', u'Verified Certificate', 0, '', 'usd', None, None)
        self.assertEqual([mode], modes)

        modes_dict = CourseMode.modes_for_course_dict(self.course_key)
        self.assertEqual(modes_dict['verified'], mode)
        self.assertEqual(CourseMode.mode_for_course(self.course_key, 'verified'),
                         mode)