def test_000_notnull(self): data = {'value': None} dest = {} field = fields.Field(null=False) with self.assertRaises(ValidationError): field.inflate('value', data, dest)
def test_000_default(self): data = {} dest = {} field = fields.Field(default=1) field.inflate('value', data, dest) self.assertEqual(dest['value'], 1)
def test_000_field_default(self): ''' With no default set, we can't deflate a field with no value. ''' data = {} field = fields.Field() with self.assertRaises(AttributeError): field.deflate('value', Mock(), data)
def test_000_field(self): data = {} field = fields.Field() field.deflate('value', Mock(value='str'), data) self.assertEqual('str', data['value']) dest = {} field.inflate('value', data, dest) self.assertEqual(dest['value'], data['value'])
def test_000_field_none(self): '''None is treated specially.''' data = {} field = fields.Field() field.deflate('value', Mock(value=None), data) self.assertTrue(data['value'] is None) dest = {} field.inflate('value', data, dest) self.assertEqual(data['value'], dest['value'])
class PollSerialiser(serialiser.Serialiser): question = fields.Field() published = fields.DateTimeField('pub_date') choices = fields.ManySerialiserField(serialiser=ChoiceSerialiser())
def test_000_nodefault(self): data = {} dest = {} field = fields.Field() field.inflate('value', data, dest) self.assertNotIn('value', dest)
def test_000_readonly(self): data = {'value': 1} dest = {} field = fields.Field(readonly=True) field.inflate('value', data, dest) self.assertNotIn('value', dest)
class SimpleSerialiser(Serialiser): a = fields.Field() b = fields.Field() c = fields.Field()