Пример #1
0
    def post(self):
        request_data = request.get_json()
        if request_data is None or not request_data.get("aliases"):
            error(400, "No json data in request body")
        check_data_fields(request_data, ["aliases"])
        for alias in request_data["aliases"]:
            check_data_fields(
                alias,
                ["first_name", "last_name", "middle_name", "birth_date"])

        cipher = DataCipher(key=current_app.config.get("SECRET_KEY"))

        if not "oeci_token" in request.cookies.keys():
            error(401, "Missing login credentials to OECI.")
        decrypted_credentials = cipher.decrypt(request.cookies["oeci_token"])
        username, password = decrypted_credentials[
            "oeci_username"], decrypted_credentials["oeci_password"]

        record, ambiguous_record, questions = RecordCreator.build_record(
            username, password, request_data["aliases"])
        if questions:
            session["ambiguous_record"] = pickle.dumps(ambiguous_record)

        try:
            save_result(request_data, record)
        except Exception as ex:
            logging.error("Saving search result failed with exception: %s" %
                          ex,
                          stack_info=True)

        record_summary = RecordSummarizer.summarize(record, questions)
        response_data = {"data": {"record": record_summary}}
        encoded_response = json.dumps(response_data, cls=ExpungeModelEncoder)
        return encoded_response
Пример #2
0
def test_disambiguate_endpoint_with_diverted_answer(record_with_single_duii):
    ambiguous_record = record_with_single_duii[1]
    answers = {
        "CASEJD1-1":
        Question(
            ambiguous_charge_id="CASEJD1-1",
            case_number="CASEJD1",
            question=
            "Was the charge dismissed pursuant to a court-ordered diversion program?",
            options={
                "Yes": "CASEJD1-1-0",
                "No": "CASEJD1-1-1"
            },
            answer="CASEJD1-1-0",
        )
    }
    questions = json.loads(json.dumps(answers))
    unknown_dispositions = record_with_single_duii[3]
    questions, record = Search.disambiguate_record(ambiguous_record, questions)
    record_summary = RecordSummarizer.summarize(record, questions,
                                                unknown_dispositions)
    response_data = {"record": record_summary}
    response_as_dict = json.loads(
        json.dumps(response_data, cls=ExpungeModelEncoder))
    assert response_as_dict == DIVERTED_RESPONSE
Пример #3
0
 def _build_record_summary(username, password, aliases_data, questions_data, edits_data) -> RecordSummary:
     aliases = [from_dict(data_class=Alias, data=alias) for alias in aliases_data]
     record, questions = RecordCreator.build_record(
         RecordCreator.build_search_results, username, password, tuple(aliases), edits_data, Search.search_cache
     )
     if questions_data:
         questions = Search._build_questions(questions_data)
     return RecordSummarizer.summarize(record, questions)
Пример #4
0
def test_record_summarizer_no_cases():
    record = Record(tuple([]))
    record_summary = RecordSummarizer.summarize(record, {})

    assert record_summary.total_balance_due == 0.00
    assert record_summary.total_cases == 0
    assert record_summary.total_charges == 0
    assert record_summary.county_balances == []
    assert record_summary.eligible_charges_by_date == {}
def test_record_summarizer_no_cases():
    record = Record(tuple([]))
    record_summary = RecordSummarizer.summarize(record, {})

    assert record_summary.total_fines_due == 0.00
    assert record_summary.total_cases == 0
    assert record_summary.total_charges == 0
    assert record_summary.county_fines == []
    assert record_summary.charges_grouped_by_eligibility_and_case == {}
Пример #6
0
 def _build_response(username, password, aliases_data, questions_data, edits_data):
     aliases = [from_dict(data_class=Alias, data=alias) for alias in aliases_data]
     record, questions = RecordCreator.build_record(
         RecordCreator.build_search_results, username, password, tuple(aliases), edits_data
     )
     if questions_data:
         questions = Search._build_questions(questions_data)
     record_summary = RecordSummarizer.summarize(record, questions)
     response_data = {"record": record_summary}
     return json.dumps(response_data, cls=ExpungeModelEncoder)
Пример #7
0
def test_pdf_print(example_record):
    record_summary = RecordSummarizer.summarize(example_record, {})
    record = json.loads(json.dumps(record_summary, cls=ExpungeModelEncoder))
    aliases = [
        {"first_name": "john", "middle_name": "", "last_name": "smith", "birth_date": "2/2/2020"},
        {"first_name": "john", "middle_name": "", "last_name": "doe", "birth_date": ""},
    ]
    header = MarkdownSerializer.default_header(aliases)
    source = MarkdownSerializer.to_markdown(record, header)
    assert source == EXPECTED_MARKDOWN
def test_record_summarizer_no_cases():
    record = Record(tuple([]))
    record_summary = RecordSummarizer.summarize(record, {})

    assert record_summary.total_fines_due == 0.00
    assert record_summary.total_cases == 0
    assert record_summary.total_charges == 0
    assert record_summary.county_fines == []
    assert record_summary.eligible_charges_by_date == {}
    assert record_summary.county_filing_fees == []
    assert record_summary.no_fees_reason == "None"
Пример #9
0
def test_disambiguate_endpoint_with_no_answers(record_with_single_duii):
    ambiguous_record = record_with_single_duii[1]
    questions = json.loads(json.dumps(record_with_single_duii[2]))
    unknown_dispositions = record_with_single_duii[3]
    questions, record = Search.disambiguate_record(ambiguous_record, questions)
    record_summary = RecordSummarizer.summarize(record, questions,
                                                unknown_dispositions)
    response_data = {"record": record_summary}
    response_as_dict = json.loads(
        json.dumps(response_data, cls=ExpungeModelEncoder))
    assert response_as_dict == DUII_SEARCH_RESPONSE
def test_record_summarizer_no_cases():
    record = Record([])
    record_summary = RecordSummarizer.summarize(record, {})

    assert record_summary.total_balance_due == 0.00
    assert record_summary.total_cases == 0
    assert record_summary.total_charges == 0
    assert record_summary.cases_sorted["fully_eligible"] == []
    assert record_summary.cases_sorted["fully_ineligible"] == []
    assert record_summary.cases_sorted["partially_eligible"] == []
    assert record_summary.cases_sorted["other"] == []
    assert record_summary.county_balances == []
    assert record_summary.eligible_charges_by_date == [("now", [])]
Пример #11
0
 def build_response(ambiguous_record: AmbiguousRecord,
                    questions_data: Dict[str, Any]):
     questions = [
         from_dict(data_class=Question, data=question)
         for id, question in questions_data.items()
     ]
     questions_as_dict = dict(
         list(map(lambda q: (q.ambiguous_charge_id, q), questions)))
     updated_ambiguous_record = RecordMerger.filter_ambiguous_record(
         ambiguous_record, questions)
     record = RecordCreator.analyze_ambiguous_record(
         updated_ambiguous_record)
     record_summary = RecordSummarizer.summarize(record, questions_as_dict)
     response_data = {"data": {"record": record_summary}}
     return json.dumps(response_data, cls=ExpungeModelEncoder)
Пример #12
0
 def _build_record_summary(aliases_data, questions_data, edits_data, today):
     aliases = [
         from_dict(data_class=Alias, data=alias) for alias in aliases_data
     ]
     record, questions = RecordCreator.build_record(
         DemoRecords.build_search_results,
         "username",
         "password",
         tuple(aliases),
         edits_data,
         today,
         Demo.search_cache,
     )
     if questions_data:
         questions = Search._build_questions(questions_data)
     return RecordSummarizer.summarize(record, questions)
Пример #13
0
    def post(self):
        request_data = request.get_json()

        if request_data is None or not request_data.get("names"):
            error(400, "No json data in request body")

        for alias in request_data["names"]:
            check_data_fields(
                alias,
                ["first_name", "last_name", "middle_name", "birth_date"])

        record = build_record()
        record_summary = RecordSummarizer.summarize(record)
        response_data = {"data": {"record": record_summary}}

        current_app.json_encoder = ExpungeModelEncoder

        return response_data  # Json-encoding happens automatically here
Пример #14
0
 def _build_response(username, password, aliases_data, questions_data,
                     edits_data):
     aliases = [
         from_dict(data_class=Alias, data=alias) for alias in aliases_data
     ]
     record, ambiguous_record, questions, disposition_was_unknown = RecordCreator.build_record(
         RecordCreator.build_search_results, username, password,
         tuple(aliases), edits_data)
     if questions_data:
         questions, record = Search.disambiguate_record(
             ambiguous_record, questions_data)
     try:
         save_search_event(aliases_data)
     except Exception as ex:
         logging.error("Saving search result failed with exception: %s" %
                       ex,
                       stack_info=True)
     record_summary = RecordSummarizer.summarize(record, questions,
                                                 disposition_was_unknown)
     response_data = {"record": record_summary}
     return json.dumps(response_data, cls=ExpungeModelEncoder)
