Skip to content

Commit

Permalink
Test tsv model export using tablib
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmayo committed Jul 21, 2024
1 parent bcab74c commit aacc43a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions flask_admin/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,31 @@ def export_formatter(v, c, m, p):
assert rv.status_code == 500


def test_export_tablib(app, admin):
client = app.test_client()

# basic test of tsv export with a few records using tablib
view_data = {
1: Model(1, "col1_1", "col2_1"),
2: Model(2, "col1_2", "col2_2"),
3: Model(3, "col1_3", "col2_3"),
}

view = MockModelView(Model, view_data, can_export=True,
column_list=['col1', 'col2'],
export_types=['tsv'])
admin.add_view(view)

rv = client.get('/admin/model/export/tsv/')
data = rv.data.decode('utf-8')
assert rv.mimetype == 'text/tab-separated-values'
assert rv.status_code == 200
assert "Col1\tCol2\r\n" + \
"col1_1\tcol2_1\r\n" + \
"col1_2\tcol2_2\r\n" + \
"col1_3\tcol2_3\r\n" == data


def test_list_row_actions(app, admin):
client = app.test_client()

Expand Down
1 change: 1 addition & 0 deletions requirements/tests.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ arrow<0.14.0
colour
email-validator
wtforms
tablib

0 comments on commit aacc43a

Please sign in to comment.