github.com/tmlbl/deis@v1.0.2/controller/api/tests/__init__.py (about)

     1  
     2  from __future__ import unicode_literals
     3  import logging
     4  import os
     5  
     6  from django.conf import settings
     7  from django.test.client import RequestFactory, Client
     8  from django.test.simple import DjangoTestSuiteRunner
     9  
    10  
    11  # add patch support to built-in django test client
    12  
    13  def construct_patch(self, path, data='',
    14                      content_type='application/octet-stream', **extra):
    15      """Construct a PATCH request."""
    16      return self.generic('PATCH', path, data, content_type, **extra)
    17  
    18  
    19  def send_patch(self, path, data='', content_type='application/octet-stream',
    20                 follow=False, **extra):
    21      """Send a resource to the server using PATCH."""
    22      # FIXME: figure out why we need to reimport Client (otherwise NoneType)
    23      from django.test.client import Client  # @Reimport
    24      response = super(Client, self).patch(
    25          path, data=data, content_type=content_type, **extra)
    26      if follow:
    27          response = self._handle_redirects(response, **extra)
    28      return response
    29  
    30  
    31  RequestFactory.patch = construct_patch
    32  Client.patch = send_patch
    33  
    34  
    35  class SilentDjangoTestSuiteRunner(DjangoTestSuiteRunner):
    36      """Prevents api log messages from cluttering the console during tests."""
    37  
    38      def run_tests(self, test_labels, extra_tests=None, **kwargs):
    39          """Run tests with all but critical log messages disabled."""
    40          # hide any log messages less than critical
    41          logging.disable(logging.CRITICAL)
    42          # also, create the log directory
    43          if not os.path.exists(settings.DEIS_LOG_DIR):
    44              os.makedirs(settings.DEIS_LOG_DIR)
    45          return super(SilentDjangoTestSuiteRunner, self).run_tests(
    46              test_labels, extra_tests, **kwargs)
    47  
    48  
    49  from .test_api_middleware import *  # noqa
    50  from .test_app import *  # noqa
    51  from .test_auth import *  # noqa
    52  from .test_build import *  # noqa
    53  from .test_config import *  # noqa
    54  from .test_domain import *  # noqa
    55  from .test_container import *  # noqa
    56  from .test_hooks import *  # noqa
    57  from .test_key import *  # noqa
    58  from .test_perm import *  # noqa
    59  from .test_release import *  # noqa
    60  from .test_scheduler import *  # noqa