Пример #15
0
def test_marijuana_violation_uses_statewide_form(record_with_mj_over_21):
    expunger_result = Expunger.run(record_with_mj_over_21)
    merged_record = RecordMerger.merge([record_with_mj_over_21],
                                       [expunger_result], [])
    record_summary = RecordSummarizer.summarize(merged_record, {})
    user_information = {
        "full_name": "",
        "date_of_birth": "",
        "mailing_address": "",
        "phone_number": "",
        "city": "",
        "state": "",
        "zip_code": "",
    }
    zip_path, zip_name = FormFilling.build_zip(record_summary,
                                               user_information)
    temp_dir = mkdtemp()
    with ZipFile(zip_path, "r") as zip_ref:
        zip_ref.extractall(temp_dir)
        for _root, _dir, files in os.walk(temp_dir):
            assert len(files) == 1
            assert "statewide_marijuana_conviction" in files[0]
Пример #16
0
def test_normal_conviction_uses_multnomah_conviction_form():
    record = CrawlerFactory.create(JohnDoe.SINGLE_CASE_RECORD,
                                   {"CASEJD1": CaseDetails.CASEJD74})
    expunger_result = Expunger.run(record)
    merged_record = RecordMerger.merge([record], [expunger_result], [])
    record_summary = RecordSummarizer.summarize(merged_record, {})
    user_information = {
        "full_name": "",
        "date_of_birth": "",
        "mailing_address": "",
        "phone_number": "",
        "city": "",
        "state": "",
        "zip_code": "",
    }
    zip_path, zip_name = FormFilling.build_zip(record_summary,
                                               user_information)
    temp_dir = mkdtemp()
    with ZipFile(zip_path, "r") as zip_ref:
        zip_ref.extractall(temp_dir)
        for _root, _dir, files in os.walk(temp_dir):
            assert len(files) == 1
            assert "multnomah_conviction" in files[0]
