From 50d4aa0e228ac9acdc0f8991353be81103f4c54f Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 15 Mar 2019 02:56:34 -0400 Subject: [PATCH] Allow disabling test's expected_content_type Setting expected_content_type to None will now disable the reponse HTTP content type checking. Added to allow API tests to be a subclass of the test view test case and support all the mixins without having to declare them separately. Signed-off-by: Roberto Rosario --- mayan/apps/common/tests/base.py | 4 ++-- mayan/apps/common/tests/mixins.py | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mayan/apps/common/tests/base.py b/mayan/apps/common/tests/base.py index c3c06672c5..28edf1b4a5 100644 --- a/mayan/apps/common/tests/base.py +++ b/mayan/apps/common/tests/base.py @@ -14,7 +14,7 @@ from .mixins import ( ) -class BaseTestCase(RandomPrimaryKeyModelMonkeyPatchMixin, DatabaseConversionMixin, ACLTestCaseMixin, ContentTypeCheckMixin, OpenFileCheckTestCaseMixin, TempfileCheckTestCaseMixin, TestCase): +class BaseTestCase(RandomPrimaryKeyModelMonkeyPatchMixin, DatabaseConversionMixin, ACLTestCaseMixin, OpenFileCheckTestCaseMixin, TempfileCheckTestCaseMixin, TestCase): """ This is the most basic test case class any test in the project should use. """ @@ -26,7 +26,7 @@ class BaseTestCase(RandomPrimaryKeyModelMonkeyPatchMixin, DatabaseConversionMixi Permission.invalidate_cache() -class GenericViewTestCase(ClientMethodsTestCaseMixin, TestViewTestCaseMixin, BaseTestCase): +class GenericViewTestCase(ClientMethodsTestCaseMixin, ContentTypeCheckMixin, TestViewTestCaseMixin, BaseTestCase): """ A generic view test case built on top of the base test case providing a single, user customizable view to test object resolution and shorthand diff --git a/mayan/apps/common/tests/mixins.py b/mayan/apps/common/tests/mixins.py index 9898d38d63..a729e7d280 100644 --- a/mayan/apps/common/tests/mixins.py +++ b/mayan/apps/common/tests/mixins.py @@ -90,13 +90,14 @@ class ContentTypeCheckMixin(object): def request(self, *args, **kwargs): response = super(CustomClient, self).request(*args, **kwargs) - content_type = response._headers['content-type'][1] - test_instance.assertEqual( - content_type, test_instance.expected_content_type, - msg='Unexpected response content type: {}, expected: {}.'.format( - content_type, test_instance.expected_content_type + 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, + msg='Unexpected response content type: {}, expected: {}.'.format( + content_type, test_instance.expected_content_type + ) ) - ) return response