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