From b03758ed8b08ff82e80accfe32bfbb71a9c1a2ab Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 24 Sep 2019 15:37:18 -0400 Subject: [PATCH] Cleanup OCR app code and link registration Signed-off-by: Roberto Rosario --- mayan/apps/ocr/apps.py | 5 +++-- mayan/apps/ocr/managers.py | 2 +- mayan/apps/ocr/tests/test_views.py | 22 +++++++++++++++------- mayan/apps/ocr/views.py | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/mayan/apps/ocr/apps.py b/mayan/apps/ocr/apps.py index e59f3cd90c..1636761ca8 100644 --- a/mayan/apps/ocr/apps.py +++ b/mayan/apps/ocr/apps.py @@ -157,8 +157,9 @@ class OCRApp(MayanAppConfig): link_document_ocr_download, link_document_submit ), sources=( - 'ocr:document_submit', 'ocr:document_ocr_content', - 'ocr:document_ocr_download', 'ocr:document_ocr_error_list' + 'ocr:document_ocr_content_delete', + 'ocr:document_ocr_content', 'ocr:document_ocr_download', + 'ocr:document_ocr_error_list', 'ocr:document_submit', ) ) menu_secondary.bind_links( diff --git a/mayan/apps/ocr/managers.py b/mayan/apps/ocr/managers.py index db0e4ffb26..b456c7bd25 100644 --- a/mayan/apps/ocr/managers.py +++ b/mayan/apps/ocr/managers.py @@ -22,7 +22,7 @@ logger = logging.getLogger(__name__) class DocumentPageOCRContentManager(models.Manager): - def delete_ocr_content_for(self, document, user=None): + def delete_content_for(self, document, user=None): with transaction.atomic(): for document_page in document.pages.all(): self.filter(document_page=document_page).delete() diff --git a/mayan/apps/ocr/tests/test_views.py b/mayan/apps/ocr/tests/test_views.py index 5326797b01..49b865189d 100644 --- a/mayan/apps/ocr/tests/test_views.py +++ b/mayan/apps/ocr/tests/test_views.py @@ -56,12 +56,6 @@ class OCRViewTestMixin(object): } ) - def _request_document_type_ocr_settings_view(self): - return self.get( - viewname='ocr:document_type_ocr_settings', - kwargs={'pk': self.test_document.document_type.pk} - ) - class OCRViewsTestCase(OCRViewTestMixin, GenericDocumentViewTestCase): # PyOCR's leak descriptor in get_available_languages and image_to_string @@ -194,13 +188,27 @@ class OCRViewsTestCase(OCRViewTestMixin, GenericDocumentViewTestCase): ), ) + +class DocumentTypeOCRViewTestMixin(object): + def _request_document_type_ocr_settings_view(self): + return self.get( + viewname='ocr:document_type_ocr_settings', + kwargs={'pk': self.test_document_type.pk} + ) + + +class DocumentTypeOCRViewsTestCase( + DocumentTypeOCRViewTestMixin, GenericDocumentViewTestCase +): + auto_upload_document = False + def test_document_type_ocr_settings_view_no_permission(self): response = self._request_document_type_ocr_settings_view() self.assertEqual(response.status_code, 404) def test_document_type_ocr_settings_view_with_access(self): self.grant_access( - obj=self.test_document.document_type, + obj=self.test_document_type, permission=permission_document_type_ocr_setup ) diff --git a/mayan/apps/ocr/views.py b/mayan/apps/ocr/views.py index 0de2556510..41b978388e 100644 --- a/mayan/apps/ocr/views.py +++ b/mayan/apps/ocr/views.py @@ -46,7 +46,7 @@ class DocumentOCRContentDeleteView(MultipleObjectConfirmActionView): return result def object_action(self, form, instance): - DocumentPageOCRContent.objects.delete_ocr_content_for( + DocumentPageOCRContent.objects.delete_content_for( document=instance, user=self.request.user )