'Ensure that default field values are used after non-default
values are explicitly deleted.'

def test_default_values_when_deleting_value(self):

    class Person(Document, ):
        name = StringField()
        age = IntField(default=30, required=False)
        userid = StringField(default=(lambda : 'test'), required=True)
        created = DateTimeField(default=datetime.datetime.utcnow)
    person = Person(name='Ross', age=50, userid='different', created=datetime.datetime(2014, 6, 12))
    del person.name
    del person.age
    del person.userid
    del person.created
    data_to_be_saved = sorted(person.to_mongo().keys())
    self.assertEqual(data_to_be_saved, ['age', 'created', 'userid'])
    self.assertTrue((person.validate() is None))
    self.assertEqual(person.name, None)
    self.assertEqual(person.age, 30)
    self.assertEqual(person.userid, 'test')
    self.assertTrue(isinstance(person.created, datetime.datetime))
    self.assertNotEqual(person.created, datetime.datetime(2014, 6, 12))
    self.assertEqual(person._data['name'], person.name)
    self.assertEqual(person._data['age'], person.age)
    self.assertEqual(person._data['userid'], person.userid)
    self.assertEqual(person._data['created'], person.created)
    data_to_be_saved = sorted(person.to_mongo().keys())
    self.assertEqual(data_to_be_saved, ['age', 'created', 'userid'])
