def test_read_form_416(): url = ( "https://www.fda.gov/downloads/AboutFDA/ReportsManualsForms/Forms/UCM074728.pdf" ) reader = PdfReader(BytesIO(get_pdf_from_url(url, name="issue_416.pdf"))) fields = reader.get_form_text_fields() assert len(fields) > 0
def test_get_form(src, expected, expected_get_fields): """Check if we can read out form data.""" src = os.path.join(RESOURCE_ROOT, src) reader = PdfReader(src) fields = reader.get_form_text_fields() assert fields == expected with open("tmp-fields-report.txt", "w") as f: fields = reader.get_fields(fileobj=f) assert fields == expected_get_fields if fields: for field in fields.values(): # Just access the attributes [ field.field_type, field.parent, field.kids, field.name, field.alternate_name, field.mapping_name, field.flags, field.value, field.default_value, field.additional_actions, ] # cleanup os.remove("tmp-fields-report.txt")