Code style cleanups. Switch to a smaller document for tests.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -4,30 +4,21 @@ 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_DOCUMENT_PATH
|
||||
from documents.tests import DocumentTestMixin, TEST_HYBRID_DOCUMENT
|
||||
from rest_api.tests import BaseAPITestCase
|
||||
|
||||
from ..permissions import permission_content_view
|
||||
|
||||
TEST_DOCUMENT_CONTENT = 'Sample text'
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class DocumentParsingAPITestCase(BaseAPITestCase):
|
||||
class DocumentParsingAPITestCase(DocumentTestMixin, BaseAPITestCase):
|
||||
test_document_filename = TEST_HYBRID_DOCUMENT
|
||||
|
||||
def setUp(self):
|
||||
super(DocumentParsingAPITestCase, self).setUp()
|
||||
self.login_user()
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE_LABEL
|
||||
)
|
||||
|
||||
with open(TEST_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(
|
||||
file_object=file_object,
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.document_type.delete()
|
||||
super(DocumentParsingAPITestCase, self).tearDown()
|
||||
|
||||
def _request_document_page_content_view(self):
|
||||
return self.get(
|
||||
@@ -49,5 +40,5 @@ class DocumentParsingAPITestCase(BaseAPITestCase):
|
||||
response = self._request_document_page_content_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertTrue(
|
||||
'Mayan EDMS Documentation' in response.data['content']
|
||||
TEST_DOCUMENT_CONTENT in response.data['content']
|
||||
)
|
||||
|
||||
@@ -2,11 +2,13 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.test import override_settings
|
||||
|
||||
from documents.tests import GenericDocumentTestCase, TEST_DOCUMENT_PATH
|
||||
from documents.tests import GenericDocumentTestCase, TEST_HYBRID_DOCUMENT
|
||||
|
||||
TEST_DOCUMENT_CONTENT = 'Sample text'
|
||||
|
||||
|
||||
class DocumentAutoParsingTestCase(GenericDocumentTestCase):
|
||||
test_document_filename = TEST_DOCUMENT_PATH
|
||||
test_document_filename = TEST_HYBRID_DOCUMENT
|
||||
auto_create_document_type = False
|
||||
|
||||
@override_settings(DOCUMENT_PARSING_AUTO_PARSING=False)
|
||||
@@ -20,4 +22,6 @@ class DocumentAutoParsingTestCase(GenericDocumentTestCase):
|
||||
def test_enabled_auto_parsing(self):
|
||||
self._create_document_type()
|
||||
self.document = self.upload_document()
|
||||
self.assertTrue('Mayan' in self.document.content().next())
|
||||
self.assertTrue(
|
||||
TEST_DOCUMENT_CONTENT in self.document.content().next()
|
||||
)
|
||||
|
||||
@@ -1,31 +1,18 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.core.files.base import File
|
||||
from django.test import override_settings
|
||||
|
||||
from common.tests import BaseTestCase
|
||||
from documents.models import DocumentType
|
||||
from documents.tests import TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE_LABEL
|
||||
from documents.tests import DocumentTestMixin, TEST_HYBRID_DOCUMENT
|
||||
|
||||
from ..parsers import PopplerParser
|
||||
|
||||
TEST_DOCUMENT_CONTENT = 'Sample text'
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class ParserTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
super(ParserTestCase, self).setUp()
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE_LABEL
|
||||
)
|
||||
|
||||
with open(TEST_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(
|
||||
file_object=File(file_object)
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.document_type.delete()
|
||||
super(ParserTestCase, self).tearDown()
|
||||
class ParserTestCase(DocumentTestMixin, BaseTestCase):
|
||||
test_document_filename = TEST_HYBRID_DOCUMENT
|
||||
|
||||
def test_poppler_parser(self):
|
||||
parser = PopplerParser()
|
||||
@@ -33,5 +20,5 @@ class ParserTestCase(BaseTestCase):
|
||||
parser.process_document_version(self.document.latest_version)
|
||||
|
||||
self.assertTrue(
|
||||
'Mayan EDMS Documentation' in self.document.pages.first().content.content
|
||||
TEST_DOCUMENT_CONTENT in self.document.pages.first().content.content
|
||||
)
|
||||
|
||||
@@ -2,24 +2,22 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.test import override_settings
|
||||
|
||||
from documents.tests import (
|
||||
GenericDocumentViewTestCase, TEST_DOCUMENT_FILENAME,
|
||||
TEST_DOCUMENT_PATH
|
||||
)
|
||||
from documents.tests import GenericDocumentViewTestCase, TEST_HYBRID_DOCUMENT
|
||||
|
||||
from ..permissions import (
|
||||
permission_content_view, permission_document_type_parsing_setup
|
||||
)
|
||||
from ..utils import get_document_content
|
||||
|
||||
TEST_DOCUMENT_CONTENT = 'Sample text'
|
||||
|
||||
|
||||
@override_settings(DOCUMENT_PARSING_AUTO_PARSING=True)
|
||||
class DocumentContentViewsTestCase(GenericDocumentViewTestCase):
|
||||
_skip_file_descriptor_test = True
|
||||
|
||||
# Ensure we use a PDF file
|
||||
test_document_filename = TEST_DOCUMENT_FILENAME
|
||||
test_document_path = TEST_DOCUMENT_PATH
|
||||
test_document_filename = TEST_HYBRID_DOCUMENT
|
||||
|
||||
def setUp(self):
|
||||
super(DocumentContentViewsTestCase, self).setUp()
|
||||
@@ -42,12 +40,12 @@ class DocumentContentViewsTestCase(GenericDocumentViewTestCase):
|
||||
response = self._request_document_content_view()
|
||||
|
||||
self.assertContains(
|
||||
response, 'Mayan EDMS Documentation', status_code=200
|
||||
response=response, text=TEST_DOCUMENT_CONTENT, status_code=200
|
||||
)
|
||||
|
||||
def _request_document_page_content_view(self):
|
||||
return self.get(
|
||||
'document_parsing:document_page_content', args=(
|
||||
viewname='document_parsing:document_page_content', args=(
|
||||
self.document.pages.first().pk,
|
||||
)
|
||||
)
|
||||
@@ -64,7 +62,7 @@ class DocumentContentViewsTestCase(GenericDocumentViewTestCase):
|
||||
response = self._request_document_page_content_view()
|
||||
|
||||
self.assertContains(
|
||||
response, 'Mayan EDMS Documentation', status_code=200
|
||||
response=response, text=TEST_DOCUMENT_CONTENT, status_code=200
|
||||
)
|
||||
|
||||
def _request_document_content_download_view(self):
|
||||
@@ -87,7 +85,7 @@ class DocumentContentViewsTestCase(GenericDocumentViewTestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self.assert_download_response(
|
||||
response, content=(
|
||||
response=response, content=(
|
||||
''.join(get_document_content(document=self.document))
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user