Skip to content

Instantly share code, notes, and snippets.

@klinkin
Created January 2, 2014 22:11
Show Gist options
  • Save klinkin/8228002 to your computer and use it in GitHub Desktop.
Save klinkin/8228002 to your computer and use it in GitHub Desktop.
[email protected]:~/develop/dealer (git: develop) (venv: /dealer) ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
➜ tox
GLOB sdist-make: /Users/marika/Develop/dealer/setup.py
py26 create: /Users/marika/Develop/dealer/.tox/py26
py26 installdeps: pytest, flask, django, mercurial
py26 inst: /Users/marika/Develop/dealer/.tox/dist/dealer-1.0.0.zip
py26 runtests: commands[0] | py.test
========================================================================================== test session starts ===========================================================================================
platform darwin -- Python 2.6.8 -- pytest-2.5.1
collected 9 items
tests/__init__.py ...F.....
================================================================================================ FAILURES ================================================================================================
_________________________________________________________________________________________ DealerTest.test_django _________________________________________________________________________________________
self = <tests.DealerTest testMethod=test_django>
def test_django(self):
from django.conf import settings
settings.configure(
ROOT_URLCONF='tests.django_app.urls',
TEMPLATE_CONTEXT_PROCESSORS = ('dealer.contrib.django.staff.context_processor',), # noqa
MIDDLEWARE_CLASSES = ('dealer.contrib.django.staff.Middleware',),
)
from django.test import Client
client = Client()
> revision = client.get('/revision/')
tests/__init__.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x1058fb1d0>, path = '/revision/', data = {}, follow = False, extra = {}
def get(self, path, data={}, follow=False, **extra):
"""
Requests a response from the server using GET.
"""
> response = super(Client, self).get(path, data=data, **extra)
.tox/py26/lib/python2.6/site-packages/django/test/client.py:473:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x1058fb1d0>, path = '/revision/', data = {}, extra = {}, parsed = ParseResult(scheme='', netloc='', path='/revision/', params='', query='', fragment='')
query_string = '', r = {'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REQUEST_METHOD': 'GET'}
def get(self, path, data={}, **extra):
"Construct a GET request."
parsed = urlparse(path)
query_string = urlencode(data, doseq=True) or force_str(parsed[4])
if six.PY3:
query_string = query_string.encode('utf-8').decode('iso-8859-1')
r = {
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': query_string,
'REQUEST_METHOD': str('GET'),
}
r.update(extra)
> return self.request(**r)
.tox/py26/lib/python2.6/site-packages/django/test/client.py:280:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x1058fb1d0>, request = {'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REQUEST_METHOD': 'GET'}
environ = {'HTTP_COOKIE': '', 'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', ...}, data = {}, on_template_render = <function _curried at 0x1058f46e0>
def request(self, **request):
"""
The master request method. Composes the environment dictionary
and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
using the arguments to the request.
"""
environ = self._base_environ(**request)
# Curry a data dictionary into an instance of the template renderer
# callback function.
data = {}
on_template_render = curry(store_rendered_templates, data)
signals.template_rendered.connect(on_template_render, dispatch_uid="template-render")
# Capture exceptions created by the handler.
got_request_exception.connect(self.store_exc_info, dispatch_uid="request-exception")
try:
try:
> response = self.handler(environ)
.tox/py26/lib/python2.6/site-packages/django/test/client.py:426:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x1058fb610>, environ = {'HTTP_COOKIE': '', 'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', ...}
def __call__(self, environ):
from django.conf import settings
# Set up middleware if needed. We couldn't do this earlier, because
# settings weren't available.
if self._request_middleware is None:
self.load_middleware()
request_started.disconnect(close_old_connections)
request_started.send(sender=self.__class__)
request_started.connect(close_old_connections)
request = WSGIRequest(environ)
# sneaky little hack so that we can easily get round
# CsrfViewMiddleware. This makes life easier, and is probably
# required for backwards compatibility with external tests against
# admin views.
request._dont_enforce_csrf_checks = not self.enforce_csrf_checks
> response = self.get_response(request)
.tox/py26/lib/python2.6/site-packages/django/test/client.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x1058fb610>
request = <WSGIRequest
path:/revision/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKI...'wsgi.run_once': False,
u'wsgi.url_scheme': 'http',
u'wsgi.version': (1, 0)}>
def get_response(self, request):
"Returns an HttpResponse object for the given HttpRequest"
# Setup default url resolver for this thread, this code is outside
# the try/except so we don't get a spurious "unbound local
# variable" exception in the event an exception is raised before
# resolver is set
urlconf = settings.ROOT_URLCONF
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
try:
response = None
# Apply request middleware
for middleware_method in self._request_middleware:
response = middleware_method(request)
if response:
break
if response is None:
if hasattr(request, 'urlconf'):
# Reset url resolver with a custom urlconf.
urlconf = request.urlconf
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
resolver_match = resolver.resolve(request.path_info)
callback, callback_args, callback_kwargs = resolver_match
request.resolver_match = resolver_match
# Apply view middleware
for middleware_method in self._view_middleware:
response = middleware_method(request, callback, callback_args, callback_kwargs)
if response:
break
if response is None:
wrapped_callback = self.make_view_atomic(callback)
try:
response = wrapped_callback(request, *callback_args, **callback_kwargs)
except Exception as e:
# If the view raised an exception, run it through exception
# middleware, and if the exception middleware returns a
# response, use that. Otherwise, reraise the exception.
for middleware_method in self._exception_middleware:
response = middleware_method(request, e)
if response:
break
if response is None:
raise
# Complain if the view returned None (a common error).
if response is None:
if isinstance(callback, types.FunctionType): # FBV
view_name = callback.__name__
else: # CBV
view_name = callback.__class__.__name__ + '.__call__'
raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name))
# If the response supports deferred rendering, apply template
# response middleware and then render the response
if hasattr(response, 'render') and callable(response.render):
for middleware_method in self._template_response_middleware:
response = middleware_method(request, response)
response = response.render()
except http.Http404 as e:
logger.warning('Not Found: %s', request.path,
extra={
'status_code': 404,
'request': request
})
if settings.DEBUG:
response = debug.technical_404_response(request, e)
else:
try:
callback, param_dict = resolver.resolve404()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
except PermissionDenied:
logger.warning(
'Forbidden (Permission denied): %s', request.path,
extra={
'status_code': 403,
'request': request
})
try:
callback, param_dict = resolver.resolve403()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(
sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request,
resolver, sys.exc_info())
except SuspiciousOperation as e:
# The request logger receives events for any problematic request
# The security logger receives events for all SuspiciousOperations
security_logger = logging.getLogger('django.security.%s' %
e.__class__.__name__)
security_logger.error(force_text(e))
try:
callback, param_dict = resolver.resolve400()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(
sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request,
resolver, sys.exc_info())
except SystemExit:
# Allow sys.exit() to actually exit. See tickets #1023 and #4701
raise
except: # Handle everything else.
# Get the exception info now, in case another exception is thrown later.
signals.got_request_exception.send(sender=self.__class__, request=request)
> response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
.tox/py26/lib/python2.6/site-packages/django/core/handlers/base.py:196:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x1058fb610>
request = <WSGIRequest
path:/revision/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKI...'wsgi.run_once': False,
u'wsgi.url_scheme': 'http',
u'wsgi.version': (1, 0)}>
resolver = <RegexURLResolver 'tests.django_app.urls' (None:None) ^/>, exc_info = (<type 'exceptions.ImportError'>, ImportError('No module named defaults',), <traceback object at 0x105af43f8>)
def handle_uncaught_exception(self, request, resolver, exc_info):
"""
Processing for any otherwise uncaught exceptions (those that will
generate HTTP 500 responses). Can be overridden by subclasses who want
customised 500 handling.
Be *very* careful when overriding this because the error could be
caused by anything, so assuming something like the database is always
available would be an error.
"""
if settings.DEBUG_PROPAGATE_EXCEPTIONS:
raise
logger.error('Internal Server Error: %s', request.path,
exc_info=exc_info,
extra={
'status_code': 500,
'request': request
}
)
if settings.DEBUG:
return debug.technical_500_response(request, *exc_info)
# If Http500 handler is not installed, re-raise last exception
> if resolver.urlconf_module is None:
.tox/py26/lib/python2.6/site-packages/django/core/handlers/base.py:234:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <RegexURLResolver 'tests.django_app.urls' (None:None) ^/>
@property
def urlconf_module(self):
try:
return self._urlconf_module
except AttributeError:
> self._urlconf_module = import_module(self.urlconf_name)
.tox/py26/lib/python2.6/site-packages/django/core/urlresolvers.py:341:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
name = 'tests.django_app.urls', package = None
def import_module(name, package=None):
"""Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
"""
if name.startswith('.'):
if not package:
raise TypeError("relative imports require the 'package' argument")
level = 0
for character in name:
if character != '.':
break
level += 1
name = _resolve_name(name[level:], package, level)
> __import__(name)
.tox/py26/lib/python2.6/site-packages/django/utils/importlib.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> from django.conf.urls.defaults import patterns
E ImportError: No module named defaults
tests/django_app/urls.py:1: ImportError
=================================================================================== 1 failed, 8 passed in 0.87 seconds ===================================================================================
ERROR: InvocationError: '/Users/marika/Develop/dealer/.tox/py26/bin/py.test'
py27 create: /Users/marika/Develop/dealer/.tox/py27
py27 installdeps: pytest, flask, django, mercurial
py27 inst: /Users/marika/Develop/dealer/.tox/dist/dealer-1.0.0.zip
py27 runtests: commands[0] | py.test
========================================================================================== test session starts ===========================================================================================
platform darwin -- Python 2.7.5 -- pytest-2.5.1
collected 9 items
tests/__init__.py ...F.....
================================================================================================ FAILURES ================================================================================================
_________________________________________________________________________________________ DealerTest.test_django _________________________________________________________________________________________
self = <tests.DealerTest testMethod=test_django>
def test_django(self):
from django.conf import settings
settings.configure(
ROOT_URLCONF='tests.django_app.urls',
TEMPLATE_CONTEXT_PROCESSORS = ('dealer.contrib.django.staff.context_processor',), # noqa
MIDDLEWARE_CLASSES = ('dealer.contrib.django.staff.Middleware',),
)
from django.test import Client
client = Client()
> revision = client.get('/revision/')
tests/__init__.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x103293e50>, path = '/revision/', data = {}, follow = False, extra = {}
def get(self, path, data={}, follow=False, **extra):
"""
Requests a response from the server using GET.
"""
> response = super(Client, self).get(path, data=data, **extra)
.tox/py27/lib/python2.7/site-packages/django/test/client.py:473:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x103293e50>, path = '/revision/', data = {}, extra = {}, parsed = ParseResult(scheme='', netloc='', path='/revision/', params='', query='', fragment='')
query_string = '', r = {'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REQUEST_METHOD': 'GET'}
def get(self, path, data={}, **extra):
"Construct a GET request."
parsed = urlparse(path)
query_string = urlencode(data, doseq=True) or force_str(parsed[4])
if six.PY3:
query_string = query_string.encode('utf-8').decode('iso-8859-1')
r = {
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': query_string,
'REQUEST_METHOD': str('GET'),
}
r.update(extra)
> return self.request(**r)
.tox/py27/lib/python2.7/site-packages/django/test/client.py:280:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x103293e50>, request = {'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REQUEST_METHOD': 'GET'}
environ = {'HTTP_COOKIE': '', 'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', ...}, data = {}, on_template_render = <function _curried at 0x10348b398>
def request(self, **request):
"""
The master request method. Composes the environment dictionary
and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
using the arguments to the request.
"""
environ = self._base_environ(**request)
# Curry a data dictionary into an instance of the template renderer
# callback function.
data = {}
on_template_render = curry(store_rendered_templates, data)
signals.template_rendered.connect(on_template_render, dispatch_uid="template-render")
# Capture exceptions created by the handler.
got_request_exception.connect(self.store_exc_info, dispatch_uid="request-exception")
try:
try:
> response = self.handler(environ)
.tox/py27/lib/python2.7/site-packages/django/test/client.py:426:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x10329d210>, environ = {'HTTP_COOKIE': '', 'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', ...}
def __call__(self, environ):
from django.conf import settings
# Set up middleware if needed. We couldn't do this earlier, because
# settings weren't available.
if self._request_middleware is None:
self.load_middleware()
request_started.disconnect(close_old_connections)
request_started.send(sender=self.__class__)
request_started.connect(close_old_connections)
request = WSGIRequest(environ)
# sneaky little hack so that we can easily get round
# CsrfViewMiddleware. This makes life easier, and is probably
# required for backwards compatibility with external tests against
# admin views.
request._dont_enforce_csrf_checks = not self.enforce_csrf_checks
> response = self.get_response(request)
.tox/py27/lib/python2.7/site-packages/django/test/client.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x10329d210>
request = <WSGIRequest
path:/revision/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKI...'wsgi.run_once': False,
u'wsgi.url_scheme': 'http',
u'wsgi.version': (1, 0)}>
def get_response(self, request):
"Returns an HttpResponse object for the given HttpRequest"
# Setup default url resolver for this thread, this code is outside
# the try/except so we don't get a spurious "unbound local
# variable" exception in the event an exception is raised before
# resolver is set
urlconf = settings.ROOT_URLCONF
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
try:
response = None
# Apply request middleware
for middleware_method in self._request_middleware:
response = middleware_method(request)
if response:
break
if response is None:
if hasattr(request, 'urlconf'):
# Reset url resolver with a custom urlconf.
urlconf = request.urlconf
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
resolver_match = resolver.resolve(request.path_info)
callback, callback_args, callback_kwargs = resolver_match
request.resolver_match = resolver_match
# Apply view middleware
for middleware_method in self._view_middleware:
response = middleware_method(request, callback, callback_args, callback_kwargs)
if response:
break
if response is None:
wrapped_callback = self.make_view_atomic(callback)
try:
response = wrapped_callback(request, *callback_args, **callback_kwargs)
except Exception as e:
# If the view raised an exception, run it through exception
# middleware, and if the exception middleware returns a
# response, use that. Otherwise, reraise the exception.
for middleware_method in self._exception_middleware:
response = middleware_method(request, e)
if response:
break
if response is None:
raise
# Complain if the view returned None (a common error).
if response is None:
if isinstance(callback, types.FunctionType): # FBV
view_name = callback.__name__
else: # CBV
view_name = callback.__class__.__name__ + '.__call__'
raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name))
# If the response supports deferred rendering, apply template
# response middleware and then render the response
if hasattr(response, 'render') and callable(response.render):
for middleware_method in self._template_response_middleware:
response = middleware_method(request, response)
response = response.render()
except http.Http404 as e:
logger.warning('Not Found: %s', request.path,
extra={
'status_code': 404,
'request': request
})
if settings.DEBUG:
response = debug.technical_404_response(request, e)
else:
try:
callback, param_dict = resolver.resolve404()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
except PermissionDenied:
logger.warning(
'Forbidden (Permission denied): %s', request.path,
extra={
'status_code': 403,
'request': request
})
try:
callback, param_dict = resolver.resolve403()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(
sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request,
resolver, sys.exc_info())
except SuspiciousOperation as e:
# The request logger receives events for any problematic request
# The security logger receives events for all SuspiciousOperations
security_logger = logging.getLogger('django.security.%s' %
e.__class__.__name__)
security_logger.error(force_text(e))
try:
callback, param_dict = resolver.resolve400()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(
sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request,
resolver, sys.exc_info())
except SystemExit:
# Allow sys.exit() to actually exit. See tickets #1023 and #4701
raise
except: # Handle everything else.
# Get the exception info now, in case another exception is thrown later.
signals.got_request_exception.send(sender=self.__class__, request=request)
> response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
.tox/py27/lib/python2.7/site-packages/django/core/handlers/base.py:196:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x10329d210>
request = <WSGIRequest
path:/revision/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKI...'wsgi.run_once': False,
u'wsgi.url_scheme': 'http',
u'wsgi.version': (1, 0)}>
resolver = <RegexURLResolver 'tests.django_app.urls' (None:None) ^/>, exc_info = (<type 'exceptions.ImportError'>, ImportError('No module named defaults',), <traceback object at 0x10348e878>)
def handle_uncaught_exception(self, request, resolver, exc_info):
"""
Processing for any otherwise uncaught exceptions (those that will
generate HTTP 500 responses). Can be overridden by subclasses who want
customised 500 handling.
Be *very* careful when overriding this because the error could be
caused by anything, so assuming something like the database is always
available would be an error.
"""
if settings.DEBUG_PROPAGATE_EXCEPTIONS:
raise
logger.error('Internal Server Error: %s', request.path,
exc_info=exc_info,
extra={
'status_code': 500,
'request': request
}
)
if settings.DEBUG:
return debug.technical_500_response(request, *exc_info)
# If Http500 handler is not installed, re-raise last exception
> if resolver.urlconf_module is None:
.tox/py27/lib/python2.7/site-packages/django/core/handlers/base.py:234:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <RegexURLResolver 'tests.django_app.urls' (None:None) ^/>
@property
def urlconf_module(self):
try:
return self._urlconf_module
except AttributeError:
> self._urlconf_module = import_module(self.urlconf_name)
.tox/py27/lib/python2.7/site-packages/django/core/urlresolvers.py:341:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
name = 'tests.django_app.urls', package = None
def import_module(name, package=None):
"""Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
"""
if name.startswith('.'):
if not package:
raise TypeError("relative imports require the 'package' argument")
level = 0
for character in name:
if character != '.':
break
level += 1
name = _resolve_name(name[level:], package, level)
> __import__(name)
.tox/py27/lib/python2.7/site-packages/django/utils/importlib.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> from django.conf.urls.defaults import patterns
E ImportError: No module named defaults
tests/django_app/urls.py:1: ImportError
=================================================================================== 1 failed, 8 passed in 0.74 seconds ===================================================================================
ERROR: InvocationError: '/Users/marika/Develop/dealer/.tox/py27/bin/py.test'
py33 create: /Users/marika/Develop/dealer/.tox/py33
ERROR: InterpreterNotFound: python3.3
cov create: /Users/marika/Develop/dealer/.tox/cov
cov installdeps: coverage, pytest, flask, django, mercurial
cov inst: /Users/marika/Develop/dealer/.tox/dist/dealer-1.0.0.zip
cov runtests: commands[0] | coverage run --source dealer -m py.test
========================================================================================== test session starts ===========================================================================================
platform darwin -- Python 2.7.5 -- pytest-2.5.1
collected 9 items
tests/__init__.py ...F.....
================================================================================================ FAILURES ================================================================================================
_________________________________________________________________________________________ DealerTest.test_django _________________________________________________________________________________________
self = <tests.DealerTest testMethod=test_django>
def test_django(self):
from django.conf import settings
settings.configure(
ROOT_URLCONF='tests.django_app.urls',
TEMPLATE_CONTEXT_PROCESSORS = ('dealer.contrib.django.staff.context_processor',), # noqa
MIDDLEWARE_CLASSES = ('dealer.contrib.django.staff.Middleware',),
)
from django.test import Client
client = Client()
> revision = client.get('/revision/')
tests/__init__.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x10aee8590>, path = '/revision/', data = {}, follow = False, extra = {}
def get(self, path, data={}, follow=False, **extra):
"""
Requests a response from the server using GET.
"""
> response = super(Client, self).get(path, data=data, **extra)
.tox/cov/lib/python2.7/site-packages/django/test/client.py:473:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x10aee8590>, path = '/revision/', data = {}, extra = {}, parsed = ParseResult(scheme='', netloc='', path='/revision/', params='', query='', fragment='')
query_string = '', r = {'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REQUEST_METHOD': 'GET'}
def get(self, path, data={}, **extra):
"Construct a GET request."
parsed = urlparse(path)
query_string = urlencode(data, doseq=True) or force_str(parsed[4])
if six.PY3:
query_string = query_string.encode('utf-8').decode('iso-8859-1')
r = {
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': query_string,
'REQUEST_METHOD': str('GET'),
}
r.update(extra)
> return self.request(**r)
.tox/cov/lib/python2.7/site-packages/django/test/client.py:280:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.Client object at 0x10aee8590>, request = {'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REQUEST_METHOD': 'GET'}
environ = {'HTTP_COOKIE': '', 'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', ...}, data = {}, on_template_render = <function _curried at 0x10b0c6050>
def request(self, **request):
"""
The master request method. Composes the environment dictionary
and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
using the arguments to the request.
"""
environ = self._base_environ(**request)
# Curry a data dictionary into an instance of the template renderer
# callback function.
data = {}
on_template_render = curry(store_rendered_templates, data)
signals.template_rendered.connect(on_template_render, dispatch_uid="template-render")
# Capture exceptions created by the handler.
got_request_exception.connect(self.store_exc_info, dispatch_uid="request-exception")
try:
try:
> response = self.handler(environ)
.tox/cov/lib/python2.7/site-packages/django/test/client.py:426:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x10aee8910>, environ = {'HTTP_COOKIE': '', 'PATH_INFO': '/revision/', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', ...}
def __call__(self, environ):
from django.conf import settings
# Set up middleware if needed. We couldn't do this earlier, because
# settings weren't available.
if self._request_middleware is None:
self.load_middleware()
request_started.disconnect(close_old_connections)
request_started.send(sender=self.__class__)
request_started.connect(close_old_connections)
request = WSGIRequest(environ)
# sneaky little hack so that we can easily get round
# CsrfViewMiddleware. This makes life easier, and is probably
# required for backwards compatibility with external tests against
# admin views.
request._dont_enforce_csrf_checks = not self.enforce_csrf_checks
> response = self.get_response(request)
.tox/cov/lib/python2.7/site-packages/django/test/client.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x10aee8910>
request = <WSGIRequest
path:/revision/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKI...'wsgi.run_once': False,
u'wsgi.url_scheme': 'http',
u'wsgi.version': (1, 0)}>
def get_response(self, request):
"Returns an HttpResponse object for the given HttpRequest"
# Setup default url resolver for this thread, this code is outside
# the try/except so we don't get a spurious "unbound local
# variable" exception in the event an exception is raised before
# resolver is set
urlconf = settings.ROOT_URLCONF
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
try:
response = None
# Apply request middleware
for middleware_method in self._request_middleware:
response = middleware_method(request)
if response:
break
if response is None:
if hasattr(request, 'urlconf'):
# Reset url resolver with a custom urlconf.
urlconf = request.urlconf
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
resolver_match = resolver.resolve(request.path_info)
callback, callback_args, callback_kwargs = resolver_match
request.resolver_match = resolver_match
# Apply view middleware
for middleware_method in self._view_middleware:
response = middleware_method(request, callback, callback_args, callback_kwargs)
if response:
break
if response is None:
wrapped_callback = self.make_view_atomic(callback)
try:
response = wrapped_callback(request, *callback_args, **callback_kwargs)
except Exception as e:
# If the view raised an exception, run it through exception
# middleware, and if the exception middleware returns a
# response, use that. Otherwise, reraise the exception.
for middleware_method in self._exception_middleware:
response = middleware_method(request, e)
if response:
break
if response is None:
raise
# Complain if the view returned None (a common error).
if response is None:
if isinstance(callback, types.FunctionType): # FBV
view_name = callback.__name__
else: # CBV
view_name = callback.__class__.__name__ + '.__call__'
raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name))
# If the response supports deferred rendering, apply template
# response middleware and then render the response
if hasattr(response, 'render') and callable(response.render):
for middleware_method in self._template_response_middleware:
response = middleware_method(request, response)
response = response.render()
except http.Http404 as e:
logger.warning('Not Found: %s', request.path,
extra={
'status_code': 404,
'request': request
})
if settings.DEBUG:
response = debug.technical_404_response(request, e)
else:
try:
callback, param_dict = resolver.resolve404()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
except PermissionDenied:
logger.warning(
'Forbidden (Permission denied): %s', request.path,
extra={
'status_code': 403,
'request': request
})
try:
callback, param_dict = resolver.resolve403()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(
sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request,
resolver, sys.exc_info())
except SuspiciousOperation as e:
# The request logger receives events for any problematic request
# The security logger receives events for all SuspiciousOperations
security_logger = logging.getLogger('django.security.%s' %
e.__class__.__name__)
security_logger.error(force_text(e))
try:
callback, param_dict = resolver.resolve400()
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(
sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request,
resolver, sys.exc_info())
except SystemExit:
# Allow sys.exit() to actually exit. See tickets #1023 and #4701
raise
except: # Handle everything else.
# Get the exception info now, in case another exception is thrown later.
signals.got_request_exception.send(sender=self.__class__, request=request)
> response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
.tox/cov/lib/python2.7/site-packages/django/core/handlers/base.py:196:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x10aee8910>
request = <WSGIRequest
path:/revision/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKI...'wsgi.run_once': False,
u'wsgi.url_scheme': 'http',
u'wsgi.version': (1, 0)}>
resolver = <RegexURLResolver 'tests.django_app.urls' (None:None) ^/>, exc_info = (<type 'exceptions.ImportError'>, ImportError('No module named defaults',), <traceback object at 0x10b0d0320>)
def handle_uncaught_exception(self, request, resolver, exc_info):
"""
Processing for any otherwise uncaught exceptions (those that will
generate HTTP 500 responses). Can be overridden by subclasses who want
customised 500 handling.
Be *very* careful when overriding this because the error could be
caused by anything, so assuming something like the database is always
available would be an error.
"""
if settings.DEBUG_PROPAGATE_EXCEPTIONS:
raise
logger.error('Internal Server Error: %s', request.path,
exc_info=exc_info,
extra={
'status_code': 500,
'request': request
}
)
if settings.DEBUG:
return debug.technical_500_response(request, *exc_info)
# If Http500 handler is not installed, re-raise last exception
> if resolver.urlconf_module is None:
.tox/cov/lib/python2.7/site-packages/django/core/handlers/base.py:234:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <RegexURLResolver 'tests.django_app.urls' (None:None) ^/>
@property
def urlconf_module(self):
try:
return self._urlconf_module
except AttributeError:
> self._urlconf_module = import_module(self.urlconf_name)
.tox/cov/lib/python2.7/site-packages/django/core/urlresolvers.py:341:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
name = 'tests.django_app.urls', package = None
def import_module(name, package=None):
"""Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
"""
if name.startswith('.'):
if not package:
raise TypeError("relative imports require the 'package' argument")
level = 0
for character in name:
if character != '.':
break
level += 1
name = _resolve_name(name[level:], package, level)
> __import__(name)
.tox/cov/lib/python2.7/site-packages/django/utils/importlib.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> from django.conf.urls.defaults import patterns
E ImportError: No module named defaults
tests/django_app/urls.py:1: ImportError
=================================================================================== 1 failed, 8 passed in 1.30 seconds ===================================================================================
ERROR: InvocationError: '/Users/marika/Develop/dealer/.tox/cov/bin/coverage run --source dealer -m py.test'
cov runtests: commands[1] | coverage report
Name Stmts Miss Cover
----------------------------------------------------
dealer/__init__ 9 0 100%
dealer/auto 24 1 96%
dealer/base 23 1 96%
dealer/contrib/__init__ 0 0 100%
dealer/contrib/django/__init__ 0 0 100%
dealer/contrib/django/settings 8 0 100%
dealer/contrib/django/staff 7 1 86%
dealer/contrib/flask 24 1 96%
dealer/git 37 3 92%
dealer/mercurial 24 12 50%
dealer/null 9 0 100%
dealer/simple 19 0 100%
----------------------------------------------------
TOTAL 184 19 90%
________________________________________________________________________________________________ summary _________________________________________________________________________________________________
ERROR: py26: commands failed
ERROR: py27: commands failed
ERROR: py33: InterpreterNotFound: python3.3
ERROR: cov: commands failed
[email protected]:~/develop/dealer (git: develop) (venv: /dealer) ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment