added pytest test suite (174 tests)
174 tests covering URL normalization, FTS5 query sanitization, SSRF/CSRF guards, sharing-mode logic, DB schema and upsert paths, handler end-to-end flows, and gateway body-size / mesh-whitelist guards. Each recent bug-fix commit (6ffd38d,1bc695f,8dffd8c) has an explicit regression test in test_regressions.py. One xfail documents a minor latent bug in clean_url where port 80 is not stripped from upgraded https URLs.
This commit is contained in:
parent
55c6619ba3
commit
4d522ce62c
18 changed files with 1673 additions and 0 deletions
58
tests/test_pagination.py
Normal file
58
tests/test_pagination.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
"""Tests for `_paginate` and `_page_nav`."""
|
||||
from handlers import _paginate, _page_nav, PER_PAGE
|
||||
|
||||
|
||||
def test_paginate_default_is_one():
|
||||
assert _paginate({}) == 1
|
||||
|
||||
|
||||
def test_paginate_reads_query_string():
|
||||
assert _paginate({"p": ["3"]}) == 3
|
||||
|
||||
|
||||
def test_paginate_clamps_to_one():
|
||||
assert _paginate({"p": ["0"]}) == 1
|
||||
assert _paginate({"p": ["-5"]}) == 1
|
||||
|
||||
|
||||
def test_paginate_handles_bad_input():
|
||||
assert _paginate({"p": ["not-a-number"]}) == 1
|
||||
assert _paginate({"p": []}) == 1
|
||||
|
||||
|
||||
def test_paginate_custom_key():
|
||||
assert _paginate({"batch": ["7"]}, key="batch") == 7
|
||||
|
||||
|
||||
def test_page_nav_empty_when_single_page():
|
||||
assert _page_nav(1, PER_PAGE, "/?q=foo") == ""
|
||||
assert _page_nav(1, 0, "/?q=foo") == ""
|
||||
|
||||
|
||||
def test_page_nav_shows_next_on_first_page():
|
||||
out = _page_nav(1, PER_PAGE * 3, "/?q=foo")
|
||||
assert "next" in out
|
||||
assert "prev" not in out
|
||||
assert "page 1 of 3" in out
|
||||
|
||||
|
||||
def test_page_nav_shows_both_in_middle():
|
||||
out = _page_nav(2, PER_PAGE * 3, "/?q=foo")
|
||||
assert "next" in out
|
||||
assert "prev" in out
|
||||
|
||||
|
||||
def test_page_nav_shows_prev_on_last_page():
|
||||
out = _page_nav(3, PER_PAGE * 3, "/?q=foo")
|
||||
assert "next" not in out
|
||||
assert "prev" in out
|
||||
assert "page 3 of 3" in out
|
||||
|
||||
|
||||
def test_page_nav_handles_query_string_separator():
|
||||
# when base_url already has ?, pagination links must use &
|
||||
out = _page_nav(1, PER_PAGE * 2, "/?q=foo")
|
||||
assert "&p=2" in out
|
||||
# when base_url has no ?, pagination links use ?
|
||||
out = _page_nav(1, PER_PAGE * 2, "/pages")
|
||||
assert "?p=2" in out
|
||||
Loading…
Add table
Add a link
Reference in a new issue