def test_import_nonexistant_model(self): """importing a non existant model fails gracefully""" # add a nonsensical discount model into the mox settings.CCCHECKOUT_DISCOUNT_MODELS = ('total.garbage',) reload(c_settings) # bind data and cause the clean methods to run data = {'code': 'tester'} form = DiscountCodeForm(data) self.assertFalse(form.is_valid()) # cleanup del(settings.CCCHECKOUT_DISCOUNT_MODELS)
def _process_discount(request, *args, **kwargs): form = DiscountCodeForm() if request.method == 'POST': form = DiscountCodeForm(request.POST) if form.is_valid(): discount = form.save() if discount.is_valid(request): request.session['cccheckout'].discount = discount request.session['cccheckout'].save() request.session.save() kwargs.update({'discountform': form}) return fn(request, *args, **kwargs)
def test_discount_code_form(self): """ensure the discoint form works as expected""" # make a discount code d = DiscountCode() d.type = DiscountCode.PERCENTAGE d.discount = Decimal('50.00') d.title = 'test discount' d.code = 'test' d.save() # make the form and get the discount form = DiscountCodeForm({'code': 'test'}) form.is_valid() discount = form.save() self.assertEqual(discount.pk, d.pk)
def test_doesnotexist(self): """if a model.DoesNotExist is raised by the form, it is silent""" # bind data and cause the clean methods to run data = {'code': 'tester'} form = DiscountCodeForm(data) self.assertFalse(form.is_valid())