Пример #1
0
 def test_clean_mode(self, raw_mode, raw_price, cleaned_mode):
     """
     Verify that mode is cleaned properly and that NOOP_MODES are set to None.
     """
     entitlement_form = CourseEntitlementForm({'mode': raw_mode, 'price': raw_price})
     self.assertTrue(entitlement_form.is_valid())
     self.assertEqual(entitlement_form.cleaned_data['mode'], cleaned_mode)
Пример #2
0
 def test_invalid_price(self, mode, price, error_message):
     """
     Verify that form raises an error if the price is None or in -ive format
     """
     form_data = {'mode': mode, 'price': price}
     entitlement_form = CourseEntitlementForm(data=form_data)
     self.assertFalse(entitlement_form.is_valid())
     self.assertEqual(entitlement_form.errors, {'price': [error_message]})
Пример #3
0
 def test_valid_data(self, mode, price):
     """
     Verify that is_valid returns True for valid mode/price combos
     """
     entitlement_form = CourseEntitlementForm({
         'mode': mode,
         'price': price
     })
     self.assertTrue(entitlement_form.is_valid())
Пример #4
0
 def test_include_blank_mode(self):
     """
     Verify that when the include_blank_mode option is passed to the constructor, the mode field includes
     a blank option.
     """
     entitlement_form = CourseEntitlementForm(include_blank_mode=True)
     self.assertEqual([('', '')] + CourseEntitlementForm.MODE_CHOICES, entitlement_form.fields['mode'].choices)
Пример #5
0
    def test_invalid_price(self, mode, price):
        """
        Verify that clean raises an error if the price is invalid for the course type
        """
        entitlement_form = CourseEntitlementForm()
        entitlement_form.cleaned_data = {}
        if mode is not None:
            entitlement_form.cleaned_data['mode'] = mode
        if price is not None:
            entitlement_form.cleaned_data['price'] = price

        with self.assertRaises(ValidationError):
            entitlement_form.clean()
Пример #6
0
    def test_valid_price(self, mode, price):
        """
        Verify that clean works fine for valid price/type combos
        """
        entitlement_form = CourseEntitlementForm()
        entitlement_form.cleaned_data = {}
        if mode is not None:
            entitlement_form.cleaned_data['mode'] = mode
        if price is not None:
            entitlement_form.cleaned_data['price'] = price

        self.assertEqual(entitlement_form.clean(), entitlement_form.cleaned_data)