1 from .fixtures import app_client
4 pytest.fixture(scope='module')(app_client)
6 def test_homepage(app_client):
7 _, response = app_client.get('/.json')
8 assert response.status == 200
9 assert response.json.keys() == {'test_tables': 0}.keys()
10 d = response.json['test_tables']
11 assert d['name'] == 'test_tables'
12 assert d['tables_count'] == 4
14 def test_database_page(app_client):
15 response = app_client.get('/test_tables.json', gather_request=False)
17 assert 'test_tables' == data['database']
26 'foreign_keys': {'incoming': [], 'outgoing': []}
28 'name': '/group1/array2',
35 'foreign_keys': {'incoming': [], 'outgoing': []}
37 'name': '/group1/table1',
38 'columns': ['identity', 'idnumber', 'speed'],
44 'foreign_keys': {'incoming': [], 'outgoing': []}
46 'name': '/group2/table2',
47 'columns': ['identity', 'idnumber', 'speed'],
53 'foreign_keys': {'incoming': [], 'outgoing': []}
56 def test_custom_sql(app_client):
57 response = app_client.get(
58 '/test_tables.json?sql=select+identity+from+[/group1/table1]&_shape=objects',
63 'sql': 'select identity from [/group1/table1]',
66 assert 50 == len(data['rows'])
68 {'identity': 'This is particle: 0'},
69 {'identity': 'This is particle: 1'},
70 {'identity': 'This is particle: 2'}
72 assert ['identity'] == data['columns']
73 assert 'test_tables' == data['database']
74 assert data['truncated']
76 def test_invalid_custom_sql(app_client):
77 response = app_client.get(
78 '/test_tables.json?sql=.schema',
81 assert response.status == 400
82 assert response.json['ok'] is False
83 assert 'Statement must be a SELECT' == response.json['error']
85 def test_table_json(app_client):
86 response = app_client.get(
87 '/test_tables/%2Fgroup2%2Ftable2.json?_shape=objects',
90 assert response.status == 200
92 assert data['query']['sql'] == 'select rowid, * from [/group2/table2] order by rowid limit 51'
93 assert data['rows'][3:6] == [{
95 'identity': 'This is particle: 3',
100 'identity': 'This is particle: 4',
105 'identity': 'This is particle: 5',
110 def test_table_not_exists_json(app_client):
113 'error': 'Table not found: blah',
117 '/test_tables/blah.json', gather_request=False