在一个全新的django项目中,django auth测试失败

在一个全新的django项目中,django auth测试失败,django,django-testing,django-authentication,Django,Django Testing,Django Authentication,我创建了一个全新的django项目,除了给数据库用户、数据库引擎、数据库名称和数据库密码赋值,django身份验证测试失败之外,我什么都不做。这怎么可能呢 我还尝试添加模板\u上下文\u处理器,如在 下面是我逐字输入的内容: $ django-admin --version 1.1.1 $ python --version Python 2.5.5 $ django-admin startproject junk $ cd junk $ vim settings.py #edit DATABAS

我创建了一个全新的django项目,除了给数据库用户、数据库引擎、数据库名称和数据库密码赋值,django身份验证测试失败之外,我什么都不做。这怎么可能呢

我还尝试添加模板\u上下文\u处理器,如在

下面是我逐字输入的内容:

$ 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...
$ 
我到底错过了什么??我甚至还没有做错什么,我已经失败了:)。

manage.py test”的默认操作是为
settings.py中的
已安装的应用程序中列出的所有应用程序运行测试。在本例中,您将为django的auth应用程序运行测试。据推测,他们需要配置一些数据/装置,以便测试顺利运行。您要做的是只为您的应用程序运行测试:“manage.py test MY_APP”。有关更多信息,请参阅

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

  • 确保PYTHONPATH中有“垃圾邮件”,并且设置中的DB用户具有“创建数据库”权限
  • 转到django中的“tests”目录(解压发行版后,这应该在顶层目录中,例如“django-1.2.1/tests”)
  • 类型:

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

    在3.538秒内运行了48个测试

  • “manage.py test”的默认操作是为
    设置.py
    中的
    已安装的应用程序中列出的应用程序运行所有测试。在这种情况下,您将为django的auth应用程序运行测试。他们可能需要配置一些数据/装置,以便测试顺利运行。您要做的是仅为您的应用程序运行测试:“manage.py test MY_APP”。有关更多信息,请参阅

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

  • 确保PYTHONPATH中有“垃圾邮件”,并且设置中的DB用户具有“创建数据库”权限
  • 转到django中的“tests”目录(解压发行版后,这应该在顶层目录中,例如“django-1.2.1/tests”)
  • 类型:

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

    在3.538秒内运行了48个测试


  • 您是否设置了站点并将设置中的
    site\u ID
    设置为
    1
    ?我记得如果
    site\u ID
    未设置为
    1
    ,您是否设置了站点并将设置中的
    site\u ID
    设置为
    1
    ,Django的测试套件无法正常工作?我记得Django的测试套件没有设置如果
    SITE\u ID
    未设置为
    1

    请确保在运行
    manage.py
    之前设置了
    PYTHONPATH
    DJANGO\u设置\u模块
    。我喜欢在我的项目目录中创建一个脚本,当我想运行东西时可以从中获取它

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

    在运行
    manage.py
    之前,请确保设置了
    PYTHONPATH
    DJANGO\u SETTINGS\u MODULE
    。我喜欢在我的项目目录中创建一个脚本,以便在我想运行东西时可以生成它

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

    你必须在模板目录中至少指定一条路径,然后它就会正常工作。我不知道原因,可能是一个bug。我没有详细说明…

    你必须在模板目录中至少指定一条路径,然后它就会正常工作。我不知道原因,可能是一个bug。我没有详细说明…

    所以我得到了同样的结果,当我将django admin放入已安装的应用程序中时,它不会再失败,因为admin模块附带了测试所抱怨的缺少的模板和处理程序


    因此,我想我的建议是将django admin保留在已安装的应用程序中,但不要在urlconf中打开它。

    因此我得到了同样的结果,当我将django admin放置在已安装的应用程序中时,它不会再失败,因为admin模块附带了缺失的模板和处理程序,而测试一直在抱怨这些模板和处理程序


    因此,我想我的建议是将django admin保留在已安装的应用程序中,但不要在urlconf中将其打开。

    SITE\u ID在我的django版本中默认设置为1。SITE\u ID在我的django版本中默认设置为1。但是,那里的身份验证测试不是要运行吗?但是那里的身份验证测试不是要运行吗?为什么需要设置django\u设置模块?不是吗正在读取settings.py文件。请尝试将其取消设置,然后再次运行manage.py。它对我不起作用。这可能不是您遇到的具体问题,但这是一个常见问题,它让我在发布一般解决方案之前多次挠头。希望它会有所帮助。可能不会::-)为什么需要设置DJANGO_SETTINGS_模块?SETTINGS.py文件读取得很好。请尝试取消设置,然后再次运行manage.py。它对我不起作用。这可能不是您遇到的具体问题,但这是一个常见问题,让我在发布一般解决方案之前多次挠头。希望它能有所帮助。可能不是。:-)我在TEMPLATE_DIRS中有一个路径,它们也失败了(使用django 1.4.1和python 2.7)。我在TEMPLATE_DIRS中有一个路径,它们也失败了(使用django 1.4.1和python 2.7)。