File size: 2,328 Bytes
6f5156a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | from datetime import date
from legex.models.base import Case
from legex.scrapers.at import (
ATScraper,
_extract_text_from_xml,
_first_geschaeftszahl,
_norm_gz,
_parse_doc_id_date,
)
def _make(case_id: str, rechtsgebiete: str = "Zivilrecht") -> Case:
return Case(
case_id=case_id,
jurisdiction="at",
metadata={"rechtsgebiete": rechtsgebiete},
)
def test_parse_doc_id_date_jjr():
assert _parse_doc_id_date("JJR_20241219_OGH0002_0010OB00108_24Z0000_000") == date(2024, 12, 19)
def test_parse_doc_id_date_jjt():
assert _parse_doc_id_date("JJT_20230515_OGH0002_0040OB00042_23X0000_000") == date(2023, 5, 15)
def test_parse_doc_id_date_invalid():
assert _parse_doc_id_date("not-a-real-id") is None
assert _parse_doc_id_date("") is None
def test_first_geschaeftszahl_single():
assert _first_geschaeftszahl("4Ob402/85") == "4Ob402/85"
def test_first_geschaeftszahl_list_string():
# API often joins related cases with semicolons; we take the first.
raw = {"item": "4Ob402/85; 4Ob402/87; 4Ob128/89"}
assert _first_geschaeftszahl(raw) == "4Ob402/85"
def test_civil_filter_keeps_zivilrecht():
cases = [_make("1Ob1/24z", "Zivilrecht"), _make("2Os1/24x", "Strafrecht")]
kept = ATScraper.civil_filter(cases)
assert [c.case_id for c in kept] == ["1Ob1/24z"]
def test_civil_filter_accepts_multi_value():
case = _make("1Ob1/24z", "Zivilrecht | Arbeitsrecht")
assert ATScraper.civil_filter([case])
def test_norm_gz_strips_whitespace():
# RIS prints "1 Ob 108/24z" in some payloads and "1Ob108/24z" in others.
assert _norm_gz("1 Ob 108/24z") == _norm_gz("1Ob108/24z") == "1ob108/24z"
def test_extract_text_from_xml_concatenates_text_nodes():
xml = b"""<?xml version="1.0"?><root><a>Hello</a><b> world </b><c></c><d>foo bar</d></root>"""
out = _extract_text_from_xml(xml)
assert out == "Hello world foo bar"
def test_extract_text_from_xml_invalid():
assert _extract_text_from_xml(b"<not xml>") is None
def test_enrich_skips_cases_with_existing_text():
# If full_text is already set, enrich shouldn't make a network call.
c = Case(case_id="1Ob1/24z", jurisdiction="at", full_text="cached", metadata={"doc_id": ""})
out = ATScraper.enrich([c])
assert out[0].full_text == "cached"
|