Update OCR app tests to work with Python 3.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -4,8 +4,7 @@ from django.test import override_settings
|
||||
|
||||
from rest_framework import status
|
||||
|
||||
from documents.models import DocumentType
|
||||
from documents.tests import TEST_DOCUMENT_TYPE_LABEL, TEST_SMALL_DOCUMENT_PATH
|
||||
from documents.tests import DocumentTestMixin
|
||||
from rest_api.tests import BaseAPITestCase
|
||||
|
||||
from ..permissions import (
|
||||
@@ -15,25 +14,13 @@ from ..permissions import (
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
@override_settings(DOCUMENT_PARSING_PDFTOTEXT_PATH='')
|
||||
class OCRAPITestCase(BaseAPITestCase):
|
||||
class OCRAPITestCase(DocumentTestMixin, BaseAPITestCase):
|
||||
"""
|
||||
Test the OCR app API endpoints
|
||||
"""
|
||||
def setUp(self):
|
||||
super(OCRAPITestCase, self).setUp()
|
||||
self.login_user()
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE_LABEL
|
||||
)
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(
|
||||
file_object=file_object,
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.document_type.delete()
|
||||
super(OCRAPITestCase, self).tearDown()
|
||||
|
||||
def _request_document_ocr_submit_view(self):
|
||||
return self.post(
|
||||
|
||||
@@ -6,32 +6,15 @@ from common.tests import BaseTestCase
|
||||
from documents.models import DocumentType
|
||||
from documents.runtime import language_choices
|
||||
from documents.tests import (
|
||||
TEST_DEU_DOCUMENT_PATH, TEST_DOCUMENT_TYPE_LABEL, TEST_SMALL_DOCUMENT_PATH
|
||||
DocumentTestMixin, TEST_DEU_DOCUMENT_PATH, TEST_DOCUMENT_TYPE_LABEL
|
||||
)
|
||||
|
||||
|
||||
class DocumentOCRTestCase(BaseTestCase):
|
||||
class DocumentOCRTestCase(DocumentTestMixin, BaseTestCase):
|
||||
# PyOCR's leak descriptor in get_available_languages and image_to_string
|
||||
# Disable descriptor leak test until fixed in upstream
|
||||
_skip_file_descriptor_test = True
|
||||
|
||||
def setUp(self):
|
||||
super(DocumentOCRTestCase, self).setUp()
|
||||
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE_LABEL
|
||||
)
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(
|
||||
file_object=file_object,
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.document.delete()
|
||||
self.document_type.delete()
|
||||
super(DocumentOCRTestCase, self).tearDown()
|
||||
|
||||
def test_ocr_language_backends_end(self):
|
||||
content = self.document.pages.first().ocr_content.content
|
||||
self.assertTrue('Mayan EDMS Documentation' in content)
|
||||
@@ -57,7 +40,7 @@ class GermanOCRSupportTestCase(BaseTestCase):
|
||||
|
||||
self.assertEqual('deu', language_code)
|
||||
|
||||
with open(TEST_DEU_DOCUMENT_PATH) as file_object:
|
||||
with open(TEST_DEU_DOCUMENT_PATH, 'rb') as file_object:
|
||||
self.document = self.document_type.new_document(
|
||||
file_object=file_object, language=language_code
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user