Skip to content

Commit

Permalink
Unit tests for _search= feature, refs #237
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed May 5, 2018
1 parent ca29071 commit 4d6a568
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ def extra_js_urls():
INSERT INTO units VALUES (2, 5000, 2500);
INSERT INTO units VALUES (3, 100000, 75000);
CREATE TABLE searchable (
pk integer primary key,
text1 text,
text2 text
);
INSERT INTO searchable VALUES (1, 'barry cat', 'john dog');
INSERT INTO searchable VALUES (2, 'terry cat', 'john weasel');
CREATE VIRTUAL TABLE "searchable_fts"
USING FTS3 (text1, text2, content="searchable");
INSERT INTO "searchable_fts" (rowid, text1, text2)
SELECT rowid, text1, text2 FROM searchable;
CREATE TABLE [select] (
[group] text,
[having] text,
Expand Down
66 changes: 65 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ def test_homepage(app_client):
assert response.json.keys() == {'test_tables': 0}.keys()
d = response.json['test_tables']
assert d['name'] == 'test_tables'
assert d['tables_count'] == 14
assert d['tables_count'] == 15


def test_database_page(app_client):
response = app_client.get('/test_tables.json', gather_request=False)
data = response.json
assert 'test_tables' == data['database']
from pprint import pprint
pprint(data['tables'])
assert [{
'columns': ['content'],
'name': '123_starts_with_digits',
Expand Down Expand Up @@ -154,6 +156,15 @@ def test_database_page(app_client):
'label_column': None,
'fts_table': None,
'primary_keys': ['id']
}, {
'columns': ['pk', 'text1', 'text2'],
'name': 'searchable',
'count': 2,
'foreign_keys': {'incoming': [], 'outgoing': []},
'fts_table': 'searchable_fts',
'hidden': False,
'label_column': None,
'primary_keys': ['pk'],
}, {
'columns': ['group', 'having', 'and'],
'name': 'select',
Expand Down Expand Up @@ -230,6 +241,45 @@ def test_database_page(app_client):
'label_column': None,
'fts_table': None,
'primary_keys': [],
}, {
'columns': ['text1', 'text2', 'content'],
'count': 2,
'foreign_keys': {'incoming': [], 'outgoing': []},
'fts_table': 'searchable_fts',
'hidden': True,
'label_column': None,
'name': 'searchable_fts',
'primary_keys': []
}, {
'columns': ['docid', 'c0text1', 'c1text2', 'c2content'],
'count': 2,
'foreign_keys': {'incoming': [], 'outgoing': []},
'fts_table': None,
'hidden': True,
'label_column': None,
'name': 'searchable_fts_content',
'primary_keys': ['docid']
}, {
'columns': [
'level', 'idx', 'start_block', 'leaves_end_block',
'end_block', 'root'
],
'count': 1,
'foreign_keys': {'incoming': [], 'outgoing': []},
'fts_table': None,
'hidden': True,
'label_column': None,
'name': 'searchable_fts_segdir',
'primary_keys': ['level', 'idx']
}, {
'columns': ['blockid', 'block'],
'count': 0,
'foreign_keys': {'incoming': [], 'outgoing': []},
'fts_table': None,
'hidden': True,
'label_column': None,
'name': 'searchable_fts_segments',
'primary_keys': ['blockid']
}] == data['tables']


Expand Down Expand Up @@ -630,6 +680,20 @@ def test_sortable_columns_metadata(app_client):
assert 'Cannot sort table by {}'.format(column) == response.json['error']


@pytest.mark.parametrize('path,expected_rows', [
('/test_tables/searchable.json?_search=cat', [
[1, 'barry cat', 'john dog'],
[2, 'terry cat', 'john weasel'],
]),
('/test_tables/searchable.json?_search=weasel', [
[2, 'terry cat', 'john weasel'],
]),
])
def test_searchable(app_client, path, expected_rows):
response = app_client.get(path, gather_request=False)
assert expected_rows == response.json['rows']


@pytest.mark.parametrize('path,expected_rows', [
('/test_tables/simple_primary_key.json?content=hello', [
['1', 'hello'],
Expand Down

0 comments on commit 4d6a568

Please sign in to comment.