class DocumentSearchTestCase(unittest.TestCase): def setUp(self): # Start the OCR queue self.default_queue = DocumentQueue.objects.get(name='default') def test_do_document_ocr(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) self.document.save() with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version(file=File(file_object, name='title_page.png')) self.failUnlessEqual(self.default_queue.queuedocument_set.count(), 1) do_document_ocr(self.default_queue.queuedocument_set.all()[0]) self.assertTrue(u'Mayan EDMS' in self.document.pages.all()[0].content) def tearDown(self): self.document.delete() self.document_type.delete()
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(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')) def test_simple_search_after_related_name_change(self): """ Test that simple search works after related_name changes to document versions and document version pages """ 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]) 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]) # 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]) def tearDown(self): self.document.delete() self.document_type.delete()
class DocumentTestCase(unittest.TestCase): def setUp(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) self.document.save() file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf')) new_version = self.document.new_version(file=File(file_object, name='mayan_11_1.pdf')) file_object.close() def test_document_no_signature(self): self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False) def test_new_document_version_signed(self): file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf.gpg')) new_version_data = { 'comment': 'test comment 1', 'version_update': VERSION_UPDATE_MAJOR, 'release_level': RELEASE_LEVEL_FINAL, 'serial': 0, } self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False) # self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID) # TODO: verify_signature is failing, check def test_detached_signatures(self): new_version_data = { 'comment': 'test comment 2', 'version_update': VERSION_UPDATE_MAJOR, 'release_level': RELEASE_LEVEL_FINAL, 'serial': 0, } file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf')) new_version = self.document.new_version(file=File(file_object), **new_version_data) file_object.close() # GPGVerificationError self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document), None) file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf.sig'), 'rb') DocumentVersionSignature.objects.add_detached_signature(self.document, File(file_object)) file_object.close() self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), True) # self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID) # TODO: verify_signature is failing, check def tearDown(self): self.document.delete() self.document_type.delete()
class FolderTestCase(TestCase): def setUp(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) self.document.save() with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version(file=File(file_object, name='nucleos_11_1.pdf')) def test_creation_of_folder(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) self.assertEqual(Folder.objects.all().count(), 1) self.assertEqual(list(Folder.objects.all()), [folder]) folder.delete() def test_addition_of_documents(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) folder.add_document(self.document) self.assertEqual(folder.documents.count(), 1) self.assertEqual(list(folder.documents), [self.document]) folder.delete() def test_addition_and_deletion_of_documents(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) folder.add_document(self.document) self.assertEqual(folder.documents.count(), 1) self.assertEqual(list(folder.documents), [self.document]) folder.remove_document(self.document) self.assertEqual(folder.documents.count(), 0) self.assertEqual(list(folder.documents), []) folder.delete() def tearDown(self): self.document.delete() self.document_type.delete()
class FolderTestCase(TestCase): def setUp(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) self.document.save() with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version(file_object=File(file_object)) def test_creation_of_folder(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) self.assertEqual(Folder.objects.all().count(), 1) self.assertEqual(list(Folder.objects.all()), [folder]) folder.delete() def test_addition_of_documents(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) folder.documents.add(self.document) self.assertEqual(folder.documents.count(), 1) self.assertEqual(list(folder.documents.all()), [self.document]) folder.delete() def test_addition_and_deletion_of_documents(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) folder.documents.add(self.document) self.assertEqual(folder.documents.count(), 1) self.assertEqual(list(folder.documents.all()), [self.document]) folder.documents.remove(self.document) self.assertEqual(folder.documents.count(), 0) self.assertEqual(list(folder.documents.all()), []) folder.delete() def tearDown(self): self.document.delete() self.document_type.delete()
def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None): if not document: document = Document() if document_type: document.document_type = document_type document.save() if metadata_dict_list: save_metadata_list(metadata_dict_list, document, create=True) warnings = update_indexes(document) if user: document.add_as_recent_document_for_user(user) create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user}) else: create_history(HISTORY_DOCUMENT_CREATED, document) else: if use_file_name: filename = None else: filename = filename if filename else document.latest_version.filename if not new_version_data: new_version_data = {} new_version = document.new_version(file=file_object, **new_version_data) if filename: new_version.filename = filename new_version.save() transformations, errors = self.get_transformation_list() new_version.apply_default_transformations(transformations)
class DocumentSearchTestCase(unittest.TestCase): def setUp(self): # Start the OCR queue self.default_queue = DocumentQueue.objects.get(name='default') def test_do_document_ocr(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) self.document.save() file_object = open(os.path.join(settings.SITE_ROOT, 'contrib', 'sample_documents', 'title_page.png')) new_version = self.document.new_version(file=File(file_object, name='title_page.png')) file_object.close() self.failUnlessEqual(self.default_queue.queuedocument_set.count(), 1) do_document_ocr(self.default_queue.queuedocument_set.all()[0]) self.assertTrue(u'Mayan EDMS' in self.document.pages.all()[0].content) def tearDown(self): self.document.delete() self.document_type.delete()
def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None): new_document = not document if not document: document = Document() if document_type: document.document_type = document_type document.save() apply_default_acls(document, user) if user: document.add_as_recent_document_for_user(user) create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user}) else: create_history(HISTORY_DOCUMENT_CREATED, document) else: if use_file_name: filename = None else: filename = filename if filename else document.latest_version.filename if not new_version_data: new_version_data = {} try: new_version = document.new_version(file=file_object, user=user, **new_version_data) except Exception: # Don't leave the database in a broken state # document.delete() transaction.rollback() raise if filename: document.rename(filename) transformations, errors = self.get_transformation_list() new_version.apply_default_transformations(transformations) #TODO: new HISTORY for version updates if metadata_dict_list and new_document: # Only do for new documents save_metadata_list(metadata_dict_list, document, create=True) warnings = update_indexes(document) return 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(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')) def test_simple_search_after_related_name_change(self): """ Test that simple search works after related_name changes to document versions and document version pages """ 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]) 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]) # 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]) def tearDown(self): self.document.delete() self.document_type.delete()
def upload_document(self, file_object, document_type, description=None, label=None, language=None, metadata_dict_list=None, metadata_dictionary=None, tag_ids=None, user=None): """ Upload an individual document """ try: with transaction.atomic(): document = Document( description=description or '', document_type=document_type, label=label or file_object.name, language=language or setting_language.value ) document.save(_user=user) except Exception as exception: logger.critical( 'Unexpected exception while trying to create new document ' '"%s" from source "%s"; %s', label or file_object.name, self, exception ) raise else: try: document_version = document.new_version( file_object=file_object, _user=user, ) if user: document.add_as_recent_document_for_user(user) Transformation.objects.copy( source=self, targets=document_version.pages.all() ) if metadata_dict_list: save_metadata_list( metadata_dict_list, document, create=True ) if metadata_dictionary: set_bulk_metadata( document=document, metadata_dictionary=metadata_dictionary ) if tag_ids: for tag in Tag.objects.filter(pk__in=tag_ids): tag.documents.add(document) except Exception as exception: logger.critical( 'Unexpected exception while trying to create version for ' 'new document "%s" from source "%s"; %s', label or file_object.name, self, exception ) document.delete(to_trash=False) raise
def upload_document(self, file_object, document_type, description=None, label=None, language=None, querystring=None, user=None): """ Upload an individual document """ try: with transaction.atomic(): document = Document(description=description or '', document_type=document_type, label=label or file_object.name, language=language or setting_language.value) document.save(_user=user) except Exception as exception: logger.critical( 'Unexpected exception while trying to create new document ' '"%s" from source "%s"; %s', label or file_object.name, self, exception) raise else: try: document_version = document.new_version( file_object=file_object, _user=user, ) if user: document.add_as_recent_document_for_user(user) Transformation.objects.copy( source=self, targets=document_version.pages.all()) except Exception as exception: logger.critical( 'Unexpected exception while trying to create version for ' 'new document "%s" from source "%s"; %s', label or file_object.name, self, exception, exc_info=True) document.delete(to_trash=False) raise else: WizardStep.post_upload_process(document=document, querystring=querystring) return document
class TagTestCase(TestCase): def setUp(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) self.document.save() with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version(file_object=File(file_object)) def runTest(self): tag = Tag(label='test', color=COLOR_RED) tag.save() self.failUnlessEqual(tag.label, 'test') self.failUnlessEqual(tag.get_color_code(), 'red') def test_addition_and_deletion_of_documents(self): tag = Tag(label='test', color=COLOR_RED) tag.save() tag.documents.add(self.document) self.assertEqual(tag.documents.count(), 1) self.assertEqual(list(tag.documents.all()), [self.document]) tag.documents.remove(self.document) self.assertEqual(tag.documents.count(), 0) self.assertEqual(list(tag.documents.all()), []) tag.delete() def tearDown(self): self.document.delete() self.document_type.delete()
class FolderTestCase(unittest.TestCase): def setUp(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) self.document.save() file_object = open(os.path.join(settings.SITE_ROOT, 'contrib', 'sample_documents', 'mayan_11_1.pdf')) new_version = self.document.new_version(file=File(file_object, name='mayan_11_1.pdf')) file_object.close() def test_creation_of_folder(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) self.assertEqual(Folder.objects.all().count(), 1) self.assertEqual(list(Folder.objects.all()), [folder]) folder.delete() def test_addition_of_documents(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) folder.add_document(self.document) self.assertEqual(folder.documents.count(), 1) self.assertEqual(list(folder.documents), [self.document]) folder.delete() def test_addition_and_deletion_of_documents(self): user = User.objects.all()[0] folder = Folder.objects.create(title='test', user=user) folder.add_document(self.document) self.assertEqual(folder.documents.count(), 1) self.assertEqual(list(folder.documents), [self.document]) folder.remove_document(self.document) self.assertEqual(folder.documents.count(), 0) self.assertEqual(list(folder.documents), []) folder.delete() def tearDown(self): self.document.delete() self.document_type.delete()
class DocumentTestCase(TestCase): def setUp(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) self.document.save() with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version(file=File(file_object, name='mayan_11_1.pdf')) with open(TEST_KEY_FILE) as file_object: gpg.import_key(file_object.read()) def test_document_no_signature(self): self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False) def test_new_document_version_signed(self): with open(TEST_SIGNED_DOCUMENT_PATH) as file_object: new_version_data = { 'comment': 'test comment 1', 'version_update': VERSION_UPDATE_MAJOR, 'release_level': RELEASE_LEVEL_FINAL, 'serial': 0, } self.document.new_version(file=File(file_object, name='mayan_11_1.pdf.gpg'), **new_version_data) self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False) self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID) def test_detached_signatures(self): new_version_data = { 'comment': 'test comment 2', 'version_update': VERSION_UPDATE_MAJOR, 'release_level': RELEASE_LEVEL_FINAL, 'serial': 0, } with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version(file=File(file_object), **new_version_data) # GPGVerificationError self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document), None) with open(TEST_SIGNATURE_FILE_PATH, 'rb') as file_object: DocumentVersionSignature.objects.add_detached_signature(self.document, File(file_object)) self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), True) self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID) def tearDown(self): self.document.delete() self.document_type.delete()
class TagTestCase(TestCase): def setUp(self): self.document_type = DocumentType(name="test doc type") self.document_type.save() self.document = Document(document_type=self.document_type, description="description") self.document.save() with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version(file_object=File(file_object)) def runTest(self): tag = Tag(label="test", color=COLOR_RED) tag.save() self.failUnlessEqual(tag.label, "test") self.failUnlessEqual(tag.get_color_code(), "red") def test_addition_and_deletion_of_documents(self): tag = Tag(label="test", color=COLOR_RED) tag.save() tag.documents.add(self.document) self.assertEqual(tag.documents.count(), 1) self.assertEqual(list(tag.documents.all()), [self.document]) tag.documents.remove(self.document) self.assertEqual(tag.documents.count(), 0) self.assertEqual(list(tag.documents.all()), []) tag.delete() def tearDown(self): self.document.delete() self.document_type.delete()
def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None, description=None): new_document = not document if not document: document = Document() if document_type: document.document_type = document_type if description: document.description = description document.save() apply_default_acls(document, user) if user: document.add_as_recent_document_for_user(user) create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user}) else: create_history(HISTORY_DOCUMENT_CREATED, document) else: if use_file_name: filename = None else: filename = filename if filename else document.latest_version.filename if description: document.description = description document.save() if not new_version_data: new_version_data = {} new_version = document.new_version(file=file_object, user=user, **new_version_data) if filename: document.rename(filename) transformations, errors = self.get_transformation_list() new_version.apply_default_transformations(transformations) # TODO: new HISTORY for version updates if metadata_dict_list and new_document: # Only do for new documents save_metadata_list(metadata_dict_list, document, create=True) warnings = update_indexes(document)
def upload_document(self, file_object, document_type, description=None, label=None, language=None, querystring=None, user=None): """ Upload an individual document """ try: with transaction.atomic(): document = Document( description=description or '', document_type=document_type, label=label or file_object.name, language=language or setting_language.value ) document.save(_user=user) except Exception as exception: logger.critical( 'Unexpected exception while trying to create new document ' '"%s" from source "%s"; %s', label or file_object.name, self, exception ) raise else: try: document_version = document.new_version( file_object=file_object, _user=user, ) if user: document.add_as_recent_document_for_user(user) Transformation.objects.copy( source=self, targets=document_version.pages.all() ) except Exception as exception: logger.critical( 'Unexpected exception while trying to create version for ' 'new document "%s" from source "%s"; %s', label or file_object.name, self, exception, exc_info=True ) document.delete(to_trash=False) raise else: WizardStep.post_upload_process( document=document, querystring=querystring ) return document
class DocumentTestCase(TestCase): def setUp(self): self.document_type = DocumentType(name="test doc type") self.document_type.save() self.document = Document(document_type=self.document_type, description="description") 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_KEY_FILE) as file_object: gpg.import_key(file_object.read()) def test_document_no_signature(self): self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False) 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.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False) self.failUnlessEqual( DocumentVersionSignature.objects.verify_signature(self.document).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) # GPGVerificationError self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document), None) with open(TEST_SIGNATURE_FILE_PATH, "rb") as file_object: DocumentVersionSignature.objects.add_detached_signature(self.document, File(file_object)) self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), True) self.failUnlessEqual( DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID ) def tearDown(self): self.document.delete() self.document_type.delete()
class DocumentSearchTestCase(TestCase): def setUp(self): # Start the OCR queue self.default_queue = DocumentQueue.objects.get(name='default') self.document_type = DocumentType.objects.create(name='test doc type') self.document = Document( document_type=self.document_type, description='description', ) self.document.save() with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version( file=File(file_object, name='title_page.png')) # Clear OCR queue QueueDocument.objects.all().delete() def reload_ocr_runtime(self, language): """ Forces the reloading of the language_backend for different languages """ from ocr.conf import settings from ocr import runtime setattr(settings, 'LANGUAGE', language) reload(runtime) from .runtime import language_backend self.assertEqual( unicode(language_backend.__class__), u"<class 'ocr.lang.{0}.LanguageBackend'>".format(language)) def _test_ocr_language_issue_16(self, language): """ Reusable OCR test for a specific language """ self.reload_ocr_runtime(language) # Clear the document's first page content first_page = self.document.pages.first() first_page.content = '' first_page.save() # Make sure no documents are queued for OCR self.failUnlessEqual(self.default_queue.queuedocument_set.count(), 0) DocumentQueue.objects.queue_document(self.document) # Make sure our document is queued for OCR self.failUnlessEqual(self.default_queue.queuedocument_set.count(), 1) do_document_ocr(self.default_queue.queuedocument_set.first()) # Make sure content was extracted self.assertTrue(u'Mayan EDMS' in self.document.pages.first().content) def test_ocr_language_german(self): self._test_ocr_language_issue_16('deu') def test_ocr_language_english(self): self._test_ocr_language_issue_16('eng') def test_ocr_language_russian(self): self._test_ocr_language_issue_16('rus') def test_ocr_language_spanish(self): self._test_ocr_language_issue_16('spa') def tearDown(self): self.document.delete() self.document_type.delete()
class DocumentSearchTestCase(TestCase): def setUp(self): # Start the OCR queue self.default_queue = DocumentQueue.objects.get(name='default') self.document_type = DocumentType.objects.create(name='test doc type') self.document = Document( document_type=self.document_type, description='description', ) self.document.save() with open(TEST_DOCUMENT_PATH) as file_object: self.document.new_version(file=File(file_object, name='title_page.png')) # Clear OCR queue QueueDocument.objects.all().delete() def reload_ocr_runtime(self, language): """ Forces the reloading of the language_backend for different languages """ from ocr.conf import settings from ocr import runtime setattr(settings, 'LANGUAGE', language) reload(runtime) from .runtime import language_backend self.assertEqual(unicode(language_backend.__class__), u"<class 'ocr.lang.{0}.LanguageBackend'>".format(language)) def _test_ocr_language_issue_16(self, language): """ Reusable OCR test for a specific language """ self.reload_ocr_runtime(language) # Clear the document's first page content first_page = self.document.pages.first() first_page.content = '' first_page.save() # Make sure no documents are queued for OCR self.failUnlessEqual(self.default_queue.queuedocument_set.count(), 0) DocumentQueue.objects.queue_document(self.document) # Make sure our document is queued for OCR self.failUnlessEqual(self.default_queue.queuedocument_set.count(), 1) do_document_ocr(self.default_queue.queuedocument_set.first()) # Make sure content was extracted self.assertTrue(u'nucleos EDMS' in self.document.pages.first().content) def test_ocr_language_german(self): self._test_ocr_language_issue_16('deu') def test_ocr_language_english(self): self._test_ocr_language_issue_16('eng') def test_ocr_language_russian(self): self._test_ocr_language_issue_16('rus') def test_ocr_language_spanish(self): self._test_ocr_language_issue_16('spa') def tearDown(self): self.document.delete() self.document_type.delete()
class DocumentTestCase(TestCase): def setUp(self): self.document_type = DocumentType(name='test doc type') self.document_type.save() self.document = Document( document_type=self.document_type, description='description', ) 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_KEY_FILE) as file_object: gpg.import_key(file_object.read()) def test_document_no_signature(self): self.failUnlessEqual( DocumentVersionSignature.objects.has_detached_signature( self.document), False) 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.failUnlessEqual( DocumentVersionSignature.objects.has_detached_signature( self.document), False) self.failUnlessEqual( DocumentVersionSignature.objects.verify_signature( self.document).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) # GPGVerificationError self.failUnlessEqual( DocumentVersionSignature.objects.verify_signature(self.document), None) with open(TEST_SIGNATURE_FILE_PATH, 'rb') as file_object: DocumentVersionSignature.objects.add_detached_signature( self.document, File(file_object)) self.failUnlessEqual( DocumentVersionSignature.objects.has_detached_signature( self.document), True) self.failUnlessEqual( DocumentVersionSignature.objects.verify_signature( self.document).status, SIGNATURE_STATE_VALID) def tearDown(self): self.document.delete() self.document_type.delete()