diff --git a/mayan/apps/acls/tests/test_models.py b/mayan/apps/acls/tests/test_models.py index ec5b21296a..94164629f5 100644 --- a/mayan/apps/acls/tests/test_models.py +++ b/mayan/apps/acls/tests/test_models.py @@ -4,7 +4,7 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import Group from django.core.exceptions import PermissionDenied from django.core.files import File -from django.test import TestCase +from django.test import TestCase, override_settings from documents.models import Document, DocumentType from documents.permissions import permission_document_view @@ -15,24 +15,17 @@ from permissions.models import Role from ..models import AccessControlList +@override_settings(OCR_AUTO_OCR=False) class PermissionTestCase(TestCase): def setUp(self): self.document_type_1 = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type_1.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - self.document_type_2 = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE + '2' ) - ocr_settings = self.document_type_2.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_SMALL_DOCUMENT_PATH) as file_object: self.document_1 = self.document_type_1.new_document( file_object=File(file_object), label='document 1' diff --git a/mayan/apps/authentication/tests/test_views.py b/mayan/apps/authentication/tests/test_views.py index 4f2def5de2..c4d26c5143 100644 --- a/mayan/apps/authentication/tests/test_views.py +++ b/mayan/apps/authentication/tests/test_views.py @@ -3,11 +3,9 @@ from __future__ import absolute_import, unicode_literals from django.conf import settings from django.contrib.auth.models import User from django.core.urlresolvers import reverse -from django.test import TestCase +from django.test import TestCase, override_settings from django.test.client import Client -from ..settings import setting_login_method - TEST_ADMIN_EMAIL = 'admin@admin.com' TEST_ADMIN_PASSWORD = 'test_admin_password' TEST_ADMIN_USERNAME = 'test_admin' @@ -26,15 +24,15 @@ class UserLoginTestCase(TestCase): ) self.client = Client() + @override_settings(AUTHENTICATION_LOGIN_METHOD='username') def test_normal_behaviour(self): - setting_login_method.value = 'username' response = self.client.get(reverse('documents:document_list')) self.assertRedirects( response, 'http://testserver/authentication/login/' ) + @override_settings(AUTHENTICATION_LOGIN_METHOD='username') def test_username_login(self): - setting_login_method.value = 'username' logged_in = self.client.login( username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD ) @@ -43,10 +41,9 @@ class UserLoginTestCase(TestCase): # We didn't get redirected to the login URL self.assertEqual(response.status_code, 200) + @override_settings(AUTHENTICATION_LOGIN_METHOD='email') def test_email_login(self): with self.settings(AUTHENTICATION_BACKENDS=(TEST_EMAIL_AUTHENTICATION_BACKEND,)): - setting_login_method.value = 'email' - logged_in = self.client.login( username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD ) @@ -61,8 +58,8 @@ class UserLoginTestCase(TestCase): # We didn't get redirected to the login URL self.assertEqual(response.status_code, 200) + @override_settings(AUTHENTICATION_LOGIN_METHOD='username') def test_username_login_via_views(self): - setting_login_method.value = 'username' response = self.client.get(reverse('documents:document_list')) self.assertRedirects( response, 'http://testserver/authentication/login/' @@ -78,9 +75,9 @@ class UserLoginTestCase(TestCase): # We didn't get redirected to the login URL self.assertEqual(response.status_code, 200) + @override_settings(AUTHENTICATION_LOGIN_METHOD='email') def test_email_login_via_views(self): with self.settings(AUTHENTICATION_BACKENDS=(TEST_EMAIL_AUTHENTICATION_BACKEND,)): - setting_login_method.value = 'email' response = self.client.get(reverse('documents:document_list')) self.assertRedirects( response, 'http://testserver/authentication/login/' diff --git a/mayan/apps/document_indexing/tests/test_models.py b/mayan/apps/document_indexing/tests/test_models.py index 718054c57c..a35417471f 100644 --- a/mayan/apps/document_indexing/tests/test_models.py +++ b/mayan/apps/document_indexing/tests/test_models.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django.core.files.base import File -from django.test import TestCase +from django.test import TestCase, override_settings from documents.models import DocumentType from documents.tests import TEST_SMALL_DOCUMENT_PATH, TEST_DOCUMENT_TYPE @@ -10,16 +10,13 @@ from metadata.models import MetadataType, DocumentTypeMetadataType from ..models import Index, IndexInstanceNode, IndexTemplateNode +@override_settings(OCR_AUTO_OCR=False) class IndexTestCase(TestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_SMALL_DOCUMENT_PATH) as file_object: self.document = self.document_type.new_document( file_object=File(file_object) diff --git a/mayan/apps/document_signatures/tests/test_models.py b/mayan/apps/document_signatures/tests/test_models.py index 1d1878b3b0..c184ffc37f 100644 --- a/mayan/apps/document_signatures/tests/test_models.py +++ b/mayan/apps/document_signatures/tests/test_models.py @@ -4,7 +4,7 @@ import os from django.conf import settings from django.core.files.base import File -from django.test import TestCase +from django.test import TestCase, override_settings from documents.models import DocumentType from documents.tests import TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE @@ -25,16 +25,13 @@ TEST_KEY_FILE = os.path.join( ) +@override_settings(OCR_AUTO_OCR=False) class DocumentTestCase(TestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_DOCUMENT_PATH) as file_object: self.document = self.document_type.new_document( file_object=File(file_object), label='mayan_11_1.pdf' diff --git a/mayan/apps/documents/tests/test_api.py b/mayan/apps/documents/tests/test_api.py index 5cde546ae1..880c9551ea 100644 --- a/mayan/apps/documents/tests/test_api.py +++ b/mayan/apps/documents/tests/test_api.py @@ -7,6 +7,7 @@ from json import loads from django.contrib.auth.models import User from django.core.files import File from django.core.urlresolvers import reverse +from django.test import override_settings from rest_framework import status from rest_framework.test import APITestCase @@ -75,6 +76,7 @@ class DocumentTypeAPITestCase(APITestCase): self.assertEqual(DocumentType.objects.all().count(), 0) +@override_settings(OCR_AUTO_OCR=False) class DocumentAPITestCase(APITestCase): """ Test document API endpoints @@ -92,10 +94,6 @@ class DocumentAPITestCase(APITestCase): label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - def tearDown(self): self.admin_user.delete() self.document_type.delete() diff --git a/mayan/apps/documents/tests/test_models.py b/mayan/apps/documents/tests/test_models.py index 8ee992fea4..61f573c6a7 100644 --- a/mayan/apps/documents/tests/test_models.py +++ b/mayan/apps/documents/tests/test_models.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django.core.files import File -from django.test import TestCase +from django.test import TestCase, override_settings from .literals import ( TEST_DOCUMENT_TYPE, TEST_DOCUMENT_PATH, TEST_MULTI_PAGE_TIFF_PATH, @@ -10,16 +10,13 @@ from .literals import ( from ..models import DeletedDocument, Document, DocumentType +@override_settings(OCR_AUTO_OCR=False) class DocumentTestCase(TestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_DOCUMENT_PATH) as file_object: self.document = self.document_type.new_document( file_object=File(file_object), label='mayan_11_1.pdf' @@ -81,16 +78,13 @@ class DocumentTestCase(TestCase): self.assertEqual(Document.objects.count(), 0) +@override_settings(OCR_AUTO_OCR=False) class OfficeDocumentTestCase(TestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_OFFICE_DOCUMENT_PATH) as file_object: self.document = self.document_type.new_document( file_object=File(file_object) @@ -109,16 +103,13 @@ class OfficeDocumentTestCase(TestCase): self.assertEqual(self.document.page_count, 2) +@override_settings(OCR_AUTO_OCR=False) class MultiPageTiffTestCase(TestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_MULTI_PAGE_TIFF_PATH) as file_object: self.document = self.document_type.new_document( file_object=File(file_object) diff --git a/mayan/apps/documents/tests/test_views.py b/mayan/apps/documents/tests/test_views.py index 005732dc90..e448419d67 100644 --- a/mayan/apps/documents/tests/test_views.py +++ b/mayan/apps/documents/tests/test_views.py @@ -6,7 +6,7 @@ from django.contrib.auth.models import User from django.core.files import File from django.core.urlresolvers import reverse from django.test.client import Client -from django.test import TestCase +from django.test import TestCase, override_settings from .literals import ( TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL, @@ -15,6 +15,7 @@ from .literals import ( from ..models import DeletedDocument, Document, DocumentType +@override_settings(OCR_AUTO_OCR=False) class DocumentsViewsFunctionalTestCase(TestCase): """ Functional tests to make sure all the moving parts after creating a @@ -25,9 +26,6 @@ class DocumentsViewsFunctionalTestCase(TestCase): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() self.admin_user = User.objects.create_superuser( username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, diff --git a/mayan/apps/dynamic_search/tests/test_api.py b/mayan/apps/dynamic_search/tests/test_api.py index e3fd59abb5..d1f937c225 100644 --- a/mayan/apps/dynamic_search/tests/test_api.py +++ b/mayan/apps/dynamic_search/tests/test_api.py @@ -5,6 +5,7 @@ from json import loads from django.contrib.auth.models import User from django.core.files import File from django.core.urlresolvers import reverse +from django.test import override_settings from rest_framework.test import APITestCase @@ -15,6 +16,7 @@ from documents.tests import ( ) +@override_settings(OCR_AUTO_OCR=False) class SearchAPITestCase(APITestCase): """ Test the search API endpoints @@ -36,10 +38,6 @@ class SearchAPITestCase(APITestCase): label=TEST_DOCUMENT_TYPE ) - ocr_settings = document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_SMALL_DOCUMENT_PATH) as file_object: document = document_type.new_document( file_object=File(file_object), diff --git a/mayan/apps/dynamic_search/tests/test_views.py b/mayan/apps/dynamic_search/tests/test_views.py index 5a09793e88..d2b27ac7fa 100644 --- a/mayan/apps/dynamic_search/tests/test_views.py +++ b/mayan/apps/dynamic_search/tests/test_views.py @@ -12,7 +12,6 @@ from documents.tests import ( TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL, TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH ) -from smart_settings import Setting class Issue46TestCase(TestCase): @@ -61,8 +60,6 @@ class Issue46TestCase(TestCase): self.assertEqual(len(result_set), self.document_count) with self.settings(COMMON_PAGINATE_BY=2): - Setting.invalidate_cache() - # Funcitonal test for the first page of advanced results response = self.client.get( reverse('search:results'), {'label': 'test'} diff --git a/mayan/apps/folders/tests/test_api.py b/mayan/apps/folders/tests/test_api.py index 92ef991f1d..21955e638e 100644 --- a/mayan/apps/folders/tests/test_api.py +++ b/mayan/apps/folders/tests/test_api.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django.contrib.auth.models import User from django.core.files import File from django.core.urlresolvers import reverse +from django.test import override_settings from rest_framework.test import APITestCase @@ -67,6 +68,7 @@ class FolderAPITestCase(APITestCase): self.assertEqual(folder.label, TEST_FOLDER_LABEL + ' edited') + @override_settings(OCR_AUTO_OCR=False) def test_folder_add_document(self): folder = Folder.objects.create(label=TEST_FOLDER_LABEL, user=self.admin_user) @@ -74,10 +76,6 @@ class FolderAPITestCase(APITestCase): label=TEST_DOCUMENT_TYPE ) - ocr_settings = document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_SMALL_DOCUMENT_PATH) as file_object: document = document_type.new_document( file_object=File(file_object), @@ -90,6 +88,7 @@ class FolderAPITestCase(APITestCase): self.assertEqual(folder.documents.count(), 1) + @override_settings(OCR_AUTO_OCR=False) def test_folder_remove_document(self): folder = Folder.objects.create(label=TEST_FOLDER_LABEL, user=self.admin_user) @@ -97,10 +96,6 @@ class FolderAPITestCase(APITestCase): label=TEST_DOCUMENT_TYPE ) - ocr_settings = document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_SMALL_DOCUMENT_PATH) as file_object: document = document_type.new_document( file_object=File(file_object), diff --git a/mayan/apps/metadata/tests/test_models.py b/mayan/apps/metadata/tests/test_models.py index ad4e6979c5..932666c419 100644 --- a/mayan/apps/metadata/tests/test_models.py +++ b/mayan/apps/metadata/tests/test_models.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django.core.files.base import File from django.core.exceptions import ValidationError -from django.test import TestCase +from django.test import TestCase, override_settings from documents.models import DocumentType from documents.tests import TEST_SMALL_DOCUMENT_PATH, TEST_DOCUMENT_TYPE @@ -20,6 +20,7 @@ TEST_VALID_DATE = '2001-1-1' TEST_PARSED_VALID_DATE = '2001-01-01' +@override_settings(OCR_AUTO_OCR=False) class MetadataTestCase(TestCase): def setUp(self): self.metadata_type = MetadataType.objects.create( @@ -30,10 +31,6 @@ class MetadataTestCase(TestCase): label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - self.document_type.metadata.create(metadata_type=self.metadata_type) with open(TEST_SMALL_DOCUMENT_PATH) as file_object: diff --git a/mayan/apps/ocr/tests/test_parsers.py b/mayan/apps/ocr/tests/test_parsers.py index 5bc84fac63..5cb36aecb4 100644 --- a/mayan/apps/ocr/tests/test_parsers.py +++ b/mayan/apps/ocr/tests/test_parsers.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django.core.files.base import File -from django.test import TestCase +from django.test import TestCase, override_settings from documents.models import DocumentType from documents.tests import ( @@ -10,18 +10,17 @@ from documents.tests import ( from ..classes import TextExtractor from ..parsers import PDFMinerParser, PopplerParser +from ..settings import setting_auto_ocr +@override_settings(OCR_AUTO_OCR=False) class ParserTestCase(TestCase): def setUp(self): + self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_DOCUMENT_PATH) as file_object: self.document = self.document_type.new_document( file_object=File(file_object) @@ -50,16 +49,13 @@ class ParserTestCase(TestCase): ) +@override_settings(OCR_AUTO_OCR=False) class TextExtractorTestCase(TestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_HYBRID_DOCUMENT_PATH) as file_object: self.document = self.document_type.new_document( file_object=File(file_object) diff --git a/mayan/apps/sources/tests/test_models.py b/mayan/apps/sources/tests/test_models.py index 9e72c1c93b..deb1aa1786 100644 --- a/mayan/apps/sources/tests/test_models.py +++ b/mayan/apps/sources/tests/test_models.py @@ -5,7 +5,7 @@ import tempfile from django.contrib.auth.models import User from django.core.files.base import File -from django.test import TestCase +from django.test import TestCase, override_settings from django.test.client import Client from documents.models import Document, DocumentType @@ -20,6 +20,7 @@ from ..literals import SOURCE_UNCOMPRESS_CHOICE_Y from ..models import WatchFolderSource, WebFormSource +@override_settings(OCR_AUTO_OCR=False) class UploadDocumentTestCase(TestCase): """ Test creating documents @@ -29,9 +30,6 @@ class UploadDocumentTestCase(TestCase): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() self.admin_user = User.objects.create_superuser( username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, @@ -92,16 +90,13 @@ class UploadDocumentTestCase(TestCase): shutil.rmtree(temporary_directory) +@override_settings(OCR_AUTO_OCR=False) class CompressedUploadsTestCase(TestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - def tearDown(self): self.document_type.delete() diff --git a/mayan/apps/sources/tests/test_views.py b/mayan/apps/sources/tests/test_views.py index 7c3bc53e7b..646ed08f01 100644 --- a/mayan/apps/sources/tests/test_views.py +++ b/mayan/apps/sources/tests/test_views.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test.client import Client -from django.test import TestCase +from django.test import TestCase, override_settings from documents.models import Document, DocumentType from documents.tests import ( @@ -15,6 +15,7 @@ from sources.literals import SOURCE_CHOICE_WEB_FORM from sources.models import WebFormSource +@override_settings(OCR_AUTO_OCR=False) class UploadDocumentTestCase(TestCase): """ Test creating documents @@ -24,9 +25,6 @@ class UploadDocumentTestCase(TestCase): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() self.admin_user = User.objects.create_superuser( username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, diff --git a/mayan/apps/tags/tests/test_api.py b/mayan/apps/tags/tests/test_api.py index f0aef0ae41..0e21e12fd0 100644 --- a/mayan/apps/tags/tests/test_api.py +++ b/mayan/apps/tags/tests/test_api.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django.contrib.auth.models import User from django.core.files import File from django.core.urlresolvers import reverse +from django.test import override_settings from rest_framework.test import APITestCase @@ -72,6 +73,7 @@ class TagAPITestCase(APITestCase): self.assertEqual(tag.label, TEST_TAG_LABEL_ALTERNATE) self.assertEqual(tag.color, TEST_TAG_COLOR_ALTERNATE) + @override_settings(OCR_AUTO_OCR=False) def test_tag_add_document(self): tag = Tag.objects.create(color=TEST_TAG_COLOR, label=TEST_TAG_LABEL) @@ -79,10 +81,6 @@ class TagAPITestCase(APITestCase): label=TEST_DOCUMENT_TYPE ) - ocr_settings = document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_SMALL_DOCUMENT_PATH) as file_object: document = document_type.new_document( file_object=File(file_object), @@ -95,6 +93,7 @@ class TagAPITestCase(APITestCase): self.assertEqual(tag.documents.count(), 1) + @override_settings(OCR_AUTO_OCR=False) def test_tag_remove_document(self): tag = Tag.objects.create(color=TEST_TAG_COLOR, label=TEST_TAG_LABEL) @@ -102,10 +101,6 @@ class TagAPITestCase(APITestCase): label=TEST_DOCUMENT_TYPE ) - ocr_settings = document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_SMALL_DOCUMENT_PATH) as file_object: document = document_type.new_document( file_object=File(file_object), diff --git a/mayan/apps/tags/tests/test_models.py b/mayan/apps/tags/tests/test_models.py index 84b886c1a8..6f0109259a 100644 --- a/mayan/apps/tags/tests/test_models.py +++ b/mayan/apps/tags/tests/test_models.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django.core.files.base import File -from django.test import TestCase +from django.test import TestCase, override_settings from documents.models import DocumentType from documents.tests import TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE @@ -11,16 +11,13 @@ from ..models import Tag TAG_COLOR = '#FF0000' +@override_settings(OCR_AUTO_OCR=False) class TagTestCase(TestCase): def setUp(self): self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE ) - ocr_settings = self.document_type.ocr_settings - ocr_settings.auto_ocr = False - ocr_settings.save() - with open(TEST_DOCUMENT_PATH) as file_object: self.document = self.document_type.new_document( file_object=File(file_object)