简体   繁体   English

与身份验证设置有关的Django单元测试失败

[英]Django unit testing failures related to authentication settings

In Django, when I run "manage.py test", I get a lot of authentication related failures. 在Django中,当我运行“ manage.py测试”时,遇到了很多与身份验证相关的失败。 Some examples: 一些例子:

FAIL: test_password_change_succeeds -- AssertionError 200 != 302
FAIL: Logout without next_page option renders the default template -- AssertionError 200 != 302

And: 和:

Failed example:
    form.non_field_errors()
Expected:
    [u'This account is inactive.']
Got:
    [u'Please enter correct username and password....']

I've configured settings.py so that Django will accept authentication from Apache2. 我已经配置了settings.py,以便Django可以接受来自Apache2的身份验证。 In settings, MIDDLEWARE_CLASSES includes 'AuthenticationMiddleware' and 'RemoteUserMiddleware', and AUTHENTICATION_BACKENDS includes 'RemoteUserBackend'. 在设置中, MIDDLEWARE_CLASSES包括“ AuthenticationMiddleware”和“ RemoteUserMiddleware”,而AUTHENTICATION_BACKENDS包括“ RemoteUserBackend”。

How do I figure out the problem here? 我如何在这里找出问题?

UPDATE 2 I cleared the test errors by commenting out the setting of AUTHENTICATION_BACKENDS. UPDATE 2我通过注释掉AUTHENTICATION_BACKENDS的设置来清除测试错误。 Now I have to think about the authentication state I need in my test environment, but at least I've cleared this issue. 现在,我必须考虑测试环境中所需的身份验证状态,但至少我已经解决了此问题。

The first update had a reference to a question I've since deleted. 第一次更新引用了我自删除以来的一个问题。

If your authentication only works via Apache, I wouldn't expect it to work in tests - the test runner doesn't use Apache. 如果您的身份验证仅通过Apache起作用,那么我就不会期望它在测试中起作用-测试运行程序不使用Apache。 You will need to set up a dummy account in the normal database authentication framework. 您将需要在普通数据库身份验证框架中设置一个虚拟帐户。

如上所述,注释掉AUTHENTICATION_BACKENDS的设置可以消除测试错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM