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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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