def test_formfield(self): data = {'json': '{}'} f1 = TestForm(data) self.assertTrue(f1.is_valid()) self.assertEqual(f1.cleaned_data, data) f2 = TestForm({}) self.assertFalse(f2.is_valid()) f3 = OptionalForm({}) self.assertTrue(f3.is_valid()) self.assertEqual(f3.cleaned_data, {'json': None})
def test_formfield(self): data = {'json': '{"asdf":42}'} f1 = TestForm(data) self.assertTrue(f1.is_valid()) self.assertEqual(f1.cleaned_data, {'json': {'asdf': 42}}) f2 = TestForm({}) self.assertFalse(f2.is_valid()) f3 = OptionalForm({}) self.assertTrue(f3.is_valid()) self.assertEqual(f3.cleaned_data, {'json': None}) f4 = TestForm({'json': '{"time": datetime.datetime.now()}'}) self.assertFalse(f4.is_valid()) f5 = EvalForm({'json': '{"time": datetime.datetime.now()}'}) self.assertTrue(f5.is_valid()) f6 = ModelForm({'json': '{"time": datetime.datetime.now()}'}) self.assertFalse(f6.is_valid()) f7 = ModelForm({'json': '{"time": datetime.datetime.now()}'}) self.assertFalse(f7.is_valid())
def test_formfield(self): data = {'json': '{"asdf":42}'} f1 = TestForm(data) self.assertTrue(f1.is_valid()) self.assertEqual(f1.cleaned_data, {'json': {'asdf':42}}) f2 = TestForm({}) self.assertFalse(f2.is_valid()) f3 = OptionalForm({}) self.assertTrue(f3.is_valid()) self.assertEqual(f3.cleaned_data, {'json': None}) f4 = TestForm({'json':'{"time": datetime.datetime.now()}'}) self.assertFalse(f4.is_valid()) f5 = EvalForm({'json':'{"time": datetime.datetime.now()}'}) self.assertTrue(f5.is_valid()) f6 = ModelForm({'json':'{"time": datetime.datetime.now()}'}) self.assertFalse(f6.is_valid()) f7 = ModelForm({'json':'{"time": datetime.datetime.now()}'}) self.assertFalse(f7.is_valid())