mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Started unit tests for row/table HTML pages
Refs #167 Thanks to the new tests, spotted and fixed a bug where pages that were supposed to have 100 things on them were actually displaying 101.
This commit is contained in:
parent
3f2fed1093
commit
7a7e4b2ed8
3 changed files with 75 additions and 1 deletions
|
|
@ -672,6 +672,7 @@ class TableView(RowTableShared):
|
|||
next_url = urllib.parse.urljoin(request.url, path_with_added_args(request, {
|
||||
'_next': next_value,
|
||||
}))
|
||||
rows = rows[:self.page_size]
|
||||
|
||||
# Number of filtered rows in whole set:
|
||||
filtered_table_rows = None
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -26,6 +26,7 @@ setup(
|
|||
tests_require=[
|
||||
'pytest==3.2.1',
|
||||
'aiohttp==2.3.2',
|
||||
'beautifulsoup4==4.6.0',
|
||||
],
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from bs4 import BeautifulSoup as Soup
|
||||
from datasette.app import Datasette
|
||||
import os
|
||||
import pytest
|
||||
|
|
@ -89,7 +90,7 @@ def test_database_page(app_client):
|
|||
}, {
|
||||
'columns': ['pk1', 'pk2', 'content'],
|
||||
'name': 'compound_primary_key',
|
||||
'count': 0,
|
||||
'count': 1,
|
||||
'hidden': False,
|
||||
'foreign_keys': {'incoming': [], 'outgoing': []},
|
||||
'label_column': None,
|
||||
|
|
@ -441,6 +442,75 @@ def test_css_classes_on_body(app_client, path, expected_classes):
|
|||
assert classes == expected_classes
|
||||
|
||||
|
||||
def test_table_html_simple_primary_key(app_client):
|
||||
response = app_client.get('/test_tables/simple_primary_key', gather_request=False)
|
||||
table = Soup(response.body, 'html.parser').find('table')
|
||||
assert [
|
||||
'Link', 'pk', 'content'
|
||||
] == [th.string for th in table.select('thead th')]
|
||||
assert [
|
||||
[
|
||||
'<td><a href="/test_tables-0f4dfa9/simple_primary_key/1">1</a></td>',
|
||||
'<td>1</td>',
|
||||
'<td>hello</td>'
|
||||
], [
|
||||
'<td><a href="/test_tables-0f4dfa9/simple_primary_key/2">2</a></td>',
|
||||
'<td>2</td>',
|
||||
'<td>world</td>'
|
||||
], [
|
||||
'<td><a href="/test_tables-0f4dfa9/simple_primary_key/3">3</a></td>',
|
||||
'<td>3</td>',
|
||||
'<td></td>'
|
||||
]
|
||||
] == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
|
||||
|
||||
|
||||
def test_row_html_simple_primary_key(app_client):
|
||||
response = app_client.get('/test_tables/simple_primary_key/1', gather_request=False)
|
||||
table = Soup(response.body, 'html.parser').find('table')
|
||||
assert [
|
||||
'pk', 'content'
|
||||
] == [th.string for th in table.select('thead th')]
|
||||
assert [
|
||||
[
|
||||
'<td>1</td>',
|
||||
'<td>hello</td>'
|
||||
]
|
||||
] == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
|
||||
|
||||
|
||||
def test_table_html_no_primary_key(app_client):
|
||||
response = app_client.get('/test_tables/no_primary_key', gather_request=False)
|
||||
table = Soup(response.body, 'html.parser').find('table')
|
||||
assert [
|
||||
'rowid', 'content'
|
||||
] == [th.string for th in table.select('thead th')]
|
||||
expected = [
|
||||
[
|
||||
'<td><a href="/test_tables-0f4dfa9/no_primary_key/{}">{}</a></td>'.format(i, i),
|
||||
'<td>{}</td>'.format(i),
|
||||
] for i in range(1, 51)
|
||||
]
|
||||
assert expected == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
|
||||
|
||||
|
||||
def test_table_html_compound_primary_key(app_client):
|
||||
response = app_client.get('/test_tables/compound_primary_key', gather_request=False)
|
||||
table = Soup(response.body, 'html.parser').find('table')
|
||||
assert [
|
||||
'Link', 'pk1', 'pk2', 'content'
|
||||
] == [th.string for th in table.select('thead th')]
|
||||
expected = [
|
||||
[
|
||||
'<td><a href="/test_tables-0f4dfa9/compound_primary_key/a,b">a,b</a></td>',
|
||||
'<td>a</td>',
|
||||
'<td>b</td>',
|
||||
'<td>c</td>',
|
||||
]
|
||||
]
|
||||
assert expected == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
|
||||
|
||||
|
||||
TABLES = '''
|
||||
CREATE TABLE simple_primary_key (
|
||||
pk varchar(30) primary key,
|
||||
|
|
@ -454,6 +524,8 @@ CREATE TABLE compound_primary_key (
|
|||
PRIMARY KEY (pk1, pk2)
|
||||
);
|
||||
|
||||
INSERT INTO compound_primary_key VALUES ('a', 'b', 'c');
|
||||
|
||||
CREATE TABLE no_primary_key (
|
||||
content text
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue