mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-16 00:36:22 +00:00
Feature: Switches to a new client to handle communication with Gotenberg (#4391)
Switches to a new client to handle communication with Gotenberg for merging and generating PDFs
This commit is contained in:
@@ -2,12 +2,11 @@ import datetime
|
||||
import os
|
||||
import zoneinfo
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test import override_settings
|
||||
from httpx import Request
|
||||
from httpx import Response
|
||||
from httpx import codes
|
||||
from httpx._multipart import DataField
|
||||
from rest_framework import status
|
||||
|
||||
from documents.parsers import ParseError
|
||||
@@ -95,8 +94,7 @@ class TestTikaParser(HttpxMockMixin, TestCase):
|
||||
with self.assertRaises(ParseError):
|
||||
self.parser.convert_to_pdf(file, None)
|
||||
|
||||
@mock.patch("paperless_tika.parsers.httpx.post")
|
||||
def test_request_pdf_a_format(self, post: mock.Mock):
|
||||
def test_request_pdf_a_format(self):
|
||||
"""
|
||||
GIVEN:
|
||||
- Document needs to be converted to PDF
|
||||
@@ -108,10 +106,6 @@ class TestTikaParser(HttpxMockMixin, TestCase):
|
||||
file = Path(os.path.join(self.parser.tempdir, "input.odt"))
|
||||
file.touch()
|
||||
|
||||
response = Response(status_code=status.HTTP_200_OK)
|
||||
response.request = Request("POST", "/somewhere/")
|
||||
post.return_value = response
|
||||
|
||||
for setting, expected_key in [
|
||||
("pdfa", "PDF/A-2b"),
|
||||
("pdfa-2", "PDF/A-2b"),
|
||||
@@ -119,11 +113,20 @@ class TestTikaParser(HttpxMockMixin, TestCase):
|
||||
("pdfa-3", "PDF/A-3b"),
|
||||
]:
|
||||
with override_settings(OCR_OUTPUT_TYPE=setting):
|
||||
self.httpx_mock.add_response(
|
||||
status_code=codes.OK,
|
||||
content=b"PDF document",
|
||||
method="POST",
|
||||
)
|
||||
|
||||
self.parser.convert_to_pdf(file, None)
|
||||
|
||||
post.assert_called_once()
|
||||
_, kwargs = post.call_args
|
||||
request = self.httpx_mock.get_request()
|
||||
found = False
|
||||
for field in request.stream.fields:
|
||||
if isinstance(field, DataField) and field.name == "pdfFormat":
|
||||
self.assertEqual(field.value, expected_key)
|
||||
found = True
|
||||
self.assertTrue(found)
|
||||
|
||||
self.assertEqual(kwargs["data"]["pdfFormat"], expected_key)
|
||||
|
||||
post.reset_mock()
|
||||
self.httpx_mock.reset(assert_all_responses_were_requested=False)
|
||||
|
Reference in New Issue
Block a user