github.com/jiasir/deis@v1.12.2/controller/api/tests/__init__.py (about)

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