From 34c3443cf1757e47a2d096450ec90a68072fc3d1 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 14 Nov 2019 23:02:00 -0400 Subject: [PATCH] Improve tag app test organization Signed-off-by: Roberto Rosario --- mayan/apps/tags/tests/mixins.py | 16 +++++++++++++++ mayan/apps/tags/tests/test_api.py | 4 +++- mayan/apps/tags/tests/test_views.py | 4 +++- mayan/apps/tags/tests/test_widgets.py | 4 +++- mayan/apps/tags/tests/test_wizard_steps.py | 24 ++++++---------------- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/mayan/apps/tags/tests/mixins.py b/mayan/apps/tags/tests/mixins.py index 6190fcd1d2..1bf07cf64d 100644 --- a/mayan/apps/tags/tests/mixins.py +++ b/mayan/apps/tags/tests/mixins.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals +from mayan.apps.documents.tests.literals import TEST_SMALL_DOCUMENT_PATH + from ..models import Tag from .literals import ( @@ -158,3 +160,17 @@ class TagViewTestMixin(object): 'pk': self.test_document.pk } ) + + +class TaggedDocumentUploadViewTestMixin(object): + def _request_upload_interactive_document_create_view(self): + with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object: + return self.post( + viewname='sources:document_upload_interactive', kwargs={ + 'source_id': self.test_source.pk + }, data={ + 'document_type_id': self.test_document_type.pk, + 'source-file': file_object, + 'tags': Tag.objects.values_list('pk', flat=True) + } + ) diff --git a/mayan/apps/tags/tests/test_api.py b/mayan/apps/tags/tests/test_api.py index efc133f4e8..069f480006 100644 --- a/mayan/apps/tags/tests/test_api.py +++ b/mayan/apps/tags/tests/test_api.py @@ -115,7 +115,9 @@ class TagAPIViewTestCase(TagAPIViewTestMixin, TagTestMixin, BaseAPITestCase): self.assertNotEqual(self.test_tag.color, tag_color) -class TagDocumentAPIViewTestCase(DocumentTestMixin, TagAPIViewTestMixin, TagTestMixin, BaseAPITestCase): +class TagDocumentAPIViewTestCase( + DocumentTestMixin, TagAPIViewTestMixin, TagTestMixin, BaseAPITestCase +): auto_upload_document = False def test_tag_document_list_view_no_access(self): diff --git a/mayan/apps/tags/tests/test_views.py b/mayan/apps/tags/tests/test_views.py index 3ef2bf3a22..d6b91c75b2 100644 --- a/mayan/apps/tags/tests/test_views.py +++ b/mayan/apps/tags/tests/test_views.py @@ -120,7 +120,9 @@ class TagViewTestCase(TagTestMixin, TagViewTestMixin, GenericViewTestCase): ) -class TagDocumentViewTestCase(TagTestMixin, TagViewTestMixin, GenericDocumentViewTestCase): +class TagDocumentViewTestCase( + TagTestMixin, TagViewTestMixin, GenericDocumentViewTestCase +): def test_document_tags_list_no_permissions(self): self._create_test_tag() diff --git a/mayan/apps/tags/tests/test_widgets.py b/mayan/apps/tags/tests/test_widgets.py index 659785e452..fc2f7aea60 100644 --- a/mayan/apps/tags/tests/test_widgets.py +++ b/mayan/apps/tags/tests/test_widgets.py @@ -11,7 +11,9 @@ from ..permissions import permission_tag_view from .mixins import TagTestMixin -class DocumentTagHTMLWidgetTestCase(DocumentViewTestMixin, TagTestMixin, GenericDocumentViewTestCase): +class DocumentTagHTMLWidgetTestCase( + DocumentViewTestMixin, TagTestMixin, GenericDocumentViewTestCase +): def test_document_tags_widget_no_permissions(self): self._create_test_tag() diff --git a/mayan/apps/tags/tests/test_wizard_steps.py b/mayan/apps/tags/tests/test_wizard_steps.py index b93a8edf10..443b47236e 100644 --- a/mayan/apps/tags/tests/test_wizard_steps.py +++ b/mayan/apps/tags/tests/test_wizard_steps.py @@ -3,39 +3,27 @@ from __future__ import unicode_literals from mayan.apps.documents.models import Document from mayan.apps.documents.permissions import permission_document_create from mayan.apps.documents.tests.base import GenericDocumentViewTestCase -from mayan.apps.documents.tests.literals import TEST_SMALL_DOCUMENT_PATH from mayan.apps.sources.models import WebFormSource from mayan.apps.sources.tests.literals import ( TEST_SOURCE_LABEL, TEST_SOURCE_UNCOMPRESS_N ) -from ..models import Tag - -from .mixins import TagTestMixin +from .mixins import TagTestMixin, TaggedDocumentUploadViewTestMixin -class TaggedDocumentUploadTestCase(TagTestMixin, GenericDocumentViewTestCase): +class TaggedDocumentUploadViewTestCase( + TaggedDocumentUploadViewTestMixin, TagTestMixin, + GenericDocumentViewTestCase +): auto_upload_document = False def setUp(self): - super(TaggedDocumentUploadTestCase, self).setUp() + super(TaggedDocumentUploadViewTestCase, self).setUp() self.test_source = WebFormSource.objects.create( enabled=True, label=TEST_SOURCE_LABEL, uncompress=TEST_SOURCE_UNCOMPRESS_N ) - def _request_upload_interactive_document_create_view(self): - with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object: - return self.post( - viewname='sources:document_upload_interactive', kwargs={ - 'source_id': self.test_source.pk - }, data={ - 'document_type_id': self.test_document_type.pk, - 'source-file': file_object, - 'tags': Tag.objects.values_list('pk', flat=True) - } - ) - def test_upload_interactive_view_with_access(self): self._create_test_tag()