

def test_default_sort():
    (app, db, admin) = setup()
    (M1, _) = create_models(db)
    db.session.add_all([M1('c'), M1('b'), M1('a')])
    db.session.commit()
    eq_(M1.query.count(), 3)
    view = CustomModelView(M1, db.session, column_default_sort='test1')
    admin.add_view(view)
    (_, data) = view.get_list(0, None, None, None, None)
    eq_(len(data), 3)
    eq_(data[0].test1, 'a')
    eq_(data[1].test1, 'b')
    eq_(data[2].test1, 'c')
    view2 = CustomModelView(M1, db.session, column_default_sort='test1', column_labels={
        'test1': 'blah',
    }, endpoint='m1_2')
    admin.add_view(view2)
    (_, data) = view2.get_list(0, None, None, None, None)
    eq_(len(data), 3)
    eq_(data[0].test1, 'a')
    eq_(data[1].test1, 'b')
    eq_(data[2].test1, 'c')
    view3 = CustomModelView(M1, db.session, column_default_sort='test1', column_labels={
        'test1': 'blah',
    }, endpoint='m1_3', column_list=['test1'])
    admin.add_view(view3)
    (_, data) = view3.get_list(0, None, None, None, None)
    eq_(len(data), 3)
    eq_(data[0].test1, 'a')
    eq_(data[1].test1, 'b')
    eq_(data[2].test1, 'c')

dataset/ETHPy150Open flask-admin/flask-admin/flask_admin/tests/sqla/test_basic.py test_default_sort/original