コード例 #1
0
ファイル: test_booleanfield.py プロジェクト: guyi2020/blog
 def test_booleanfield_clean_2(self):
     f = BooleanField(required=False)
     self.assertIs(f.clean(''), False)
     self.assertIs(f.clean(None), False)
     self.assertIs(f.clean(True), True)
     self.assertIs(f.clean(False), False)
     self.assertIs(f.clean(1), True)
     self.assertIs(f.clean(0), False)
     self.assertIs(f.clean('1'), True)
     self.assertIs(f.clean('0'), False)
     self.assertIs(f.clean('Django rocks'), True)
     self.assertIs(f.clean('False'), False)
     self.assertIs(f.clean('false'), False)
     self.assertIs(f.clean('FaLsE'), False)
コード例 #2
0
 def test_booleanfield_clean_2(self):
     f = BooleanField(required=False)
     self.assertEqual(False, f.clean(''))
     self.assertEqual(False, f.clean(None))
     self.assertEqual(True, f.clean(True))
     self.assertEqual(False, f.clean(False))
     self.assertEqual(True, f.clean(1))
     self.assertEqual(False, f.clean(0))
     self.assertEqual(True, f.clean('1'))
     self.assertEqual(False, f.clean('0'))
     self.assertEqual(True, f.clean('Django rocks'))
     self.assertEqual(False, f.clean('False'))
     self.assertEqual(False, f.clean('false'))
     self.assertEqual(False, f.clean('FaLsE'))
コード例 #3
0
 def test_booleanfield_clean_1(self):
     f = BooleanField()
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean('')
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean(None)
     self.assertTrue(f.clean(True))
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean(False)
     self.assertTrue(f.clean(1))
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean(0)
     self.assertTrue(f.clean('Django rocks'))
     self.assertTrue(f.clean('True'))
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean('False')