Ejemplo n.º 1
0
def communicate_results(
    sourcerecords: List[SourceRecord],
    analysis: Analysis,
    output_json_path: str,
    output_html_path: str,
    email_address,
) -> None:
    """
    Communicate the results of the record screening.

    Right now, this just means print them out.
    """
    sources = []
    for sr in to_serializable(sourcerecords):
        sr.pop("raw_source")
        sr.pop("parsed_source")
        sources.append(sr)
    results = {"sourcerecords": sources, "analysis": to_serializable(analysis)}
    message_builder = EmailBuilder(sources, analysis)
    if output_json_path is not None:
        with open(output_json_path, "w") as f:
            f.write(json.dumps(results, indent=4))
        logger.info(f"    Analysis written to {output_json_path}.")
    if output_html_path is not None:
        with open(output_html_path, "w") as f:
            html_message = message_builder.html()
            f.write(html_message)
    if email_address is not None:
        message_builder.email(email_address)
Ejemplo n.º 2
0
    def post(self, request):
        """ Analyze a Criminal Record for expungeable and sealable cases and charges.
        
        POST body should be json-endoded CRecord object. 

        Return, if not an error, will be a json-encoded Decision that explains the expungements
        and sealings that can be generated for this record.

        """
        try:
            serializer = CRecordSerializer(data=request.data)
            if serializer.is_valid():
                rec = CRecord.from_dict(serializer.validated_data)
                analysis = (Analysis(rec).rule(expunge_deceased).rule(
                    expunge_over_70).rule(expunge_nonconvictions).rule(
                        expunge_summary_convictions).rule(seal_convictions))
                return Response(to_serializable(analysis))
            return Response(
                {"validation_errors": serializer.errors},
                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
            )
        except Exception as err:
            logger.error(err)
            return Response("Something went wrong",
                            status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 3
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
def test_serialize():
    """
    A sourcerecord should serialize to friendly json-style object
    """
    path = "tests/data/summaries"
    files = os.listdir(path)
    if not os.path.exists(path) or len(files) == 0:
        pytest.fail(f"Need to put example summary files at {path}")
    first = files[0]
    try:
        src = SourceRecord(os.path.join(path, first), parser=parse_pdf)
        src = to_serializable(src)
    except Exception as err:
        pytest.fail(str(err))
Ejemplo n.º 5
0
def test_person_todict():
    per = Person("John",
                 "Smeth",
                 date(2010, 1, 1),
                 aliases=["JJ", "Smelly"],
                 ssn="999-99-9999",
                 address=Address(line_one="1234 Main St.",
                                 city_state_zip="Philadelphia, PA 19103"))
    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": {
            "line_one": "1234 Main St.",
            "city_state_zip": "Philadelphia, PA 19103"
        }
    }
Ejemplo n.º 6
0
def test_case_serialize(example_case):
    """ Serialize a case."""
    serialized = to_serializable(example_case)
    assert "docket_number" in serialized.keys()
    assert "otn" in serialized.keys()
Ejemplo n.º 7
0
def test_serialize_summary(example_summary):
    ser = to_serializable(example_summary)
    assert "_cases" in ser.keys()
Ejemplo n.º 8
0
def test_serialize_docket(example_docket):
    ser = to_serializable(example_docket)
    assert "_case" in ser.keys()
Ejemplo n.º 9
0
def test_serialize_none():
    serialized = to_serializable(None)
    assert serialized == ""
Ejemplo n.º 10
0
def test_case_todict(example_case):
    """ to_serializable transforms a RecordLib case into a json object"""
    assert to_serializable(example_case)["county"] == example_case.county
Ejemplo n.º 11
0
def test_from_dict(example_case):
    assert Case.from_dict({"invalid": "stuff"}) is None
    ser = to_serializable(example_case)
    c2 = Case.from_dict(ser)
    assert c2.docket_number == example_case.docket_number
Ejemplo n.º 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
    assert isinstance(per2.date_of_birth, date)
Ejemplo n.º 13
0
def test_from_dict(example_crecord):
    serialized = to_serializable(example_crecord)
    crec2 = CRecord.from_dict(serialized)
    assert example_crecord.person.last_name == crec2.person.last_name