Skip to content

Commit

Permalink
Add TOC endpoint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-piles committed Jul 16, 2024
1 parent 9dee746 commit 22668cd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ async def error():

@app.post("/")
@catch_exceptions
async def run(file: UploadFile = File(...)):
async def run(file: UploadFile = File(...), fast: bool = Form(False)):
if fast:
return await run_in_threadpool(analyze_pdf_fast, file.file.read())

return await run_in_threadpool(analyze_pdf, file.file.read(), "")


Expand All @@ -44,12 +47,6 @@ async def get_xml_by_name(xml_file_name: str):
return await run_in_threadpool(get_xml, xml_file_name)


@app.post("/fast")
@catch_exceptions
async def run_fast(file: UploadFile = File(...)):
return await run_in_threadpool(analyze_pdf_fast, file.file.read())


@app.post("/toc")
@catch_exceptions
async def get_toc_endpoint(file: UploadFile = File(...), fast: bool = Form(False)):
Expand Down
29 changes: 29 additions & 0 deletions src/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,32 @@ def test_chinese_fast(self):
results = requests.post(f"{self.service_url}", files=files, data=data)

self.assertEqual(200, results.status_code)

def test_toc(self):
with open(f"{ROOT_PATH}/test_pdfs/toc-test.pdf", "rb") as stream:
files = {"file": stream}

response = requests.post(f"{self.service_url}/toc", files=files)

response_json = response.json()
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response_json), 5)
self.assertEqual(response_json[0]["label"], "TEST")
self.assertEqual(response_json[0]["indentation"], 0)
self.assertEqual(response_json[-1]["label"], "C. TITLE LONGER")
self.assertEqual(response_json[-1]["indentation"], 2)

def test_toc_fast(self):
with open(f"{ROOT_PATH}/test_pdfs/toc-test.pdf", "rb") as stream:
files = {"file": stream}
data = {"fast": "True"}

response = requests.post(f"{self.service_url}/toc", files=files, data=data)

response_json = response.json()
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response_json), 5)
self.assertEqual(response_json[0]["label"], "TEST")
self.assertEqual(response_json[0]["indentation"], 0)
self.assertEqual(response_json[-1]["label"], "C. TITLE LONGER")
self.assertEqual(response_json[-1]["indentation"], 2)
Binary file added test_pdfs/toc-test.pdf
Binary file not shown.

0 comments on commit 22668cd

Please sign in to comment.