From e17bc416b89ea93f48f56c060f8be530cca6ef67 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 7 Jul 2015 02:59:45 -0400 Subject: [PATCH] Tests updates. --- mayan/apps/document_signatures/tests.py | 13 ++------- mayan/apps/dynamic_search/tests.py | 38 +++++++------------------ mayan/apps/ocr/tests.py | 10 +++++-- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/mayan/apps/document_signatures/tests.py b/mayan/apps/document_signatures/tests.py index e39a922597..501c75996e 100644 --- a/mayan/apps/document_signatures/tests.py +++ b/mayan/apps/document_signatures/tests.py @@ -27,7 +27,7 @@ class DocumentTestCase(TestCase): ocr_settings.save() with open(TEST_DOCUMENT_PATH) as file_object: - self.document = self.document_type.new_document(file_object=File(file_object, name='mayan_11_1.pdf')) + self.document = self.document_type.new_document(file_object=File(file_object), label='mayan_11_1.pdf') with open(TEST_KEY_FILE) as file_object: gpg.import_key(file_object.read()) @@ -37,21 +37,14 @@ class DocumentTestCase(TestCase): def test_new_document_version_signed(self): with open(TEST_SIGNED_DOCUMENT_PATH) as file_object: - new_version_data = { - 'comment': 'test comment 1', - } - - self.document.new_version(file_object=File(file_object, name='mayan_11_1.pdf.gpg'), **new_version_data) + self.document.new_version(file_object=File(file_object), comment='test comment 1') self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document.latest_version), False) self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document.latest_version).status, SIGNATURE_STATE_VALID) def test_detached_signatures(self): - new_version_data = { - 'comment': 'test comment 2', - } with open(TEST_DOCUMENT_PATH) as file_object: - self.document.new_version(file_object=File(file_object), **new_version_data) + self.document.new_version(file_object=File(file_object), comment='test comment 2') # GPGVerificationError self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document.latest_version), None) diff --git a/mayan/apps/dynamic_search/tests.py b/mayan/apps/dynamic_search/tests.py index e09ec52140..3fa0752da0 100644 --- a/mayan/apps/dynamic_search/tests.py +++ b/mayan/apps/dynamic_search/tests.py @@ -7,30 +7,20 @@ from django.test.client import Client from django.test import TestCase from documents.models import Document, DocumentType +from documents.search import document_search from documents.tests import ( TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL, TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH ) -from .classes import SearchModel - -document_search = SearchModel.get('documents.Document') - class DocumentSearchTestCase(TestCase): def setUp(self): self.admin_user = User.objects.create_superuser(username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD) + self.document_type = DocumentType.objects.create(name=TEST_DOCUMENT_TYPE) - self.document_type = DocumentType(name=TEST_DOCUMENT_TYPE) - self.document_type.save() - - self.document = Document( - document_type=self.document_type, - ) - self.document.save() - - with open(TEST_DOCUMENT_PATH) as file_object: - self.document.new_version(file_object=File(file_object, name='mayan_11_1.pdf')) + with open(TEST_SMALL_DOCUMENT_PATH) as file_object: + self.document = self.document_type.new_document(file_object=File(file_object), label='mayan_11_1.pdf') def test_simple_search_after_related_name_change(self): """ @@ -40,24 +30,18 @@ class DocumentSearchTestCase(TestCase): model_list, result_set, elapsed_time = document_search.search({'q': 'Mayan'}, user=self.admin_user) self.assertEqual(len(result_set), 1) - self.assertEqual(model_list, [self.document]) + self.assertEqual(list(model_list), [self.document]) def test_advanced_search_after_related_name_change(self): # Test versions__filename model_list, result_set, elapsed_time = document_search.search({'label': self.document.label}, user=self.admin_user) self.assertEqual(len(result_set), 1) - self.assertEqual(model_list, [self.document]) + self.assertEqual(list(model_list), [self.document]) # Test versions__mimetype model_list, result_set, elapsed_time = document_search.search({'versions__mimetype': self.document.file_mimetype}, user=self.admin_user) self.assertEqual(len(result_set), 1) - self.assertEqual(model_list, [self.document]) - - # Test versions__pages__content - # Search by the first 20 characters of the content of the first page of the uploaded document - model_list, result_set, elapsed_time = document_search.search({'versions__pages__content': self.document.latest_version.pages.all()[0].content[0:20]}, user=self.admin_user) - self.assertEqual(len(result_set), 1) - self.assertEqual(model_list, [self.document]) + self.assertEqual(list(model_list), [self.document]) def tearDown(self): self.document.delete() @@ -84,22 +68,20 @@ class Issue46TestCase(TestCase): # Upload 30 instances of the same test document for i in range(self.document_count): with open(TEST_SMALL_DOCUMENT_PATH) as file_object: - Document.objects.new_document( + self.document_type.new_document( file_object=File(file_object), label='test document', - document_type=self.document_type ) def test_advanced_search_past_first_page(self): - # Make sure all documents are returned by the search model_list, result_set, elapsed_time = document_search.search({'label': 'test document'}, user=self.admin_user) self.assertEqual(len(result_set), self.document_count) # Funcitonal test for the first page of advanced results response = self.client.get(reverse('search:results'), {'label': 'test'}) - self.assertContains(response, 'esults (1 - 20 out of 30) (Page 1 of 2)', status_code=200) + self.assertContains(response, 'Total (1 - 20 out of 30) (Page 1 of 2)', status_code=200) # Functional test for the second page of advanced results response = self.client.get(reverse('search:results'), {'label': 'test', 'page': 2}) - self.assertContains(response, 'esults (21 - 30 out of 30) (Page 2 of 2)', status_code=200) + self.assertContains(response, 'Total (21 - 30 out of 30) (Page 2 of 2)', status_code=200) diff --git a/mayan/apps/ocr/tests.py b/mayan/apps/ocr/tests.py index 04a1579718..4ca888d5d0 100644 --- a/mayan/apps/ocr/tests.py +++ b/mayan/apps/ocr/tests.py @@ -9,10 +9,14 @@ from documents.tests import TEST_SMALL_DOCUMENT_PATH, TEST_DOCUMENT_TYPE class DocumentOCRTestCase(TransactionTestCase): def setUp(self): - self.document_type = DocumentType.objects.create(name=TEST_DOCUMENT_TYPE, ocr=False) + self.document_type = DocumentType.objects.create(name=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 = Document.objects.new_document(file_object=File(file_object), document_type=self.document_type)[0].document + self.document = self.document_type.new_document(file_object=File(file_object)) def _test_ocr_language_issue_16(self, language, result): """ @@ -30,7 +34,7 @@ class DocumentOCRTestCase(TransactionTestCase): self.document.submit_for_ocr() # Make sure content was extracted - self.assertTrue(result in self.document.pages.first().content) + self.assertTrue(result in self.document.pages.first().ocr_content.content) def test_ocr_language_backends_end(self): self._test_ocr_language_issue_16('eng', 'Mayan EDMS')