mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Added addressable page per row
Refs #1 - only exists for tables with introspectable primary keys. Still need to link to this page. Also added first unit tests - refs #9
This commit is contained in:
parent
606ff9e35e
commit
6a9fdcc071
2 changed files with 101 additions and 1 deletions
46
test_helpers.py
Normal file
46
test_helpers.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import app
|
||||
import pytest
|
||||
import sqlite3
|
||||
|
||||
|
||||
@pytest.mark.parametrize('path,expected', [
|
||||
('foo', ['foo']),
|
||||
('foo,bar', ['foo', 'bar']),
|
||||
('123,433,112', ['123', '433', '112']),
|
||||
('123%2C433,112', ['123,433', '112']),
|
||||
('123%2F433%2F112', ['123/433/112']),
|
||||
])
|
||||
def test_compound_pks_from_path(path, expected):
|
||||
assert expected == app.compound_pks_from_path(path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('sql,table,expected_keys', [
|
||||
('''
|
||||
CREATE TABLE `Compound` (
|
||||
A varchar(5) NOT NULL,
|
||||
B varchar(10) NOT NULL,
|
||||
PRIMARY KEY (A, B)
|
||||
);
|
||||
''', 'Compound', ['A', 'B']),
|
||||
('''
|
||||
CREATE TABLE `Compound2` (
|
||||
A varchar(5) NOT NULL,
|
||||
B varchar(10) NOT NULL,
|
||||
PRIMARY KEY (B, A)
|
||||
);
|
||||
''', 'Compound2', ['B', 'A']),
|
||||
])
|
||||
def test_pks_for_table(sql, table, expected_keys):
|
||||
conn = sqlite3.connect(':memory:')
|
||||
conn.execute(sql)
|
||||
actual = app.pks_for_table(conn, table)
|
||||
assert expected_keys == actual
|
||||
|
||||
|
||||
@pytest.mark.parametrize('row,pks,expected_path', [
|
||||
({'A': 'foo', 'B': 'bar'}, ['A', 'B'], 'foo,bar'),
|
||||
({'A': 'f,o', 'B': 'bar'}, ['A', 'B'], 'f%2Co,bar'),
|
||||
])
|
||||
def test_path_from_row_pks(row, pks, expected_path):
|
||||
actual_path = app.path_from_row_pks(row, pks)
|
||||
assert expected_path == actual_path
|
||||
Loading…
Add table
Add a link
Reference in a new issue