File size: 1,961 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
import pytest

from legex.models.base import Case
from legex.scrapers.ch import CHScraper


@pytest.mark.parametrize(
    "url, expected",
    [
        # JumpCGI shape
        (
            "http://relevancy.bger.ch/cgi-bin/JumpCGI?id=03.10.2024_4A_426/2024",
            ("4A_426/2024", "4A", "4"),
        ),
        (
            "http://relevancy.bger.ch/cgi-bin/JumpCGI?id=20.10.2025_4A_43/2025",
            ("4A_43/2025", "4A", "4"),
        ),
        (
            "http://relevancy.bger.ch/cgi-bin/JumpCGI?id=12.11.2025_5A_957/2025",
            ("5A_957/2025", "5A", "5"),
        ),
        (
            "http://relevancy.bger.ch/cgi-bin/JumpCGI?id=06.11.2024_7B_893/2024",
            ("7B_893/2024", "7B", "7"),
        ),
        # highlight_docid=aza:// shape (plain)
        (
            "http://relevancy.bger.ch/php/aza/http/index.php?highlight_docid=aza://09-09-2025-9C_276-2025&lang=de",
            ("9C_276/2025", "9C", "9"),
        ),
        # URL-encoded aza shape (aza%3A%2F%2F)
        (
            "https://search.bger.ch/ext/eurospider/live/de/php/aza/http/index.php?"
            "lang=de&highlight_docid=aza%3A%2F%2F29-07-2025-2C_401-2025&rank=43",
            ("2C_401/2025", "2C", "2"),
        ),
        # Fallback: no match
        ("https://example.com/not-a-case", (None, None, None)),
        ("", (None, None, None)),
        (None, (None, None, None)),
    ],
)
def test_parse_case_id(url: str | None, expected: tuple) -> None:
    assert CHScraper.parse_case_id(url) == expected


def _case(division: str | None, case_id: str) -> Case:
    md = {"division": division} if division else {}
    return Case(case_id=case_id, link=f"http://x/{case_id}", jurisdiction="ch", metadata=md)


def test_civil_filter_keeps_4_and_5_drops_rest() -> None:
    cases = [_case(d, f"{d}X_1/2020") for d in ["1", "2", "4", "5", "6", None]]
    assert [c.case_id for c in CHScraper.civil_filter(cases)] == ["4X_1/2020", "5X_1/2020"]