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', gather_request=False)
15 assert 'dummy_tables' == data['database']
18 'columns': ['c1', 'c2', 'c3'],
24 'foreign_keys': {'incoming': [], 'outgoing': []}
27 'columns': ['c1', 'c2', 'c3'],
33 'foreign_keys': {'incoming': [], 'outgoing': []}
36 def test_custom_sql(app_client):
37 response = app_client.get(
38 '/dummy_tables.json?' + urlencode({
39 'sql': 'select c1 from table1',
46 'sql': 'select c1 from table1',
49 assert 2 == len(data['rows'])
54 assert ['c1'] == data['columns']
55 assert 'dummy_tables' == data['database']
56 assert not data['truncated']
58 def test_invalid_custom_sql(app_client):
59 response = app_client.get(
60 '/dummy_tables.json?sql=.schema',
63 assert response.status == 400
64 assert response.json['ok'] is False
65 assert 'Statement must be a SELECT' == response.json['error']
67 def test_table_json(app_client):
68 response = app_client.get(
69 '/dummy_tables/table2.json?_shape=objects',
72 assert response.status == 200
74 assert data['query']['sql'] == 'select rowid, * from table2 order by rowid limit 51'
75 assert data['rows'] == [{
87 def test_table_not_exists_json(app_client):
90 'error': 'Table not found: blah',
94 '/dummy_tables/blah.json', gather_request=False
97 def test_table_shape_arrays(app_client):
98 response = app_client.get(
99 '/dummy_tables/table2.json?_shape=arrays',
105 ] == response.json['rows']
107 def test_table_shape_objects(app_client):
108 response = app_client.get(
109 '/dummy_tables/table2.json?_shape=objects',
122 }] == response.json['rows']
124 def test_table_shape_array(app_client):
125 response = app_client.get(
126 '/dummy_tables/table2.json?_shape=array',
141 def test_table_shape_invalid(app_client):
142 response = app_client.get(
143 '/dummy_tables/table2.json?_shape=invalid',
148 'error': 'Invalid _shape: invalid',