Exemplo n.º 1
0
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())
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
class User(Model):

    name = Model.Field(None)
    roles = Model.Field([])
Exemplo n.º 5
0
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)