mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Tests for unit filtering
This commit is contained in:
parent
3c985ec271
commit
ed974417ad
2 changed files with 38 additions and 2 deletions
|
|
@ -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'):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue