Order norm finder collections by source code

This commit is contained in:
anor
2026-12-04 20:04:44 +10:00
parent 5f50dab4ab
commit 4bb95e757f
2 changed files with 40 additions and 8 deletions
+26
View File
@@ -36,6 +36,32 @@ def test_browse_keeps_sections_and_base_types_separate(tmp_path, monkeypatch):
norm_finder.browse("2022", "ГЭСН", "%")
def test_browse_orders_collections_and_sections_by_norm_code(tmp_path, monkeypatch):
import norm_finder
import fsnb_ref
db = tmp_path / "ordered_fsnb.sqlite"
with sqlite3.connect(db) as con:
con.execute("CREATE TABLE sources (source_id INTEGER)")
con.execute("CREATE TABLE works (base TEXT, base_type TEXT, code TEXT, name TEXT, "
"unit TEXT, cost REAL, price_level TEXT, section_path TEXT)")
con.executemany("INSERT INTO works VALUES (?,?,?,?,?,?,?,?)", [
("ГЭСН-2022", "ГЭСН", "06-01-001-01", "Бетон", "м3", None,
"норма", "Бетонные работы > Раздел 1"),
("ГЭСН-2022", "ГЭСН", "02-01-001-01", "Горные работы", "м3", None,
"норма", "Горные работы > Раздел 1"),
("ГЭСН-2022", "ГЭСН", "01-10-001-01", "Земляные работы 10", "м3", None,
"норма", "Земляные работы > Раздел 10"),
("ГЭСН-2022", "ГЭСН", "01-02-001-01", "Земляные работы 2", "м3", None,
"норма", "Земляные работы > Раздел 2"),
])
monkeypatch.setattr(fsnb_ref, "db_path", lambda: db)
root = norm_finder.browse("2022", "ГЭСН")
assert [row["name"] for row in root["children"]] == [
"Земляные работы", "Горные работы", "Бетонные работы"]
sections = norm_finder.browse("2022", "ГЭСН", "Земляные работы")
assert [row["name"] for row in sections["children"]] == ["Раздел 2", "Раздел 10"]
def test_search_rejects_empty_query_and_uses_existing_fsnb(monkeypatch):
import fsnb_ref
import norm_finder