File size: 1,839 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
from datetime import date

from legex.scrapers.it import ITScraper, _clean_ocr, _first, _parse_solr_date


def test_parse_solr_date_compact():
    assert _parse_solr_date("20240115") == date(2024, 1, 15)


def test_parse_solr_date_iso():
    assert _parse_solr_date("2024-01-15") == date(2024, 1, 15)


def test_parse_solr_date_list():
    assert _parse_solr_date(["20240115"]) == date(2024, 1, 15)


def test_parse_solr_date_invalid():
    assert _parse_solr_date("") is None
    assert _parse_solr_date("garbage") is None


def test_first_handles_list_and_scalar():
    assert _first(["a", "b"]) == "a"
    assert _first("a") == "a"
    assert _first(None) == ""


def test_clean_ocr_collapses_whitespace():
    assert _clean_ocr("foo  bar\n\n\n\nbaz") == "foo bar\n\nbaz"


def test_to_case_builds_xway_attach_link():
    # SentenzeWeb serves PDFs via /xway/.../hc.dll?verbo=attach with `.clean.pdf`
    # rewritten from the Solr `filename` field. Plain /sncass/{filename} 404s.
    doc = {
        "id": "snciv2024500001A",
        "kind": "snciv",
        "numdec": "00001",
        "anno": "2024",
        "datdep": "20240115",
        "filename": "./20240115/snciv@s50@a2024@n00001@tA.pdf",
        "tipoprov": "Ordinanza",
        "ocr": "test content " * 20,
    }
    case = ITScraper._to_case(doc)
    assert case is not None
    assert case.case_id == "00001/2024"
    assert case.decision_date == date(2024, 1, 15)
    assert case.link == (
        "https://www.italgiure.giustizia.it/xway/application/nif/clean/hc.dll"
        "?verbo=attach&db=snciv&id=20240115/snciv@s50@a2024@n00001@tA.clean.pdf"
    )
    assert case.metadata["filename"] == "./20240115/snciv@s50@a2024@n00001@tA.pdf"
    assert case.full_text and "test content" in case.full_text
    assert case.metadata["ecli"] == "ECLI:IT:CASS:2024:snciv2024500001A"