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(
43 '/dummy_tables.json?sql=.schema',
46 assert response.status == 400
47 assert response.json['ok'] is False
48 assert 'Statement must be a SELECT' == response.json['error']
50 def test_table_json(app_client):
51 response = app_client.get(
52 '/dummy_tables/table2.json?_shape=objects',
55 assert response.status == 200
57 assert data['query']['sql'] == 'select rowid, * from table2 order by rowid limit 51'
58 assert data['rows'] == [{
70 def test_table_not_exists_json(app_client):
73 'error': 'Table not found: blah',
77 '/dummy_tables/blah.json', gather_request=False
80 def test_table_shape_arrays(app_client):
81 response = app_client.get(
82 '/dummy_tables/table2.json?_shape=arrays',
88 ] == response.json['rows']
90 def test_table_shape_objects(app_client):
91 response = app_client.get(
92 '/dummy_tables/table2.json?_shape=objects',
105 }] == response.json['rows']
107 def test_table_shape_array(app_client):
108 response = app_client.get(
109 '/dummy_tables/table2.json?_shape=array',
124 def test_table_shape_invalid(app_client):
125 response = app_client.get(
126 '/dummy_tables/table2.json?_shape=invalid',
131 'error': 'Invalid _shape: invalid',