diff --git a/HISTORY.rst b/HISTORY.rst index 73a7181ca5..ac4d722229 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,12 @@ =================== - Auto-import dependecies. No need to use: from .dependencies import * # NOQA +- Add makefile target to run all tests in debug mode. + This mode is more strict and sidesteps a Django bug that + causes errors in the template code that to be silent during + tests. +- Rename expected_content_type to expected_content_types + and allow a list of content types to be specified. 3.2.9 (2019-11-03) diff --git a/mayan/apps/common/tests/mixins.py b/mayan/apps/common/tests/mixins.py index afb9501fde..83013acaf8 100644 --- a/mayan/apps/common/tests/mixins.py +++ b/mayan/apps/common/tests/mixins.py @@ -104,7 +104,7 @@ class ConnectionsCheckTestCaseMixin(object): class ContentTypeCheckTestCaseMixin(object): - expected_content_type = 'text/html; charset=utf-8' + expected_content_types = ('text/html', 'text/html; charset=utf-8') def _pre_setup(self): super(ContentTypeCheckTestCaseMixin, self)._pre_setup() @@ -115,11 +115,11 @@ class ContentTypeCheckTestCaseMixin(object): response = super(CustomClient, self).request(*args, **kwargs) content_type = response._headers.get('content-type', [None, ''])[1] - if test_instance.expected_content_type: - test_instance.assertEqual( - content_type, test_instance.expected_content_type, + if test_instance.expected_content_types: + test_instance.assertTrue( + content_type in test_instance.expected_content_types, msg='Unexpected response content type: {}, expected: {}.'.format( - content_type, test_instance.expected_content_type + content_type, ' or '.join(test_instance.expected_content_types) ) ) diff --git a/mayan/apps/django_gpg/tests/test_views.py b/mayan/apps/django_gpg/tests/test_views.py index 5bc46a0b70..7c2c7f2754 100644 --- a/mayan/apps/django_gpg/tests/test_views.py +++ b/mayan/apps/django_gpg/tests/test_views.py @@ -31,7 +31,7 @@ class KeyViewTestCase(KeyTestMixin, KeyViewTestMixin, GenericViewTestCase): self.assertEqual(response.status_code, 403) def test_key_download_view_with_permission(self): - self.expected_content_type = 'application/octet-stream; charset=utf-8' + self.expected_content_types = ('application/octet-stream; charset=utf-8',) self._create_test_key() diff --git a/mayan/apps/document_parsing/tests/test_views.py b/mayan/apps/document_parsing/tests/test_views.py index e7792dfd70..13856cdadf 100644 --- a/mayan/apps/document_parsing/tests/test_views.py +++ b/mayan/apps/document_parsing/tests/test_views.py @@ -111,7 +111,7 @@ class DocumentContentViewsTestCase( self.assertEqual(response.status_code, 403) def test_download_view_with_access(self): - self.expected_content_type = 'application/octet-stream; charset=utf-8' + self.expected_content_types = ('application/octet-stream; charset=utf-8',) self.grant_access( permission=permission_content_view, obj=self.test_document ) diff --git a/mayan/apps/documents/tests/test_document_views.py b/mayan/apps/documents/tests/test_document_views.py index bd57dc905e..8ade3d7efd 100644 --- a/mayan/apps/documents/tests/test_document_views.py +++ b/mayan/apps/documents/tests/test_document_views.py @@ -186,10 +186,12 @@ class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase) self.assertEqual(response.status_code, 403) def test_document_download_view_with_permission(self): - # Set the expected_content_type for + # Set the expected_content_types for # common.tests.mixins.ContentTypeCheckMixin - self.expected_content_type = '{}; charset=utf-8'.format( - self.test_document.file_mimetype + self.expected_content_types = ( + '{}; charset=utf-8'.format( + self.test_document.file_mimetype + ), ) self.grant_access( @@ -211,10 +213,12 @@ class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase) self.assertEqual(response.status_code, 403) def test_document_multiple_download_view_with_permission(self): - # Set the expected_content_type for + # Set the expected_content_types for # common.tests.mixins.ContentTypeCheckMixin - self.expected_content_type = '{}; charset=utf-8'.format( - self.test_document.file_mimetype + self.expected_content_types = ( + '{}; charset=utf-8'.format( + self.test_document.file_mimetype + ), ) self.grant_access( obj=self.test_document, permission=permission_document_download @@ -235,10 +239,12 @@ class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase) self.assertEqual(response.status_code, 403) def test_document_version_download_view_with_permission(self): - # Set the expected_content_type for + # Set the expected_content_types for # common.tests.mixins.ContentTypeCheckMixin - self.expected_content_type = '{}; charset=utf-8'.format( - self.test_document.latest_version.mimetype + self.expected_content_types = ( + '{}; charset=utf-8'.format( + self.test_document.latest_version.mimetype + ), ) self.grant_access( @@ -258,10 +264,12 @@ class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase) ) def test_document_version_download_preserve_extension_view_with_permission(self): - # Set the expected_content_type for + # Set the expected_content_types for # common.tests.mixins.ContentTypeCheckMixin - self.expected_content_type = '{}; charset=utf-8'.format( - self.test_document.latest_version.mimetype + self.expected_content_types = ( + '{}; charset=utf-8'.format( + self.test_document.latest_version.mimetype + ), ) self.grant_access( diff --git a/mayan/apps/documents/tests/test_events.py b/mayan/apps/documents/tests/test_events.py index 2f9428054b..7f7594356c 100644 --- a/mayan/apps/documents/tests/test_events.py +++ b/mayan/apps/documents/tests/test_events.py @@ -32,7 +32,7 @@ class DocumentEventsTestCase(GenericDocumentViewTestCase): self.assertEqual(list(Action.objects.any(obj=self.test_document)), []) def test_document_download_event_with_permissions(self): - self.expected_content_type = 'image/png; charset=utf-8' + self.expected_content_types = ('image/png; charset=utf-8',) Action.objects.all().delete() diff --git a/mayan/apps/ocr/tests/test_views.py b/mayan/apps/ocr/tests/test_views.py index 49b865189d..2935039a98 100644 --- a/mayan/apps/ocr/tests/test_views.py +++ b/mayan/apps/ocr/tests/test_views.py @@ -173,7 +173,7 @@ class OCRViewsTestCase(OCRViewTestMixin, GenericDocumentViewTestCase): def test_document_ocr_download_view_with_access(self): self.test_document.submit_for_ocr() - self.expected_content_type = 'application/octet-stream; charset=utf-8' + self.expected_content_types = ('application/octet-stream; charset=utf-8',) self.grant_access( obj=self.test_document, permission=permission_ocr_content_view diff --git a/mayan/apps/rest_api/tests/base.py b/mayan/apps/rest_api/tests/base.py index 114549d89e..8f77430952 100644 --- a/mayan/apps/rest_api/tests/base.py +++ b/mayan/apps/rest_api/tests/base.py @@ -11,7 +11,7 @@ class BaseAPITestCase(APITestCase, GenericViewTestCase): """ API test case class that invalidates permissions and smart settings """ - expected_content_type = None + expected_content_types = None def setUp(self): super(BaseAPITestCase, self).setUp()