mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
The test used to expect CSV to come back like this: hello world "" With the final blank value encoded in quotes. Judging by Travis failures, this behaviour changed between Python 3.6.3 and 3.6.5: https://travis-ci.org/simonw/datasette/jobs/392586661
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from .fixtures import app_client # noqa
|
|
|
|
EXPECTED_TABLE_CSV = '''id,content
|
|
1,hello
|
|
2,world
|
|
3,
|
|
'''.replace('\n', '\r\n')
|
|
|
|
EXPECTED_CUSTOM_CSV = '''content
|
|
hello
|
|
world
|
|
'''.replace('\n', '\r\n')
|
|
|
|
|
|
def test_table_csv(app_client):
|
|
response = app_client.get('/test_tables/simple_primary_key.csv')
|
|
assert response.status == 200
|
|
assert 'text/plain; charset=utf-8' == response.headers['Content-Type']
|
|
assert EXPECTED_TABLE_CSV == response.text
|
|
|
|
|
|
def test_custom_sql_csv(app_client):
|
|
response = app_client.get(
|
|
'/test_tables.csv?sql=select+content+from+simple_primary_key+limit+2'
|
|
)
|
|
assert response.status == 200
|
|
assert 'text/plain; charset=utf-8' == response.headers['Content-Type']
|
|
assert EXPECTED_CUSTOM_CSV == response.text
|
|
|
|
|
|
def test_table_csv_download(app_client):
|
|
response = app_client.get('/test_tables/simple_primary_key.csv?_dl=1')
|
|
assert response.status == 200
|
|
assert 'text/csv; charset=utf-8' == response.headers['Content-Type']
|
|
expected_disposition = 'attachment; filename="simple_primary_key.csv"'
|
|
assert expected_disposition == response.headers['Content-Disposition']
|