def test_record_summarizer_multiple_cases():
    case_all_eligible = CaseFactory.create(case_number="1", balance="100.00", date_location=["1/1/1995", "Multnomah"])
    case_all_eligible.charges = [
        ChargeFactory.create(
            case_number=case_all_eligible.case_number,
            name="Theft of dignity",
            disposition=Disposition(ruling="Convicted", date=Time.TEN_YEARS_AGO),
        )
    ]

    case_partially_eligible = CaseFactory.create(
        case_number="2", balance="200.00", date_location=["1/1/1995", "Clackamas"]
    )
    case_partially_eligible.charges = [
        ChargeFactory.create(
            case_number=case_partially_eligible.case_number,
            disposition=Disposition(ruling="Convicted", date=Time.TEN_YEARS_AGO),
        ),
        ChargeFactory.create(
            case_number=case_partially_eligible.case_number,
            level="Felony Class A",
            disposition=Disposition(ruling="Convicted", date=Time.TEN_YEARS_AGO),
        ),
    ]

    case_possibly_eligible = CaseFactory.create(case_number="3", balance="300.00", date_location=["1/1/1995", "Baker"])
    case_possibly_eligible.charges = [
        ChargeFactory.create(
            case_number=case_possibly_eligible.case_number,
            level="Felony Class B",
            disposition=Disposition(ruling="Convicted", date=Time.TEN_YEARS_AGO),
        )
    ]

    case_all_ineligible = CaseFactory.create(case_number="4", balance="400.00", date_location=["1/1/1995", "Baker"])
    case_all_ineligible.charges = [
        ChargeFactory.create(
            case_number=case_all_ineligible.case_number,
            level="Felony Class A",
            disposition=Disposition(ruling="Convicted", date=Time.TEN_YEARS_AGO),
        )
    ]

    case_all_ineligible_2 = CaseFactory.create(case_number="5", date_location=["1/1/1995", "Baker"])
    case_all_ineligible_2.charges = [
        ChargeFactory.create(
            case_number=case_all_ineligible_2.case_number,
            level="Felony Class A",
            disposition=Disposition(ruling="Convicted", date=Time.TEN_YEARS_AGO),
        )
    ]
    record = Record(
        [case_all_eligible, case_partially_eligible, case_possibly_eligible, case_all_ineligible, case_all_ineligible_2]
    )
    expunger = Expunger(record)
    expunger_result = expunger.run()
    merged_record = RecordMerger.merge([record], [expunger_result])
    record_summary = RecordSummarizer.summarize(merged_record, {})

    assert record_summary.total_balance_due == 1000.00
    assert record_summary.total_cases == 5
    assert record_summary.total_charges == 6
    assert record_summary.cases_sorted["fully_eligible"] == ["1"]
    assert record_summary.cases_sorted["fully_ineligible"] == ["4", "5"]
    assert record_summary.cases_sorted["partially_eligible"] == ["2"]
    assert record_summary.cases_sorted["other"] == ["3"]

    """
def test_record_summarizer_multiple_cases():
    case_all_eligible = CaseFactory.create(
        case_number="1",
        balance="100.00",
        date_location=["1/1/1995", "Multnomah"],
        charges=tuple([
            ChargeFactory.create(
                case_number="1",
                name="Theft of dignity",
                disposition=DispositionCreator.create(ruling="Convicted",
                                                      date=date(2010, 1, 1)),
            )
        ]),
    )

    case_partially_eligible = CaseFactory.create(
        case_number="2",
        balance="200.00",
        date_location=["1/1/1995", "Clackamas"],
        charges=tuple([
            ChargeFactory.create(
                case_number="2",
                disposition=DispositionCreator.create(ruling="Convicted",
                                                      date=date(2010, 1, 1)),
            ),
            ChargeFactory.create(
                case_number="2",
                level="Felony Class A",
                disposition=DispositionCreator.create(ruling="Convicted",
                                                      date=date(2010, 1, 1)),
            ),
        ]),
    )

    case_possibly_eligible = CaseFactory.create(
        case_number="3",
        balance="300.00",
        date_location=["1/1/1995", "Baker"],
        charges=tuple([
            ChargeFactory.create(
                case_number="3",
                level="Felony Class B",
                disposition=DispositionCreator.create(ruling="Convicted",
                                                      date=date(2010, 1, 1)),
            )
        ]),
    )

    case_all_ineligible = CaseFactory.create(
        case_number="4",
        balance="400.00",
        date_location=["1/1/1995", "Baker"],
        charges=tuple([
            ChargeFactory.create(
                case_number="4",
                level="Felony Class A",
                disposition=DispositionCreator.create(ruling="Convicted",
                                                      date=date(2010, 1, 1)),
            )
        ]),
    )

    case_all_ineligible_2 = CaseFactory.create(
        case_number="5",
        date_location=["1/1/1995", "Baker"],
        charges=tuple([
            ChargeFactory.create(
                case_number="5",
                level="Felony Class A",
                disposition=DispositionCreator.create(ruling="Convicted",
                                                      date=date(2010, 1, 1)),
            )
        ]),
    )
    record = Record(
        tuple([
            case_all_eligible,
            case_partially_eligible,
            case_possibly_eligible,
            case_all_ineligible,
            case_all_ineligible_2,
        ]))
    expunger_result = Expunger.run(record)

    merged_record = RecordMerger.merge([record], [expunger_result], [])
    record_summary = RecordSummarizer.summarize(merged_record, {})

    assert record_summary.total_fines_due == 1000.00
    assert record_summary.total_cases == 5
    assert record_summary.total_charges == 6
    assert record_summary.eligible_charges_by_date == {
        "Eligible Jan 1, 2030": [(
            case_possibly_eligible.charges[0].ambiguous_charge_id,
            "Theft of services (CONVICTED) Charged Jan 1, "
            "2010",
        )],
        "Eligible Now": [
            (case_all_eligible.charges[0].ambiguous_charge_id,
             "Theft of dignity (CONVICTED) Charged Jan 1, 2010"),
            (
                case_partially_eligible.charges[0].ambiguous_charge_id,
                "Theft of services (CONVICTED) Charged Jan 1, 2010",
            ),
        ],
        "Ineligible": [
            (
                case_partially_eligible.charges[1].ambiguous_charge_id,
                "Theft of services (CONVICTED) Charged Jan 1, 2010",
            ),
            (
                case_all_ineligible.charges[0].ambiguous_charge_id,
                "Theft of services (CONVICTED) Charged Jan 1, 2010",
            ),
            (
                case_all_ineligible_2.charges[0].ambiguous_charge_id,
                "Theft of services (CONVICTED) Charged Jan 1, 2010",
            ),
        ],
    }
    assert len(record_summary.county_filing_fees) == 2
    assert record_summary.total_filing_fees_due == 722
    assert (next(county.total_fines_due
                 for county in record_summary.county_fines
                 if county.county_name == "Multnomah") == 100)
    assert (next(county.total_fines_due
                 for county in record_summary.county_fines
                 if county.county_name == "Clackamas") == 200)
    assert (next(county.total_fines_due
                 for county in record_summary.county_fines
                 if county.county_name == "Baker") == 700)