Failing tests for label stuff

This commit is contained in:
Simon Willison 2018-06-16 10:05:30 -07:00
commit 9920a8dc72
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
2 changed files with 39 additions and 0 deletions

View file

@ -11,6 +11,24 @@ hello
world
'''.replace('\n', '\r\n')
EXPECTED_TABLE_WITH_LABELS_CSV = '''
pk,planet_int,state,city_id,city_id_label,neighborhood
1,1,CA,1,San Francisco,Mission
2,1,CA,1,San Francisco,Dogpatch
3,1,CA,1,San Francisco,SOMA
4,1,CA,1,San Francisco,Tenderloin
5,1,CA,1,San Francisco,Bernal Heights
6,1,CA,1,San Francisco,Hayes Valley
7,1,CA,2,Los Angeles,Hollywood
8,1,CA,2,Los Angeles,Downtown
9,1,CA,2,Los Angeles,Los Feliz
10,1,CA,2,Los Angeles,Koreatown
11,1,MI,3,Detroit,Downtown
12,1,MI,3,Detroit,Greektown
13,1,MI,3,Detroit,Corktown
14,1,MI,3,Detroit,Mexicantown
15,2,MC,4,Memnonia,Arcadia Planitia
'''.strip().replace('\n', '\r\n')
def test_table_csv(app_client):
response = app_client.get('/test_tables/simple_primary_key.csv')
@ -19,6 +37,13 @@ def test_table_csv(app_client):
assert EXPECTED_TABLE_CSV == response.text
def test_table_csv_with_labels(app_client):
response = app_client.get('/test_tables/facetable.csv?_labels=1')
assert response.status == 200
assert 'text/plain; charset=utf-8' == response.headers['Content-Type']
assert EXPECTED_TABLE_WITH_LABELS_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'

View file

@ -388,6 +388,20 @@ def test_table_html_foreign_key_links(app_client):
assert expected == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
def test_table_html_disable_foreign_key_links_with_labels(app_client):
response = app_client.get('/test_tables/foreign_key_references?_labels=off')
assert response.status == 200
table = Soup(response.body, 'html.parser').find('table')
expected = [
[
'<td no class="col-pk"><a href="/test_tables/foreign_key_references/1">1</a></td>',
'<td class="col-foreign_key_with_label"><a href="/test_tables/simple_primary_key/1">hello</a>\xa0<em>1</em></td>',
'<td class="col-foreign_key_with_no_label"><a href="/test_tables/primary_key_multiple_columns/1">1</a></td>'
]
]
assert expected == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
def test_table_html_foreign_key_custom_label_column(app_client):
response = app_client.get('/test_tables/custom_foreign_key_label')
assert response.status == 200