def test_handle_duplicate_pdf(self) -> None: """Can we validate PDF not in system?""" d = Docket.objects.create( source=Docket.DIRECT_INPUT, court_id="tennworkcompcl", pacer_case_id=None, docket_number="1234123", case_name="One v. Two", ) oc = OpinionCluster.objects.create( case_name="One v. Two", docket=d, date_filed=datetime.date(2010, 1, 1), ) Opinion.objects.create( cluster=oc, type="Lead Opinion", sha1="ffe0ec472b16e4e573aa1bbaf2ae358460b5d72c", ) form2 = TennWorkersForm( self.work_comp_data, pk="tennworkcompcl", files={"pdf_upload": self.pdf}, ) form2.fields["lead_author"].queryset = Person.objects.filter( positions__court_id="tennworkcompcl") if form2.is_valid(): form2.save() self.assertIn("Document already in database", form2.errors["pdf_upload"][0])
def test_required_case_title(self) -> None: """Can we validate required testing field case title?""" self.work_comp_app_data.pop("case_title") form = TennWorkersForm( self.work_comp_app_data, pk="tennworkcompapp", files={"pdf_upload": self.pdf}, ) qs = Person.objects.filter(positions__court_id="tennworkcompapp") form.fields["lead_author"].queryset = qs form.fields["second_judge"].queryset = qs form.fields["third_judge"].queryset = qs form.is_valid() self.assertEqual(form.errors["case_title"], ["This field is required."])
def test_pdf_validation_failure(self): """Can we fail upload documents that are not PDFs?""" form = TennWorkersForm( self.work_comp_data, pk="tennworkcompcl", files={"pdf_upload": self.png}, ) form.fields["lead_author"].queryset = Person.objects.filter( positions__court_id="tennworkcompcl") self.assertEqual(form.is_valid(), False, form.errors) self.assertEqual( form.errors["pdf_upload"], [ "File extension 'b'png'' is not allowed. Allowed extensions are: 'pdf'." ], )
def test_form_save(self) -> None: """Can we saves successfully to db?""" pre_count = Opinion.objects.all().count() form = TennWorkersForm( self.work_comp_app_data, pk="tennworkcompapp", files={"pdf_upload": self.pdf}, ) qs = Person.objects.filter(positions__court_id="tennworkcompapp") form.fields["lead_author"].queryset = qs form.fields["second_judge"].queryset = qs form.fields["third_judge"].queryset = qs if form.is_valid(): form.save() self.assertEqual(pre_count + 1, Opinion.objects.all().count())
def court_publish_page(request: HttpRequest, pk: int) -> HttpResponse: """Display upload form and intake Opinions for Tenn. Workers Comp Cl/App :param request: A GET or POST request for the page :param pk: The CL Court ID for each court """ if pk not in ["tennworkcompcl", "tennworkcompapp"]: raise Http404("Court pages only implemented for Tennessee so far.") form = TennWorkersForm(pk=pk) if request.method == "POST": form = TennWorkersForm(request.POST, request.FILES, pk=pk) if form.is_valid(): cluster = form.save() goto = reverse("view_case", args=[cluster.pk, cluster.slug]) messages.info( request, "Document uploaded successfully.", extra_tags=goto ) return HttpResponseRedirect( reverse("court_publish_page", kwargs={"pk": pk}) ) else: messages.info( request, "Error submitting form, please review below." ) return render( request, "publish.html", {"form": form, "private": True, "pk": pk} )
def test_pdf_upload(self) -> None: """Can we upload a PDF and form?""" form = TennWorkersForm( self.work_comp_data, pk="tennworkcompcl", files={"pdf_upload": self.pdf}, ) form.fields["lead_author"].queryset = Person.objects.filter( positions__court_id="tennworkcompcl") if form.is_valid(): form.save() self.assertEqual(form.is_valid(), True, form.errors)
def test_tn_wc_app_upload(self) -> None: """Can we test appellate uplading?""" form = TennWorkersForm( self.work_comp_app_data, pk="tennworkcompapp", files={"pdf_upload": self.pdf}, ) qs = Person.objects.filter(positions__court_id="tennworkcompapp") form.fields["lead_author"].queryset = qs form.fields["second_judge"].queryset = qs form.fields["third_judge"].queryset = qs if form.is_valid(): form.save() self.assertEqual(form.is_valid(), True, form.errors)