fix failing tests

This commit is contained in:
Philipp 2023-12-13 08:20:44 +00:00
parent 5d17df3a18
commit 02d8fb67bb

View File

@ -3,6 +3,7 @@ from pathlib import Path
from unittest import mock from unittest import mock
import httpx import httpx
from django.conf import settings
from django.test import TestCase from django.test import TestCase
from documents.parsers import ParseError from documents.parsers import ParseError
@ -341,7 +342,10 @@ class TestTikaHtmlParse(HttpxMockMixin, BaseMailParserTestCase):
) )
parsed = self.parser.tika_parse(html) parsed = self.parser.tika_parse(html)
self.assertEqual(expected_text, parsed.strip()) self.assertEqual(expected_text, parsed.strip())
self.assertIn("http://localhost:9998", str(self.httpx_mock.get_request().url)) self.assertIn(
f"{settings.TIKA_ENDPOINT}",
str(self.httpx_mock.get_request().url),
)
def test_tika_parse_exception(self): def test_tika_parse_exception(self):
""" """
@ -508,7 +512,7 @@ class TestParser(FileSystemAssertsMixin, HttpxMockMixin, BaseMailParserTestCase)
""" """
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:3000/forms/chromium/convert/html", url=f"{settings.TIKA_GOTENBERG_ENDPOINT}/forms/chromium/convert/html",
method="POST", method="POST",
content=(self.SAMPLE_DIR / "simple_text.eml.pdf").read_bytes(), content=(self.SAMPLE_DIR / "simple_text.eml.pdf").read_bytes(),
) )
@ -529,7 +533,7 @@ class TestParser(FileSystemAssertsMixin, HttpxMockMixin, BaseMailParserTestCase)
- Archive file is generated - Archive file is generated
""" """
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:9998/tika/text", url=f"{settings.TIKA_ENDPOINT}/tika/text",
method="PUT", method="PUT",
json={ json={
"Content-Type": "text/html", "Content-Type": "text/html",
@ -538,12 +542,12 @@ class TestParser(FileSystemAssertsMixin, HttpxMockMixin, BaseMailParserTestCase)
}, },
) )
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:3000/forms/chromium/convert/html", url=f"{settings.TIKA_GOTENBERG_ENDPOINT}/forms/chromium/convert/html",
method="POST", method="POST",
content=(self.SAMPLE_DIR / "html.eml.pdf").read_bytes(), content=(self.SAMPLE_DIR / "html.eml.pdf").read_bytes(),
) )
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:3000/forms/pdfengines/merge", url=f"{settings.TIKA_GOTENBERG_ENDPOINT}/forms/pdfengines/merge",
method="POST", method="POST",
content=b"Pretend merged PDF content", content=b"Pretend merged PDF content",
) )
@ -562,7 +566,7 @@ class TestParser(FileSystemAssertsMixin, HttpxMockMixin, BaseMailParserTestCase)
- ParseError is raised - ParseError is raised
""" """
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:9998/tika/text", url=f"{settings.TIKA_ENDPOINT}/tika/text",
method="PUT", method="PUT",
json={ json={
"Content-Type": "text/html", "Content-Type": "text/html",
@ -571,12 +575,12 @@ class TestParser(FileSystemAssertsMixin, HttpxMockMixin, BaseMailParserTestCase)
}, },
) )
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:3000/forms/chromium/convert/html", url=f"{settings.TIKA_GOTENBERG_ENDPOINT}/forms/chromium/convert/html",
method="POST", method="POST",
content=(self.SAMPLE_DIR / "html.eml.pdf").read_bytes(), content=(self.SAMPLE_DIR / "html.eml.pdf").read_bytes(),
) )
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:3000/forms/chromium/convert/html", url=f"{settings.TIKA_GOTENBERG_ENDPOINT}/forms/chromium/convert/html",
method="POST", method="POST",
status_code=httpx.codes.INTERNAL_SERVER_ERROR, status_code=httpx.codes.INTERNAL_SERVER_ERROR,
) )
@ -594,7 +598,7 @@ class TestParser(FileSystemAssertsMixin, HttpxMockMixin, BaseMailParserTestCase)
- ParseError is raised - ParseError is raised
""" """
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:9998/tika/text", url=f"{settings.TIKA_ENDPOINT}/tika/text",
method="PUT", method="PUT",
json={ json={
"Content-Type": "text/html", "Content-Type": "text/html",
@ -603,12 +607,12 @@ class TestParser(FileSystemAssertsMixin, HttpxMockMixin, BaseMailParserTestCase)
}, },
) )
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:3000/forms/chromium/convert/html", url=f"{settings.TIKA_GOTENBERG_ENDPOINT}/forms/chromium/convert/html",
method="POST", method="POST",
content=(self.SAMPLE_DIR / "html.eml.pdf").read_bytes(), content=(self.SAMPLE_DIR / "html.eml.pdf").read_bytes(),
) )
self.httpx_mock.add_response( self.httpx_mock.add_response(
url="http://localhost:3000/forms/pdfengines/merge", url=f"{settings.TIKA_GOTENBERG_ENDPOINT}/forms/pdfengines/merge",
method="POST", method="POST",
status_code=httpx.codes.INTERNAL_SERVER_ERROR, status_code=httpx.codes.INTERNAL_SERVER_ERROR,
) )
@ -653,5 +657,5 @@ class TestParser(FileSystemAssertsMixin, HttpxMockMixin, BaseMailParserTestCase)
self.assertEqual( self.assertEqual(
str(request.url), str(request.url),
"http://localhost:3000/forms/chromium/convert/html", f"{settings.TIKA_GOTENBERG_ENDPOINT}/forms/chromium/convert/html",
) )