| 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(): |
| |
| |
| 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" |
|
|