开发者

in a brand-new django project, django auth tests fail

I make a brand-new django project and do literally nothing with it except give values to DATABASE_USER, DATABASE_ENGINE, DATABASE_NAME, and DATABASE_PASSWORD, and django auth test fail. How is this even possible?

I also tried adding TEMPLATE_CONTEXT_PROCESSORS as suggested at django: failing tests from django.contrib.auth

Below is verbatim what I typed:

$ django-admin --version
1.1.1
$ python --version
Python 2.5.5
$ django-admin startproject junk
$ cd junk
$ vim settings.py #edit DATABASE_USER, DATABASE_ENGINE, DATABASE_NAME,DATABASE_PASSWORD
$ ./manage.py test
Creating test database...
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Installing index for auth.Permission model
Installing index for auth.Message model
EE..E...EEEEEEE..................
======================================================================
ERROR: test_password_change_fails_with_invalid_old_password (django.contrib.auth.tests.views.ChangePasswordTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 156, in test_password_change_fails_with_invalid_old_password
    'new_password2': 'password1',
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/decorators.py", line 78, in __call__
    return self.view_func(request, *args, **kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 160, in password_change
    }, context_instance=RequestContext(request))
  File "/usr/lib/pymodules/python2.5/django/shortcuts/__init__.py", line 20, in render_to_response
    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 103, in render_to_string
    t = get_template(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_change_form.html

======================================================================
ERROR: test_password_change_fails_with_mismatched_passwords (django.contrib.auth.tests.views.ChangePasswordTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 167, in test_password_change_fails_with_mismatched_passwords
    'new_password2': 'donuts',
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/decorators.py", line 78, in __call__
    return self.view_func(request, *args, **kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 160, in password_change
    }, context_instance=RequestContext(request))
  File "/usr/lib/pymodules/python2.5/django/shortcuts/__init__.py", line 20, in render_to_response
    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 103, in render_to_string
    t = get_template(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_change_form.html

==========开发者_如何学C============================================================
ERROR: Logout without next_page option renders the default template
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 216, in test_logout_default
    response = self.client.get('/logout/')
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 281, in get
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 225, in request
    response = self.handler(environ)
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 69, in __call__
    response = self.get_response(request)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 134, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 165, in handle_uncaught_exception
    callback, param_dict = resolver.resolve500()
  File "/usr/lib/pymodules/python2.5/django/core/urlresolvers.py", line 266, in resolve500
    return self._resolve_special('500')
  File "/usr/lib/pymodules/python2.5/django/core/urlresolvers.py", line 255, in _resolve_special
    callback = getattr(self.urlconf_module, 'handler%s' % view_type)
AttributeError: 'module' object has no attribute 'handler500'

======================================================================
ERROR: test_confirm_complete (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 107, in test_confirm_complete
    url, path = self._test_confirm_start()
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 67, in _test_confirm_start
    response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 99, in password_reset
    form.save(**opts)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/forms.py", line 125, in save
    t = loader.get_template(email_template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_reset_email.html

======================================================================
ERROR: test_confirm_different_passwords (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 122, in test_confirm_different_passwords
    url, path = self._test_confirm_start()
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 67, in _test_confirm_start
    response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 99, in password_reset
    form.save(**opts)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/forms.py", line 125, in save
    t = loader.get_template(email_template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_reset_email.html

======================================================================
ERROR: test_confirm_invalid (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 85, in test_confirm_invalid
    url, path = self._test_confirm_start()
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 67, in _test_confirm_start
    response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 99, in password_reset
    form.save(**opts)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/forms.py", line 125, in save
    t = loader.get_template(email_template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_reset_email.html

======================================================================
ERROR: test_confirm_invalid_post (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 97, in test_confirm_invalid_post
    url, path = self._test_confirm_start()
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 67, in _test_confirm_start
    response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 99, in password_reset
    form.save(**opts)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/forms.py", line 125, in save
    t = loader.get_template(email_template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_reset_email.html

======================================================================
ERROR: test_confirm_valid (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 78, in test_confirm_valid
    url, path = self._test_confirm_start()
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 67, in _test_confirm_start
    response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 99, in password_reset
    form.save(**opts)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/forms.py", line 125, in save
    t = loader.get_template(email_template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_reset_email.html

======================================================================
ERROR: Email is sent if a valid email address is provided for password reset
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 60, in test_email_found
    response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 99, in password_reset
    form.save(**opts)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/forms.py", line 125, in save
    t = loader.get_template(email_template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_reset_email.html

======================================================================
ERROR: Error is raised if the provided email address isn't currently registered
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/tests/views.py", line 52, in test_email_not_found
    response = self.client.get('/password_reset/')
  File "/usr/lib/pymodules/python2.5/django/test/client.py", line 281, in get
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/pymodules/python2.5/django/contrib/auth/views.py", line 105, in password_reset
    }, context_instance=RequestContext(request))
  File "/usr/lib/pymodules/python2.5/django/shortcuts/__init__.py", line 20, in render_to_response
    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 103, in render_to_string
    t = get_template(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 81, in get_template
    source, origin = find_template_source(template_name)
  File "/usr/lib/pymodules/python2.5/django/template/loader.py", line 74, in find_template_source
    raise TemplateDoesNotExist, name
TemplateDoesNotExist: registration/password_reset_form.html

----------------------------------------------------------------------
Ran 33 tests in 3.696s

FAILED (errors=10)
Destroying test database...
$ 

What on earth am I missing?? I haven't even done anything wrong yet and I'm already failing :).


The default action for "manage.py test" is to run all tests for applications listed in your INSTALLED_APPS in settings.py. In this case, you end up running tests for django's auth application. Presumably, they need some data/fixtures perconfigured for the tests to run smoothly. What you want to do instead is run tests for your applications only: "manage.py test MY_APP". See Running Tests for more information.

UPDATE: Unless you're contributing a patch to django, I'm not sure it's necessary to run those tests everytime you run your own. But ... if you want to run the django tests, for whatever reason, the easiest way is the following (I'll use your "junk" project as a blank template).

  1. Make sure "junk" is in your PYTHONPATH and the DB user in the settings has "create database" permissions.
  2. Go to the "tests" directory in django (after unzipping the distributions this should be in the top level directory, e.g. "Django-1.2.1/tests".
  3. Type:

    python runtests.py --settings=junk.settings auth

    Ran 48 tests in 3.538s

    OK


Did you set up your site and set the SITE_ID in your settings to 1? I recall that Django's test suite doesn't work correctly if SITE_ID is not set to 1.


You have to specify at least one path in TEMPLATE_DIRS, then it will work fine. I don't know the reasons for it, maybe it is a bug. I did not elaborate...


So I get the same thing, and when I put django admin in the INSTALLED_APPS, it doesn't fail anymore, because the admin module comes with the missing templates and handlers that the tests were complaining about.

So I guess my suggestion is leave django admin in INSTALLED_APPS, but don't turn it on in urlconf.


Make sure that PYTHONPATH and DJANGO_SETTINGS_MODULE are set before you run manage.py. I like to make a script in my project directory that I can source when I want to run things. I.e.

# cat ./localenv
PYTHONPATH=...
DJANGO_SETTINGS_MODULE=...
# . ./localenv
# python ./manage.py ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