Beispiel #1
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"])

        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"])

        crawler = Crawler()

        login_result = crawler.login(decrypted_credentials["oeci_username"],
                                     decrypted_credentials["oeci_password"],
                                     close_session=False)

        if login_result is False:
            error(401, "Attempted login to OECI failed")

        cases: List[Case] = []
        for alias in request_data["names"]:
            cases += crawler.search(
                alias["first_name"],
                alias["last_name"],
                alias["middle_name"],
                alias["birth_date"],
            ).cases
        cases_with_unique_case_number = [
            list(group)[0]
            for key, group in groupby(cases, lambda case: case.case_number)
        ]
        record = Record(cases_with_unique_case_number)

        expunger = Expunger(record)
        expunger.run()

        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)
        response_data = {"data": {"record": record_summary}}

        current_app.json_encoder = ExpungeModelEncoder

        return response_data  # Json-encoding happens automatically here
def test_record_summarizer_no_cases():
    record = RecordFactory.create([])
    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 == []
Beispiel #3
0
    def post(self):
        request_data = request.get_json()

        if request_data is None:
            error(400, "No json data in request body")

        check_data_fields(request_data, ["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"])

        crawler = Crawler()

        login_result = crawler.login(
            decrypted_credentials["oeci_username"], decrypted_credentials["oeci_password"], close_session=False
        )

        if login_result is False:
            error(401, "Attempted login to OECI failed")

        record = crawler.search(
            request_data["first_name"],
            request_data["last_name"],
            request_data["middle_name"],
            request_data["birth_date"],
        )

        expunger = Expunger(record)
        expunger.run()

        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)
        response_data = {"data": {"record": record}}

        current_app.json_encoder = ExpungeModelEncoder

        return response_data  # Json-encoding happens automatically here
Beispiel #4
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
def test_search(service, monkeypatch):
    service.login(service.user_data["user1"]["email"], service.user_data["user1"]["password"])

    monkeypatch.setattr(search.Crawler, "login", mock_login(True))
    monkeypatch.setattr(search.Crawler, "search", mock_search(service, "john_doe"))

    """
    A separate test, below, verifies that the save-result step
    also works. Here, we mock the function to reduce the scope of the test.
    """
    monkeypatch.setattr(search, "save_result", lambda user_id, request_data, record: None)

    """
    as a more unit-y unit test, we could make the encrypted cookie
    ""manually" in the test code ...
    But attaching a cookie client-side isn't really a thing. So, use the oeci endpoint.
    """

    service.client.post(
        "/api/oeci_login", json={"oeci_username": "******", "oeci_password": "******"}
    )

    assert service.client.cookie_jar._cookies["localhost.local"]["/"]["oeci_token"]

    response = service.client.post("/api/search", json=service.search_request_data)

    assert response.status_code == 200
    data = response.get_json()["data"]

    """
    Check that the resulting "record" field in the response matches what we gave to the
    mock search function.
    (use this json encode-decode approach because it turns a Record or RecordSummary into a dict.)
    """
    assert data["record"] == json.loads(json.dumps(service.mock_record["john_doe"], cls=ExpungeModelEncoder))
    assert data["summary"] == json.loads(
        json.dumps(RecordSummarizer.summarize(service.mock_record["john_doe"]), cls=ExpungeModelEncoder)
    )
    ]

    case_all_ineligible_2 = CaseFactory.create(
        case_number="0004", date_location=["1/1/1995", "Baker"])
    case_all_ineligible_2.charges = [
        ChargeFactory.create(case=case_all_ineligible_2,
                             level="Felony Class A",
                             disposition=["Convicted", Time.TEN_YEARS_AGO])
    ]
    record = RecordFactory.create([
        case_all_eligible, case_partially_eligible, case_possibly_eligible,
        case_all_ineligible, case_all_ineligible_2
    ])
    expunger = Expunger(record)
    expunger.run()
    record_summary = RecordSummarizer.summarize(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"] == ["0000"]
    assert record_summary.cases_sorted["fully_ineligible"] == ["0003", "0004"]
    assert record_summary.cases_sorted["partially_eligible"] == ["0001"]
    assert record_summary.cases_sorted["other"] == ["0002"]
    """
    assert record_summary.county_balances["Baker"] == 700.00
    assert record_summary.county_balances["Multnomah"] == 100.00
    assert record_summary.county_balances["Clackamas"] == 200.00
    assert record_summary.eligible_charges == ["Theft of dignity", "Theft of services"]
    """