def test_model():
    (app, db, admin) = setup()
    (Model1, Model2) = create_models(db)
    view = CustomModelView(Model1)
    admin.add_view(view)
    eq_(view.model, Model1)
    eq_(view.name, 'Model1')
    eq_(view.endpoint, 'model1')
    eq_(view._primary_key, 'id')
    ok_(('test1' in view._sortable_columns))
    ok_(('test2' in view._sortable_columns))
    ok_(('test3' in view._sortable_columns))
    ok_(('test4' in view._sortable_columns))
    ok_((view._create_form_class is not None))
    ok_((view._edit_form_class is not None))
    eq_(view._search_supported, False)
    eq_(view._filters, None)
    eq_(view._create_form_class.test1.field_class, fields.StringField)
    eq_(view._create_form_class.test2.field_class, fields.StringField)
    eq_(view._create_form_class.test3.field_class, fields.TextAreaField)
    eq_(view._create_form_class.test4.field_class, fields.TextAreaField)
    client = app.test_client()
    rv = client.get('/admin/model1/')
    eq_(rv.status_code, 200)
    rv = client.get('/admin/model1/new/')
    eq_(rv.status_code, 200)
    rv = client.post('/admin/model1/new/', data=dict(test1='test1large', test2='test2'))
    eq_(rv.status_code, 302)
    model = Model1.objects.first()
    eq_(model.test1, 'test1large')
    eq_(model.test2, 'test2')
    eq_(model.test3, '')
    eq_(model.test4, '')
    rv = client.get('/admin/model1/')
    eq_(rv.status_code, 200)
    ok_(('test1large' in rv.data))
    url = ('/admin/model1/edit/?id=%s' % model.id)
    rv = client.get(url)
    eq_(rv.status_code, 200)
    rv = client.post(url, data=dict(test1='test1small', test2='test2large'))
    eq_(rv.status_code, 302)
    model = Model1.objects.first()
    eq_(model.test1, 'test1small')
    eq_(model.test2, 'test2large')
    eq_(model.test3, '')
    eq_(model.test4, '')
    url = ('/admin/model1/delete/?id=%s' % model.id)
    rv = client.post(url)
    eq_(rv.status_code, 302)
    eq_(Model1.objects.count(), 0)
def test_model():
    (app, db, admin) = setup()
    (Model1, Model2) = create_models(db)
    view = CustomModelView(Model1)
    admin.add_view(view)
    eq_(view.model, Model1)
    eq_(view.name, 'Model1')
    eq_(view.endpoint, 'model1')
    eq_(view._primary_key, 'id')
    ok_(('test1' in view._sortable_columns))
    ok_(('test2' in view._sortable_columns))
    ok_(('test3' in view._sortable_columns))
    ok_(('test4' in view._sortable_columns))
    ok_((view._create_form_class is not None))
    ok_((view._edit_form_class is not None))
    eq_(view._search_supported, False)
    eq_(view._filters, None)
    eq_(view._create_form_class.test1.field_class, fields.StringField)
    eq_(view._create_form_class.test2.field_class, fields.StringField)
    eq_(view._create_form_class.test3.field_class, fields.TextAreaField)
    eq_(view._create_form_class.test4.field_class, fields.TextAreaField)
    client = app.test_client()
    rv = client.get('/admin/model1/')
    eq_(rv.status_code, 200)
    rv = client.get('/admin/model1/new/')
    eq_(rv.status_code, 200)
    rv = client.post('/admin/model1/new/', data=dict(test1='test1large', test2='test2'))
    eq_(rv.status_code, 302)
    model = Model1.objects.first()
    eq_(model.test1, 'test1large')
    eq_(model.test2, 'test2')
    eq_(model.test3, )
    eq_(model.test4, )
    rv = client.get('/admin/model1/')
    eq_(rv.status_code, 200)
    ok_(('test1large' in rv.data))
    url = ('/admin/model1/edit/?id=%s' % model.id)
    rv = client.get(url)
    eq_(rv.status_code, 200)
    rv = client.post(url, data=dict(test1='test1small', test2='test2large'))
    eq_(rv.status_code, 302)
    model = Model1.objects.first()
    eq_(model.test1, 'test1small')
    eq_(model.test2, 'test2large')
    eq_(model.test3, )
    eq_(model.test4, )
    url = ('/admin/model1/delete/?id=%s' % model.id)
    rv = client.post(url)
    eq_(rv.status_code, 302)
    eq_(Model1.objects.count(), 0)