Ejemplo n.º 1
0
 def build_response(self):
     request_data = request.get_json()
     Search._validate_request(request_data)
     today = Search._build_today(request_data.get("today", ""))
     return Demo._build_record_summary(request_data["aliases"],
                                       request_data.get("questions"),
                                       request_data.get("edits", {}), today)
Ejemplo n.º 2
0
    def post(self):
        request_data = request.get_json()

        Search._validate_request(request_data)
        return Demo._build_response(request_data["aliases"],
                                    request_data.get("questions"),
                                    request_data.get("edits", {}))
Ejemplo n.º 3
0
 def post(self):
     response = Search().post()
     record = json.loads(response)["record"]
     request_data = request.get_json()
     aliases = request_data["aliases"]
     header = MarkdownSerializer.default_header(aliases)
     source = MarkdownSerializer.to_markdown(record, header)
     pdf = MarkdownToPDF.to_pdf("Expungement analysis", source)
     response = make_response(pdf)
     response.headers["Content-Type"] = "application/pdf"
     filename = Pdf.build_filename(aliases)
     response.headers["Content-Disposition"] = f"inline; filename={filename}"
     return response
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def test_search_cache(service, monkeypatch):

    monkeypatch.setattr(Crawler, "attempt_login",
                        mock_login("Successful login response"))
    monkeypatch.setattr(Crawler, "search", mock_search(service, "john_doe"))

    test_alias = (Alias("john", "deer", "", ""), )
    test_alias_dictionary = [
        {
            "first_name": "john",
            "last_name": "deer",
            "middle_name": "",
            "birth_date": ""
        },
    ]

    Search._build_record_summary("username", "password", test_alias_dictionary,
                                 {}, {}, date.today())
    assert Search.search_cache[test_alias]
Ejemplo n.º 6
0
def test_search_cache_error(service, monkeypatch):

    monkeypatch.setattr(Crawler, "attempt_login",
                        mock_login("Successful login response"))
    monkeypatch.setattr(Crawler, "search", mock_search_fail())
    test_fail_alias = (Alias("jane", "doe", "q", "June 29th"), )

    test_fail_alias_dictionary = [
        {
            "first_name": "jane",
            "last_name": "doe",
            "middle_name": "q",
            "birth_date": "June 29th"
        },
    ]

    Search._build_record_summary("username", "password",
                                 test_fail_alias_dictionary, {}, {})

    assert not Search.search_cache[test_fail_alias]
Ejemplo n.º 7
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
Ejemplo n.º 8
0
 def _build_response(aliases_data, questions_data, edits_data):
     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, Demo.search_cache)
     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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
 def post(self):
     request_data = request.get_json()
     user_information = request_data.get("userInformation")
     record_summary = Search().build_response()
     temp_dir = mkdtemp()
     zip_dir = mkdtemp()
     zip_name = "expungement_packet.zip"
     zip_path = path.join(zip_dir, zip_name)
     zipfile = ZipFile(zip_path, "w")
     for case in record_summary.record.cases:
         pdf = FormFilling._build_pdf_for_case(case, user_information)
         if pdf:
             file_name = f"{case.summary.name}_{case.summary.case_number}.pdf"
             file_path = path.join(temp_dir, file_name)
             PdfWriter().write(file_path, pdf)
             zipfile.write(file_path, file_name)
     zipfile.close()
     return send_file(zip_path,
                      as_attachment=True,
                      attachment_filename=zip_name)