Add SilenceLoggerTestCaseMixin

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-12 03:13:07 -04:00
parent 2b0b9675fd
commit 5118cad9a2
5 changed files with 33 additions and 3 deletions

View File

@@ -26,6 +26,8 @@
* Update Pillow to version 6.0.0
* Update PyYAML to version 5.1. Update use of safe_load and
safe_dump to load and dump using the SafeLoader.
* Add SilenceLoggerTestCaseMixin to lower level of loggers
during tests.
3.1.11 (2019-04-XX)
===================

View File

@@ -50,6 +50,8 @@ Other changes
to the API app's URLs module.
* Update PyYAML to version 5.1. Update use of safe_load and
safe_dump to load and dump using the CSafeLoader and SafeLoader as fallback.
* Add SilenceLoggerTestCaseMixin to lower level of loggers
during tests.
Removals
--------

View File

@@ -12,12 +12,12 @@ from mayan.apps.user_management.tests.mixins import UserTestCaseMixin
from .mixins import (
ClientMethodsTestCaseMixin, ContentTypeCheckTestCaseMixin,
DatabaseConversionMixin, OpenFileCheckTestCaseMixin,
RandomPrimaryKeyModelMonkeyPatchMixin, TempfileCheckTestCasekMixin,
TestViewTestCaseMixin
RandomPrimaryKeyModelMonkeyPatchMixin, SilenceLoggerTestCaseMixin,
TempfileCheckTestCasekMixin, TestViewTestCaseMixin
)
class BaseTestCase(RandomPrimaryKeyModelMonkeyPatchMixin, DatabaseConversionMixin, ACLTestCaseMixin, OpenFileCheckTestCaseMixin, TempfileCheckTestCasekMixin, TestCase):
class BaseTestCase(SilenceLoggerTestCaseMixin, RandomPrimaryKeyModelMonkeyPatchMixin, DatabaseConversionMixin, ACLTestCaseMixin, OpenFileCheckTestCaseMixin, TempfileCheckTestCasekMixin, TestCase):
"""
This is the most basic test case class any test in the project should use.
"""

View File

@@ -2,6 +2,7 @@ from __future__ import unicode_literals
import glob
import importlib
import logging
import os
import random
@@ -209,6 +210,23 @@ class RandomPrimaryKeyModelMonkeyPatchMixin(object):
super(RandomPrimaryKeyModelMonkeyPatchMixin, self).tearDown()
class SilenceLoggerTestCaseMixin(object):
test_case_logger = None
def tearDown(self):
if self.test_case_logger:
self.test_case_logger.setLevel(level=self.test_case_logger_level)
super(SilenceLoggerTestCaseMixin, self).tearDown()
def _silence_logger(self, name):
self.test_case_logger = logging.getLogger(name=name)
self.test_case_logger_level = self.test_case_logger.level
self.test_case_logger.setLevel(
level=logging.CRITICAL
)
class TempfileCheckTestCasekMixin(object):
# Ignore the jvmstat instrumentation and GitLab's CI .config files
# Ignore LibreOffice fontconfig cache dir

View File

@@ -112,6 +112,8 @@ class TransformationBaseTestCase(TestCase):
class TransformationTestCase(GenericDocumentTestCase):
def test_crop_transformation_optional_arguments(self):
self._silence_logger(name='mayan.apps.converter.managers')
document_page = self.document.pages.first()
Transformation.objects.add_for_model(
@@ -122,6 +124,8 @@ class TransformationTestCase(GenericDocumentTestCase):
self.assertTrue(document_page.generate_image().startswith('page'))
def test_crop_transformation_invalid_arguments(self):
self._silence_logger(name='mayan.apps.converter.managers')
document_page = self.document.pages.first()
Transformation.objects.add_for_model(
@@ -132,6 +136,8 @@ class TransformationTestCase(GenericDocumentTestCase):
self.assertTrue(document_page.generate_image().startswith('page'))
def test_crop_transformation_non_valid_range_arguments(self):
self._silence_logger(name='mayan.apps.converter.managers')
document_page = self.document.pages.first()
Transformation.objects.add_for_model(
@@ -142,6 +148,8 @@ class TransformationTestCase(GenericDocumentTestCase):
self.assertTrue(document_page.generate_image().startswith('page'))
def test_crop_transformation_overlapping_ranges_arguments(self):
self._silence_logger(name='mayan.apps.converter.managers')
document_page = self.document.pages.first()
Transformation.objects.add_for_model(