32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Интеграционные тесты db/spec_current.py."""
|
||
import json
|
||
|
||
from db import spec_current, documents, spec_events
|
||
|
||
|
||
class TestListByContract:
|
||
def test_empty(self, db):
|
||
assert spec_current.list_by_contract("nope") == []
|
||
|
||
def test_ordered_by_name(self, db):
|
||
ops = [
|
||
{"action": "ADD", "new_row": {"name": "Б", "price": 2}},
|
||
{"action": "ADD", "new_row": {"name": "А", "price": 1}},
|
||
]
|
||
spec_events.apply_ops("c1", "s1", "d1", ops, "pid", {})
|
||
rows = spec_current.list_by_contract("c1")
|
||
assert [r["name"] for r in rows] == ["А", "Б"]
|
||
|
||
|
||
class TestGetElementsJson:
|
||
def test_none(self, db):
|
||
assert spec_current.get_elements_json("missing") is None
|
||
|
||
def test_parsed(self, db):
|
||
d = documents.insert("f.docx", "m", "raw", batch_id="b1")
|
||
documents.set_parsed(d["id"], [{"type": "paragraph", "text": "x"}])
|
||
ej = spec_current.get_elements_json(d["id"])
|
||
assert ej is not None
|
||
parsed = json.loads(ej)
|
||
assert parsed[0]["text"] == "x"
|