From 5ac1276f25bd9dc3376dfc9105ee3b16ba79770b Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 27 Jun 2016 19:20:42 -0400 Subject: [PATCH] Add base test class that includes unclaimed temporary and file descriptor test mixins. GitLab issue #309. --- mayan/apps/common/tests/__init__.py | 1 + mayan/apps/common/tests/test_views.py | 15 ++++-------- mayan/apps/django_gpg/tests/test_models.py | 5 ++-- mayan/apps/documents/tests/test_models.py | 28 +++++++++++++++++----- mayan/apps/ocr/tests/test_models.py | 12 +++++++--- mayan/apps/ocr/tests/test_parsers.py | 11 ++++++--- 6 files changed, 46 insertions(+), 26 deletions(-) diff --git a/mayan/apps/common/tests/__init__.py b/mayan/apps/common/tests/__init__.py index e69de29bb2..31efe2d653 100644 --- a/mayan/apps/common/tests/__init__.py +++ b/mayan/apps/common/tests/__init__.py @@ -0,0 +1 @@ +from .base import BaseTestCase # NOQA diff --git a/mayan/apps/common/tests/test_views.py b/mayan/apps/common/tests/test_views.py index fdc2bce50d..9541d06436 100644 --- a/mayan/apps/common/tests/test_views.py +++ b/mayan/apps/common/tests/test_views.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, unicode_literals -import os - from django.conf.urls import url from django.contrib.auth import get_user_model from django.contrib.auth.models import Group @@ -18,15 +16,13 @@ from user_management.tests import ( TEST_USER_EMAIL, TEST_USER_USERNAME, TEST_USER_PASSWORD ) -from ..settings import setting_temporary_directory - +from .base import BaseTestCase from .literals import TEST_VIEW_NAME, TEST_VIEW_URL -class GenericViewTestCase(TestCase): +class GenericViewTestCase(BaseTestCase): def setUp(self): - self.temp_items = len(os.listdir(setting_temporary_directory.value)) - + super(GenericViewTestCase, self).setUp() self.has_test_view = False self.admin_user = get_user_model().objects.create_superuser( username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, @@ -50,10 +46,7 @@ class GenericViewTestCase(TestCase): self.client.logout() if self.has_test_view: urlpatterns.pop(0) - - self.assertEqual( - self.temp_items, len(os.listdir(setting_temporary_directory.value)) - ) + super(GenericViewTestCase, self).tearDown() def add_test_view(self, test_object): from mayan.urls import urlpatterns diff --git a/mayan/apps/django_gpg/tests/test_models.py b/mayan/apps/django_gpg/tests/test_models.py index 019fe4ba7c..f98781ddf5 100644 --- a/mayan/apps/django_gpg/tests/test_models.py +++ b/mayan/apps/django_gpg/tests/test_models.py @@ -5,8 +5,7 @@ import StringIO import gnupg import mock -from django.test import TestCase - +from common.tests import BaseTestCase from common.utils import TemporaryFile from ..exceptions import ( @@ -44,7 +43,7 @@ def mock_recv_keys(self, keyserver, *keyids): return ImportResult() -class KeyTestCase(TestCase): +class KeyTestCase(BaseTestCase): def test_key_instance_creation(self): # Creating a Key instance is analogous to importing a key key = Key.objects.create(key_data=TEST_KEY_DATA) diff --git a/mayan/apps/documents/tests/test_models.py b/mayan/apps/documents/tests/test_models.py index c8ec1d737e..ff9983b656 100644 --- a/mayan/apps/documents/tests/test_models.py +++ b/mayan/apps/documents/tests/test_models.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from datetime import timedelta import time +from common.tests import BaseTestCase from django.test import TestCase, override_settings from ..exceptions import NewDocumentVersionNotAllowed @@ -16,8 +17,10 @@ from .literals import ( @override_settings(OCR_AUTO_OCR=False) -class DocumentTestCase(TestCase): +class DocumentTestCase(BaseTestCase): def setUp(self): + super(DocumentTestCase, self).setUp() + self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) @@ -29,6 +32,7 @@ class DocumentTestCase(TestCase): def tearDown(self): self.document_type.delete() + super(DocumentTestCase, self).tearDown() def test_document_creation(self): self.assertEqual(self.document_type.label, TEST_DOCUMENT_TYPE) @@ -135,8 +139,10 @@ class DocumentTestCase(TestCase): @override_settings(OCR_AUTO_OCR=False) -class OfficeDocumentTestCase(TestCase): +class OfficeDocumentTestCase(BaseTestCase): def setUp(self): + super(OfficeDocumentTestCase, self).setUp() + self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) @@ -148,6 +154,7 @@ class OfficeDocumentTestCase(TestCase): def tearDown(self): self.document_type.delete() + super(OfficeDocumentTestCase, self).tearDown() def test_document_creation(self): self.assertEqual(self.document.file_mimetype, 'application/msword') @@ -162,8 +169,9 @@ class OfficeDocumentTestCase(TestCase): @override_settings(OCR_AUTO_OCR=False) -class MultiPageTiffTestCase(TestCase): +class MultiPageTiffTestCase(BaseTestCase): def setUp(self): + super(MultiPageTiffTestCase, self).setUp() self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) @@ -175,6 +183,7 @@ class MultiPageTiffTestCase(TestCase): def tearDown(self): self.document_type.delete() + super(MultiPageTiffTestCase, self).tearDown() def test_document_creation(self): self.assertEqual(self.document.file_mimetype, 'image/tiff') @@ -187,8 +196,9 @@ class MultiPageTiffTestCase(TestCase): @override_settings(OCR_AUTO_OCR=False) -class DocumentVersionTestCase(TestCase): +class DocumentVersionTestCase(BaseTestCase): def setUp(self): + super(DocumentVersionTestCase, self).setUp() self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) @@ -200,6 +210,7 @@ class DocumentVersionTestCase(TestCase): def tearDown(self): self.document_type.delete() + super(DocumentVersionTestCase, self).setUp() def test_add_new_version(self): self.assertEqual(self.document.versions.count(), 1) @@ -236,14 +247,16 @@ class DocumentVersionTestCase(TestCase): @override_settings(OCR_AUTO_OCR=False) -class DocumentManagerTestCase(TestCase): +class DocumentManagerTestCase(BaseTestCase): def setUp(self): + super(DocumentManagerTestCase, self).setUp() self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) def tearDown(self): self.document_type.delete() + super(DocumentManagerTestCase, self).tearDown() def test_document_stubs_deletion(self): document_stub = Document.objects.create( @@ -265,8 +278,10 @@ class DocumentManagerTestCase(TestCase): @override_settings(OCR_AUTO_OCR=False) -class NewVersionBlockTestCase(TestCase): +class NewVersionBlockTestCase(BaseTestCase): def setUp(self): + super(NewVersionBlockTestCase, self).setUp() + self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) @@ -279,6 +294,7 @@ class NewVersionBlockTestCase(TestCase): def tearDown(self): self.document.delete() self.document_type.delete() + super(NewVersionBlockTestCase, self).tearDown() def test_blocking(self): NewVersionBlock.objects.block(document=self.document) diff --git a/mayan/apps/ocr/tests/test_models.py b/mayan/apps/ocr/tests/test_models.py index 39daf68e79..d7a834dbd6 100644 --- a/mayan/apps/ocr/tests/test_models.py +++ b/mayan/apps/ocr/tests/test_models.py @@ -3,8 +3,8 @@ from __future__ import unicode_literals from django.core.files.base import File -from django.test import TestCase +from common.tests import BaseTestCase from documents.models import DocumentType from documents.settings import setting_language_choices from documents.tests import ( @@ -12,8 +12,10 @@ from documents.tests import ( ) -class DocumentOCRTestCase(TestCase): +class DocumentOCRTestCase(BaseTestCase): def setUp(self): + super(DocumentOCRTestCase, self).setUp() + self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) @@ -26,6 +28,7 @@ class DocumentOCRTestCase(TestCase): 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 @@ -33,8 +36,10 @@ class DocumentOCRTestCase(TestCase): self.assertTrue('Mayan EDMS Documentation' in content) -class GermanOCRSupportTestCase(TestCase): +class GermanOCRSupportTestCase(BaseTestCase): def setUp(self): + super(GermanOCRSupportTestCase, self).setUp() + self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) @@ -54,6 +59,7 @@ class GermanOCRSupportTestCase(TestCase): def tearDown(self): self.document_type.delete() + super(GermanOCRSupportTestCase, self).tearDown() def test_ocr_language_backends_end(self): content = self.document.pages.first().ocr_content.content diff --git a/mayan/apps/ocr/tests/test_parsers.py b/mayan/apps/ocr/tests/test_parsers.py index 202f80e70b..a6727c4d0f 100644 --- a/mayan/apps/ocr/tests/test_parsers.py +++ b/mayan/apps/ocr/tests/test_parsers.py @@ -1,9 +1,12 @@ from __future__ import unicode_literals +import psutil + from django.core.files.base import File -from django.test import TestCase, override_settings +from django.test import override_settings from common.settings import setting_temporary_directory +from common.tests import BaseTestCase from documents.models import DocumentType from documents.tests import ( TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE, TEST_HYBRID_DOCUMENT_PATH @@ -14,8 +17,9 @@ from ..parsers import PDFMinerParser, PopplerParser @override_settings(OCR_AUTO_OCR=False) -class ParserTestCase(TestCase): +class ParserTestCase(BaseTestCase): def setUp(self): + super(ParserTestCase, self).setUp() self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) @@ -27,6 +31,7 @@ class ParserTestCase(TestCase): def tearDown(self): self.document_type.delete() + super(ParserTestCase, self).tearDown() def test_pdfminer_parser(self): parser = PDFMinerParser() @@ -48,7 +53,7 @@ class ParserTestCase(TestCase): @override_settings(OCR_AUTO_OCR=False) -class TextExtractorTestCase(TestCase): +class TextExtractorTestCase(BaseTestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE