1 from .fixtures import app_client
2 from urllib.parse import urlencode
4 def test_homepage(app_client):
5 response = app_client.get('/.json')
6 assert response.status == 200
7 assert response.json.keys() == {'dummy_tables': 0}.keys()
8 d = response.json['dummy_tables']
9 assert d['name'] == 'dummy_tables'
10 assert d['tables_count'] == 2
12 def test_database_page(app_client):
13 response = app_client.get('/dummy_tables.json')
15 assert 'dummy_tables' == data['database']
16 assert len(data['tables']) == 2
17 assert data['tables'][0]['count'] == 2
18 assert data['tables'][0]['columns'] == ['c1', 'c2', 'c3']
20 def test_custom_sql(app_client):
21 response = app_client.get(
22 '/dummy_tables.json?' + urlencode({
23 'sql': 'select c1 from table1',
29 'sql': 'select c1 from table1',
32 assert 2 == len(data['rows'])
37 assert ['c1'] == data['columns']
38 assert 'dummy_tables' == data['database']
39 assert not data['truncated']
41 def test_invalid_custom_sql(app_client):
42 response = app_client.get('/dummy_tables.json?sql=.schema')
43 assert response.status == 400
44 assert response.json['ok'] is False
45 assert 'Statement must be a SELECT' == response.json['error']
47 def test_table_json(app_client):
48 response = app_client.get('/dummy_tables/table2.json?_shape=objects')
49 assert response.status == 200
51 assert data['query']['sql'] == 'select c1, c2, c3 from table2 limit 51'
52 assert data['rows'] == [
64 def test_table_not_exists_json(app_client):
67 'title': 'Invalid SQL',
68 'error': 'no such table: blah',
70 } == app_client.get('/dummy_tables/blah.json').json
72 def test_table_shape_arrays(app_client):
73 response = app_client.get('/dummy_tables/table2.json?_shape=arrays')
77 ] == response.json['rows']
79 def test_table_shape_objects(app_client):
80 response = app_client.get('/dummy_tables/table2.json?_shape=objects')
92 ] == response.json['rows']
94 def test_table_shape_array(app_client):
95 response = app_client.get('/dummy_tables/table2.json?_shape=array')
109 def test_table_shape_invalid(app_client):
110 response = app_client.get('/dummy_tables/table2.json?_shape=invalid')
113 'error': 'Invalid _shape: invalid',