diff --git a/HISTORY.rst b/HISTORY.rst index 256120f78e..105cf2e098 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -131,6 +131,12 @@ - Add the document template sandbox feature. - 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 85d1e674ea..0c611a7639 100644 --- a/mayan/apps/common/tests/mixins.py +++ b/mayan/apps/common/tests/mixins.py @@ -116,7 +116,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() @@ -127,11 +127,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 a7c4c8137f..bda30a6131 100644 --- a/mayan/apps/django_gpg/tests/test_views.py +++ b/mayan/apps/django_gpg/tests/test_views.py @@ -19,7 +19,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_private() diff --git a/mayan/apps/document_parsing/tests/test_views.py b/mayan/apps/document_parsing/tests/test_views.py index bb88c1817b..423a11adcd 100644 --- a/mayan/apps/document_parsing/tests/test_views.py +++ b/mayan/apps/document_parsing/tests/test_views.py @@ -110,7 +110,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/document_signatures/tests/test_views.py b/mayan/apps/document_signatures/tests/test_views.py index 1032e25ef3..814dafbc9c 100644 --- a/mayan/apps/document_signatures/tests/test_views.py +++ b/mayan/apps/document_signatures/tests/test_views.py @@ -306,7 +306,7 @@ class DetachedSignaturesViewTestCase( permission=permission_document_version_signature_download ) - self.expected_content_type = 'application/octet-stream; charset=utf-8' + self.expected_content_types = ('application/octet-stream; charset=utf-8',) response = self._request_test_document_version_signature_download_view() diff --git a/mayan/apps/documents/tests/test_document_views.py b/mayan/apps/documents/tests/test_document_views.py index bb9cc8dbef..4a0a3fed7a 100644 --- a/mayan/apps/documents/tests/test_document_views.py +++ b/mayan/apps/documents/tests/test_document_views.py @@ -187,10 +187,12 @@ class DocumentViewTestCase( 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( @@ -212,10 +214,12 @@ class DocumentViewTestCase( 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 @@ -236,10 +240,12 @@ class DocumentViewTestCase( 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( @@ -259,10 +265,12 @@ class DocumentViewTestCase( ) 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 940f5e3041..cc18d46981 100644 --- a/mayan/apps/documents/tests/test_events.py +++ b/mayan/apps/documents/tests/test_events.py @@ -43,7 +43,7 @@ class DocumentEventsTestCase( 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 6ed278c54a..8e83b43bb6 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 7419688585..8b0493356b 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()