def test_model_as_dict(): """ Model.as_dict() should only include field attributes and reflect their current value""" m = Model(a=11) m.id = 12 m.b = 13 eq_({'id': 12, 'cls': 'Model'}, m.as_dict())
def test_model_del_field(): """ Deleting a model object's field attribute should behave like deleting a regular attribute without affecting the class or sister objects """ m = Model() del m.cls assert_raises(AttributeError, getattr, m, 'cls') ok_('cls' not in m.as_dict()) ok_(Model.cls) eq_('Model', Model().cls)
def test_model_field_defaults(): "Fix behaviour of default fields and their default values" eq_({'id': None, 'cls': 'Model'}, Model().as_dict()) class Test(Model): pass eq_('Test', Test().cls)
class User(Model): name = Model.Field(None) roles = Model.Field([])
def test_model_constructor(): "Model(**kwargs) should initialize object attributes from kwargs" m = Model(id=12, not_a_field=13) eq_(12, m.id) eq_(13, m.not_a_field)