Allow multitle expected_content_types in tests
Some tests return 'text/html' or 'text/html; charset=utf-8' which are essentially the same if they are tested in debug mode. Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -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)
|
||||
==================
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user