def test_no_op(): record, questions = RecordCreator.build_record( search("two_cases_two_charges_each"), "username", "password", (), {}) assert len(record.cases) == 2 assert len(record.cases[0].charges) == 2 assert record.cases[0].charges[ 1].disposition.status == DispositionStatus.UNKNOWN
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
def create_ambiguous_record_with_questions( record=JohnDoe.RECORD_WITH_CLOSED_CASES, cases={ "X0001": CaseDetails.case_x(), "X0002": CaseDetails.case_x(), "X0003": CaseDetails.case_x() }, ) -> Tuple[Record, AmbiguousRecord, Dict[str, Question], List[str]]: base_url = "https://publicaccess.courts.oregon.gov/PublicAccessLogin/" with requests_mock.Mocker() as m: m.post(URL.login_url(), text=PostLoginPage.POST_LOGIN_PAGE) m.post("{}{}".format(base_url, "Search.aspx?ID=100"), [{ "text": SearchPageResponse.RESPONSE }, { "text": record }]) for key, value in cases.items(): m.get("{}{}{}".format(base_url, "CaseDetail.aspx?CaseID=", key), text=value) aliases = (Alias(first_name="John", last_name="Doe", middle_name="", birth_date=""), ) return RecordCreator.build_record( RecordCreator.build_search_results.__wrapped__, "username", "password", aliases, {})
def test_edit_charge_type_of_charge(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), { "X0001": { "summary": { "edit_status": "UPDATE" }, "charges": { "X0001-2": { "edit_status": "UPDATE", "charge_type": "MisdemeanorClassA", "level": "Misdemeanor Class A", } }, } }, date.today(), LRUCache(4), ) assert isinstance(record.cases[0].charges[1].charge_type, MisdemeanorClassA)
def test_edit_some_fields_on_case(): record, questions = RecordCreator.build_record( search("two_cases_two_charges_each"), "username", "password", (), { "X0002": { "summary": { "edit_status": "UPDATE", "location": "ocean", "balance_due": "100", "date": "1/1/1981", } } }, date.today(), LRUCache(4), ) assert len(record.cases) == 2 assert record.cases[0].summary.location == "earth" assert record.cases[0].summary.edit_status == EditStatus.UNCHANGED assert record.cases[1].summary.location == "ocean" assert record.cases[1].summary.balance_due_in_cents == 10000 assert record.cases[1].summary.date == date(1981, 1, 1) assert record.cases[1].summary.edit_status == EditStatus.UPDATE
def test_add_disposition(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), { "X0001": { "summary": { "edit_status": "UPDATE" }, "charges": { "X0001-2": { "disposition": { "date": "1/1/2001", "ruling": "Convicted" }, "level": "Misdemeanor Class A", } }, } }, date.today(), LRUCache(4), ) assert record.cases[0].charges[ 1].disposition.status == DispositionStatus.CONVICTED assert record.cases[0].charges[1].edit_status == EditStatus.UNCHANGED
def test_add_new_charge(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), { "X0001": { "summary": { "edit_status": "UPDATE" }, "charges": { "X0001-3": { "edit_status": "ADD", "charge_type": "MisdemeanorClassA", "level": "Misdemeanor Class A", "date": "1/1/2001", "disposition": { "date": "2/1/2020", "ruling": "Convicted" }, } }, } }, date.today(), LRUCache(4), ) assert isinstance(record.cases[0].charges[2].charge_type, MisdemeanorClassA) assert record.cases[0].charges[2].date == date(2001, 1, 1) assert record.cases[0].charges[2].edit_status == EditStatus.ADD
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)
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)
def test_update_case_with_add_and_update_and_delete_charges(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), { "X0001": { "summary": { "case_number": "X0001", "edit_status": "UPDATE", "location": "ocean", "balance_due": "100", "date": "1/1/1981", }, "charges": { "X0001-1": { "edit_status": "UPDATE", "charge_type": "FelonyClassB", "level": "Felony Class B", "date": "1/1/2001", "disposition": { "date": "2/1/2020", "ruling": "Convicted" }, }, "X0001-2": { "edit_status": "DELETE" }, "X0001-3": { "edit_status": "ADD", "charge_type": "FelonyClassC", "date": "1/1/1900", "level": "Felony Class A", "disposition": { "date": "2/1/1910", "ruling": "Convicted" }, }, }, } }, date.today(), LRUCache(4), ) assert len(record.cases) == 1 assert record.cases[0].summary.location == "ocean" assert record.cases[0].summary.edit_status == EditStatus.UPDATE assert record.cases[0].charges[0].ambiguous_charge_id == "X0001-1" assert record.cases[0].charges[0].edit_status == EditStatus.UPDATE assert isinstance(record.cases[0].charges[0].charge_type, FelonyClassB) assert record.cases[0].charges[1].ambiguous_charge_id == "X0001-2" assert record.cases[0].charges[1].edit_status == EditStatus.DELETE assert record.cases[0].charges[2].ambiguous_charge_id == "X0001-3" assert record.cases[0].charges[2].edit_status == EditStatus.ADD
def test_delete_case(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), {"X0001": { "action": "delete" }}, ) assert record == Record((), ())
def test_no_op(): record, questions = RecordCreator.build_record( search("two_cases_two_charges_each"), "username", "password", (), {}) assert len(record.cases) == 2 assert len(record.cases[0].charges) == 2 assert record.cases[1].charges[1].ambiguous_charge_id == "X0002-2" assert record.cases[1].charges[ 1].disposition.status == DispositionStatus.UNKNOWN assert record.cases[1].summary.edit_status == EditStatus.UNCHANGED assert isinstance(record.cases[1].charges[0].charge_type, FelonyClassB) assert record.cases[1].charges[ 0].expungement_result.charge_eligibility.status == ChargeEligibilityStatus.INELIGIBLE assert record.cases[1].charges[ 0].expungement_result.time_eligibility.status == EligibilityStatus.INELIGIBLE
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)
def test_edit_charge_type_of_charge(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), { "X0001": { "action": "edit", "charges": { "X0001-2": { "charge_type": "Misdemeanor" } }, } }, ) assert isinstance(record.cases[0].charges[1].charge_type, Misdemeanor)
def test_add_case(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), { "5": { "summary": { "case_number": "5", "edit_status": "ADD", "location": "ocean", "balance_due": "100", "date": "1/1/1981", }, "charges": { "5-1": { "edit_status": "ADD", "charge_type": "FelonyClassC", "level": "Felony Class C", "date": "1/1/2001", "disposition": { "date": "2/1/2020", "ruling": "Convicted" }, } }, } }, date.today(), LRUCache(4), ) assert len(record.cases) == 2 assert record.cases[0].summary.location == "earth" assert record.cases[0].summary.edit_status == EditStatus.UNCHANGED assert record.cases[1].summary.location == "ocean" assert record.cases[1].summary.balance_due_in_cents == 10000 assert record.cases[1].summary.date == date(1981, 1, 1) assert record.cases[1].summary.edit_status == EditStatus.ADD assert record.cases[1].charges[0].edit_status == EditStatus.ADD assert record.cases[1].charges[0].charge_type assert isinstance(record.cases[1].charges[0].charge_type, FelonyClassC)
def test_delete_case(): record, questions = RecordCreator.build_record( search("two_cases_two_charges_each"), "username", "password", (), {"X0001": { "summary": { "edit_status": "DELETE" } }}, ) assert record.cases[0].summary.case_number == "X0001" assert record.cases[0].summary.edit_status == EditStatus.DELETE assert len(record.cases[0].charges) == 2 assert record.cases[0].charges[0].edit_status == EditStatus.DELETE assert record.cases[0].charges[1].edit_status == EditStatus.DELETE assert record.cases[1].summary.case_number == "X0002" assert record.cases[1].summary.edit_status == EditStatus.UNCHANGED
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)
def test_add_disposition(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), { "X0001": { "action": "edit", "charges": { "X0001-2": { "disposition": { "date": "1/1/2001", "ruling": "Convicted" } } }, } }, ) assert record.cases[0].charges[ 1].disposition.status == DispositionStatus.CONVICTED
def test_edit_some_fields_on_case(): record, questions = RecordCreator.build_record( search("two_cases_two_charges_each"), "username", "password", (), { "X0002": { "action": "edit", "summary": { "location": "ocean", "balance_due": "100", "date": "1/1/1001", } } }, ) assert len(record.cases) == 2 assert record.cases[0].summary.location == "earth" assert record.cases[1].summary.location == "ocean" assert record.cases[1].summary.balance_due_in_cents == 10000 assert record.cases[1].summary.date == date(1001, 1, 1)
def test_add_new_charge(): record, questions = RecordCreator.build_record( search("single_case_two_charges"), "username", "password", (), { "X0001": { "action": "edit", "charges": { "X0001-3": { "charge_type": "Misdemeanor", "date": "1/1/2001", "disposition": { "date": "2/1/2020", "ruling": "Convicted" }, } }, } }, ) assert isinstance(record.cases[0].charges[2].charge_type, Misdemeanor) assert record.cases[0].charges[2].date == date(2001, 1, 1)
def test_deleted_charge_does_not_block(): """""" record, questions = RecordCreator.build_record( search("two_cases_two_charges_each"), "username", "password", (), { "X0001": { "summary": { "edit_status": "UPDATE" }, "charges": { "X0001-1": { "edit_status": "UPDATE", "date": "1/1/2020", "disposition": { "date": "2/1/2020", "ruling": "Convicted" }, "level": "Misdemeanor Class A", } }, }, }, date.today(), LRUCache(4), ) assert record.cases[0].summary.case_number == "X0001" assert record.cases[0].summary.edit_status == EditStatus.UPDATE assert record.cases[0].charges[0].edit_status == EditStatus.UPDATE assert record.cases[0].charges[1].edit_status == EditStatus.UNCHANGED assert record.cases[1].summary.case_number == "X0002" assert (record.cases[1].charges[0].expungement_result.charge_eligibility. status == ChargeEligibilityStatus.WILL_BE_ELIGIBLE) record, questions = RecordCreator.build_record( search("two_cases_two_charges_each"), "username", "password", (), { "X0001": { "summary": { "edit_status": "UPDATE", }, "charges": { "X0001-1": { "edit_status": "DELETE" }, "X0001-2": { "edit_status": "DELETE" }, }, } }, date.today(), LRUCache(4), ) assert record.cases[0].summary.case_number == "X0001" assert record.cases[0].summary.edit_status == EditStatus.UPDATE assert record.cases[0].charges[0].edit_status == EditStatus.DELETE assert record.cases[0].charges[1].edit_status == EditStatus.DELETE assert record.cases[1].summary.case_number == "X0002" assert (record.cases[1].charges[0].expungement_result.charge_eligibility. status == ChargeEligibilityStatus.ELIGIBLE_NOW)
def test_no_op(): record, ambiguous_record, questions, _ = RecordCreator.build_record( search("two_cases_two_charges_each"), "username", "password", (), {}) assert len(record.cases) == 2 assert len(record.cases[0].charges) == 2 assert record.cases[0].charges[1].disposition == None