def test_integer(self): t = Integer() self.assertIs(t.to_python(None), None) self.assertRaises(ValueError, lambda: t.to_python('test')) self.assertEqual(t.to_python(123), 123) self.assertEqual(t.to_python('123'), 123) self.assertEqual(t.from_python('test'), 'test') self.assertRaises(ValidationError, lambda: t.from_python('test', validate=True)) self.assertRaises(ValidationError, lambda: t.from_python(1 << 31, validate=True))
def to_int(value, type=None): type = type or Integer() v = type.to_python_single(value) if Integer.MIN_VALUE < v < Integer.MAX_VALUE: return v raise ValueError('Integer value must be between %s and %s' % (Integer.MIN_VALUE, Integer.MAX_VALUE))
def test_from_python__is_none(self): # self.assertIsNone(String().from_python(None)) self.assertIsNone(Byte().from_python(None)) self.assertIsNone(Short().from_python(None)) self.assertIsNone(Integer().from_python(None)) self.assertIsNone(Long().from_python(None)) self.assertIsNone(Float().from_python(None)) self.assertIsNone(Double().from_python(None)) # self.assertIsNone(Date().from_python(None)) # self.assertIsNone(Boolean().from_python(None)) # self.assertIsNone(Binary().from_python(None)) self.assertIsNone(Ip().from_python(None)) self.assertIsNone(Object(DynamicDocument).from_python(None)) # self.assertIsNone(Nested().to_python(None)) # self.assertIsNone(List(String).from_python(None)) self.assertIsNone(GeoPoint().from_python(None)) self.assertIsNone(Completion().from_python(None))