Exemple #1
0
def test_add_summary_merge_strategies(example_summary):
    summary2 = copy.deepcopy(example_summary)
    summary2.get_cases()[0].otn = "a_different_otn"
    # default merge_strategy is to ignore new duplicates or
    # new Person
    rec = CRecord(Person("Dummy", "Name", None))
    rec.add_summary(example_summary)
    rec.add_summary(summary2)
    assert rec.cases[0].otn == example_summary.get_cases()[0].otn
    assert rec.person.first_name == "Dummy"

    # alternate merge strategy overwrites duplicates w/ new case
    # but doesn't touch the Person
    rec = CRecord(Person("Dummy", "Name", None))
    rec.add_summary(example_summary)
    rec.add_summary(summary2, case_merge_strategy="overwrite_old")
    assert rec.cases[0].otn == summary2.get_cases()[0].otn
    assert rec.person.first_name == "Dummy"

    # override_person param provides for overwriting the Person with the new summary's
    # Person
    rec = CRecord(Person("Dummy", "Name", None))
    rec.add_summary(example_summary)
    rec.add_summary(summary2, override_person=True)
    assert rec.cases[0].otn != summary2.get_cases()[0].otn
    assert rec.person.first_name == summary2.get_defendant().first_name
Exemple #2
0
def get_person(stree: etree) -> Person:
    """
    Extract a Person the xml of a docket, parsed into sections.

    Returns an empty Person object on errors.

    Args:
        stree: xml tree of a docket, parsed into a header and some number of sections
    
    Returns:
        a Person object
    """
    try:
        name = stree.xpath(
            "docket/header/caption/defendant_line")[0].text.strip()
        first_name, last_name = split_first_name(name)
    except IndexError:
        first_name = ""
        last_name = ""

    aliases = xpath_or_empty_list(stree, "//alias")
    date_of_birth = xpath_date_or_blank(stree, "//birth_date")
    return Person(first_name=first_name,
                  last_name=last_name,
                  date_of_birth=date_of_birth,
                  aliases=aliases)
Exemple #3
0
 def from_dict(dct: dict) -> Expungement:
     dct.update({
         "attorney": Attorney.from_dict(dct["attorney"]),
         "client": Person.from_dict(dct["client"]),
         "cases": [Case.from_dict(c) for c in dct["cases"]],
     })
     return Expungement(**dct)
Exemple #4
0
def test_add_summary_to_crecord():
    summary = parse_pdf(
        pdf="tests/data/CourtSummaryReport.pdf",
        tempdir="tests/data/tmp")
    rec = CRecord(Person("John", "Smith", date(1998, 1, 1)))
    rec.add_summary(summary, override_person=True)
    assert len(rec.person.first_name) > 0
    assert rec.person.first_name != "John"
Exemple #5
0
def example_person():
    return Person(
        first_name="Jane",
        last_name="Smorp",
        aliases=["JSmo", "SmorpyJJ"],
        address="1234 Main St",
        date_of_birth=date(2010, 1, 1),
        ssn="999-99-9999",
    )
Exemple #6
0
def test_init():
    dob = date(2010, 1,1)
    person = Person(**{
        "first_name": "Joe",
        "last_name": "Smith",
        "date_of_birth": dob
    })
    rec = CRecord(**{
        "person": person
    })
    assert rec.person.first_name == "Joe"
    rec = CRecord(
        person = Person(
            first_name="Joan",
            last_name="Smythe",
            date_of_birth=dob
        )
    )
    assert rec.person.last_name == "Smythe"
Exemple #7
0
def get_defendant(summary_xml: etree.Element) -> Person:
    full_name = summary_xml.find("caption/defendant_name").text
    last_first = [n.strip() for n in full_name.split(",")]
    def_dob = summary_xml.find("caption/def_dob").text.strip()
    aliases = [el.text.strip() for el in summary_xml.xpath("//alias")]
    try:
        def_dob = datetime.strptime(def_dob, "%m/%d/%Y").date()
    except ValueError:
        def_dob = None
    return Person(last_first[1], last_first[0], def_dob, aliases=aliases)
Exemple #8
0
def test_serializing_person(example_person):
    ser = to_serializable(example_person)
    assert ser["first_name"] == example_person.first_name
    assert ser["aliases"] == example_person.aliases

    deser = PersonSerializer(data=ser)
    assert deser.is_valid(), deser.error_messages
    deser = deser.validated_data
    deser = Person.from_dict(deser)
    assert isinstance(deser, Person)
    assert deser == example_person
Exemple #9
0
def test_person_todict():
    per = Person("John", "Smeth", date(2010, 1, 1), aliases=["JJ", "Smelly"], 
                 ssn="999-99-9999", address="1234 Main St")
    assert to_serializable(per) == {
        "first_name": "John",
        "last_name": "Smeth",
        "date_of_birth": date(2010, 1, 1).isoformat(),
        "aliases": ["JJ", "Smelly"],
        "ssn": "999-99-9999",
        "address": "1234 Main St"
    }
Exemple #10
0
 def from_dict(dct: dict) -> Optional[CRecord]:
     try:
         try:
             person = Person.from_dict(dct["person"])
         except:
             person = None
         try:
             cases = [Case.from_dict(c) for c in dct["cases"]]
         except:
             cases = []
         return CRecord(person=person, cases=cases)
     except:
         return None
Exemple #11
0
def test_person():
    per = Person(
        "John", "Smeth", 
        date(2010, 1, 1), 
        date_of_death = date(2020, 1, 1), 
        aliases=["SmithGuy"],
        ssn = "999-99-9999",
        address = "1234 Main St.",
    )
    assert per.first_name == "John"
    assert per.last_name == "Smeth"
    assert per.date_of_birth.year == 2010
    assert per.date_of_death.year == 2020
    assert per.aliases == ["SmithGuy"]
    assert per.ssn == "999-99-9999"
    assert per.address == "1234 Main St."
Exemple #12
0
def test_person_from_dict(example_person):
    ser = to_serializable(example_person)
    per2 = Person.from_dict(ser)
    assert example_person.last_name == per2.last_name
Exemple #13
0
def test_person_age():
    per = Person("John", "Smeth", date(2000, 1, 1))
    assert per.age() > 17
Exemple #14
0
def test_add_docket(example_docket):
    rec = CRecord(Person("dummy", "name", None))
    rec.add_docket(example_docket)
    assert len(rec.cases) == 1
    assert rec.person.first_name != "dummy"
Exemple #15
0
def test_add_summary_doesnt_add_duplicates(example_summary):
    summary2 = copy.deepcopy(example_summary)
    rec = CRecord(Person("Dummy", "Name", None))
    rec.add_summary(example_summary)
    rec.add_summary(summary2)
    assert len(rec.cases) == len(example_summary.get_cases())
Exemple #16
0
def is_over_age(person: Person, age_limit: int) -> Decision:
    return Decision(name=f"Is {person.first_name} over {age_limit}?",
                    value=person.age() > 70,
                    reasoning=f"{person.first_name} is {person.age()}")