diff --git a/mayan/apps/ocr/tests/test_api.py b/mayan/apps/ocr/tests/test_api.py index c91e92a765..ab14eb91bb 100644 --- a/mayan/apps/ocr/tests/test_api.py +++ b/mayan/apps/ocr/tests/test_api.py @@ -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( diff --git a/mayan/apps/ocr/tests/test_models.py b/mayan/apps/ocr/tests/test_models.py index 4379a210db..4e44c7e50a 100644 --- a/mayan/apps/ocr/tests/test_models.py +++ b/mayan/apps/ocr/tests/test_models.py @@ -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 )