1

我做了一个全新的 django 项目,除了给 DATABASE_USER、DATABASE_ENGINE、DATABASE_NAME 和 DATABASE_PASSWORD 赋值外,实际上什么也没做,而 django auth 测试失败。这怎么可能?

我还尝试按照django 的建议添加 TEMPLATE_CONTEXT_PROCESSORS: failed tests from django.contrib.auth

以下是我输入的逐字记录:

$ 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

======================================================================
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...
$ 

我到底错过了什么??我什至还没有做错任何事,而且我已经失败了:)。

4

5 回答 5

3

INSTALLED_APPS“manage.py test”的默认操作是为您的in 中列出的应用程序运行所有测试settings.py。在这种情况下,您最终会为 django 的 auth 应用程序运行测试。据推测,他们需要为测试顺利运行配置一些数据/固定装置。您想要做的只是为您的应用程序运行测试:“manage.py test MY_APP”。有关更多信息,请参阅运行测试

更新:除非您为 django 提供补丁,否则我不确定每次运行自己的测试时是否有必要运行这些测试。但是...如果您想运行 django 测试,无论出于何种原因,最简单的方法如下(我将使用您的“垃圾”项目作为空白模板)。

  1. 确保“垃圾”在您的 PYTHONPATH 中,并且设置中的数据库用户具有“创建数据库”权限。
  2. 转到 django 中的“tests”目录(解压缩发行版后,它应该在顶级目录中,例如“Django-1.2.1/tests”。
  3. 类型:

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

    在 3.538 秒内运行 48 次测试

    好的

于 2010-07-17T18:38:00.407 回答
1

您是否设置了站点并将设置SITE_ID中的设置为1SITE_ID我记得如果没有设置Django 的测试套件不能正常工作1

于 2010-07-17T18:49:45.293 回答
1

您必须在 TEMPLATE_DIRS 中至少指定一个路径,然后它才能正常工作。我不知道它的原因,也许它是一个错误。我没有详细说明...

于 2010-07-17T20:23:56.497 回答
0

确保PYTHONPATHDJANGO_SETTINGS_MODULE在运行之前设置manage.py。我喜欢在我的项目目录中创建一个脚本,当我想运行时可以获取它。IE

# cat ./localenv
PYTHONPATH=...
DJANGO_SETTINGS_MODULE=...
# . ./localenv
# python ./manage.py ...
于 2010-07-17T18:51:46.583 回答
0

所以我得到了同样的结果,当我将 django admin 放入 INSTALLED_APPS 时,它不再失败,因为 admin 模块带有测试抱怨的缺失模板和处理程序。

所以我想我的建议是将 django admin 留在 INSTALLED_APPS 中,但不要在 urlconf 中打开它。

于 2010-08-26T20:49:16.017 回答