From ed974417ad54f0c0f65b2f1cf54dc12485abb570 Mon Sep 17 00:00:00 2001 From: Russ Garrett Date: Sat, 14 Apr 2018 15:06:52 +0100 Subject: [PATCH] Tests for unit filtering --- tests/fixtures.py | 17 ++++++++++++++++- tests/test_api.py | 23 ++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/fixtures.py b/tests/fixtures.py index b44b2e1d..37015bf1 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -79,6 +79,12 @@ METADATA = { 'no_primary_key': { 'sortable_columns': [], }, + 'units': { + 'units': { + 'distance': 'm', + 'frequency': 'Hz' + } + }, } }, } @@ -155,6 +161,16 @@ CREATE TABLE "complex_foreign_keys" ( FOREIGN KEY ("f3") REFERENCES [simple_primary_key](id) ); +CREATE TABLE units ( + pk integer primary key, + distance int, + frequency int +); + +INSERT INTO units VALUES (1, 1, 100); +INSERT INTO units VALUES (2, 5000, 2500); +INSERT INTO units VALUES (3, 100000, 75000); + CREATE TABLE [select] ( [group] text, [having] text, @@ -189,7 +205,6 @@ CREATE VIEW simple_view AS ).replace('None', 'null') for row in generate_sortable_rows(201) ]) - if __name__ == '__main__': filename = sys.argv[-1] if filename.endswith('.db'): diff --git a/tests/test_api.py b/tests/test_api.py index 33938667..608c69d2 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -14,7 +14,7 @@ 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'] == 10 + assert d['tables_count'] == 11 def test_database_page(app_client): @@ -134,6 +134,14 @@ def test_database_page(app_client): 'foreign_keys': {'incoming': [], 'outgoing': []}, 'label_column': None, 'primary_keys': ['pk'], + }, { + 'columns': ['pk', 'distance', 'frequency'], + 'name': 'units', + 'count': 3, + 'hidden': False, + 'foreign_keys': {'incoming': [], 'outgoing': []}, + 'label_column': None, + 'primary_keys': ['pk'], }] == data['tables'] @@ -534,3 +542,16 @@ def test_row_foreign_key_tables(app_client): 'other_column': 'f1', 'other_table': 'complex_foreign_keys' }] == response.json['foreign_key_tables'] + + +def test_unit_filters(app_client): + response = app_client.get('/test_tables/units.json?distance__lt=75km&frequency__gt=1kHz', + gather_request=False) + assert response.status == 200 + data = response.json + + assert data['units']['distance'] == 'm' + assert data['units']['frequency'] == 'Hz' + + assert len(data['rows']) == 1 + assert data['rows'][0][0] == 2