diff --git a/mayan/apps/common/tests/base.py b/mayan/apps/common/tests/base.py index 086179b17b..5142902ce1 100644 --- a/mayan/apps/common/tests/base.py +++ b/mayan/apps/common/tests/base.py @@ -2,10 +2,10 @@ from __future__ import unicode_literals from django.test import TestCase -from .mixins import OpenFileCheckMixin, TempfileCheckMixin +from .mixins import ContentTypeCheckMixin, OpenFileCheckMixin, TempfileCheckMixin -class BaseTestCase(OpenFileCheckMixin, TempfileCheckMixin, TestCase): +class BaseTestCase(ContentTypeCheckMixin, OpenFileCheckMixin, TempfileCheckMixin, TestCase): """ This is the most basic test case class any test in the project should use. """ diff --git a/mayan/apps/common/tests/mixins.py b/mayan/apps/common/tests/mixins.py index 844585ecef..cd8be439a0 100644 --- a/mayan/apps/common/tests/mixins.py +++ b/mayan/apps/common/tests/mixins.py @@ -7,6 +7,30 @@ import psutil from ..settings import setting_temporary_directory +class ContentTypeCheckMixin(object): + expected_content_type = 'text/html; charset=utf-8' + + def _pre_setup(self): + super(ContentTypeCheckMixin, self)._pre_setup() + test_instance = self + + class CustomClient(self.client_class): + 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 + ) + ) + + return response + + self.client = CustomClient() + + class TempfileCheckMixin(object): def _get_temporary_entries_count(self): return len(os.listdir(setting_temporary_directory.value))