自定义用户模型破坏了身份验证测试
Hecko 在那里,
我正在使用一个自定义用户模型,我选择将其称为 Member,它扩展了默认用户模型(与描述的非常相似此处)。
问题在于,这会破坏身份验证应用程序的多个测试,因为测试装置仅创建标准用户,而不是成员。当我将缺少的成员定义/行添加到 django/contrib/auth/fixtures/authtestdata.json 时,它们会再次运行,但这当然不是解决方案。
这是我做错了什么的结果吗?我应该如何最好地解决它?
作为最后的手段,我只是在 Buildout 中添加 authtestdata.json 的补丁,但也许有一个更优雅的解决方案。
非常感谢,
特洛菲
Hecko out there,
I’m using a custom user model that I’ve opted to call Member, which extends the default user model (pretty much as described here).
The rub is that this breaks several tests of the auth app, because the test fixture only creates standard users, not members. When I add the missing member definitions/rows to django/contrib/auth/fixtures/authtestdata.json they run again, but that’s of course no solution.
Is this is a result of me doing something wrong, and how should I best go about fixing it?
As a last recourse, I would just add a patch for authtestdata.json in Buildout, but perhaps there is a more elegant solution.
Thanks a lot,
Telofy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能会从 settings.py 中设置 AUTH_USER_PROFILE 参数中获得一些乐趣,按照
You may get some joy from setting the AUTH_USER_PROFILE parameter in settings.py, as per http://docs.djangoproject.com/en/1.2/topics/auth/#storing-additional-information-about-users. This is a great way of extending the standard User model in a way that Django can work with.
更新:请忽略我下面的帖子。使用原始版本自定义身份验证后端,并在
设置中的
.效果是一样的,而且简单多了。AUTHENTICATION_BACKENDS
中的自定义后端下添加django.contrib.auth.backends.ModelBackend
作为第二个(后备)后端。 py我现在摆脱了补丁,而是扩展了 自定义身份验证后端,我在问题中链接到,如果在成员表(我的自定义用户)中找不到用户,则可以依靠原始身份验证后端的方法。如果发生这种情况,则会发出警告(运行测试时这可能有点烦人)。此外,消息测试会导致很多异常,但它们似乎不会对测试产生任何不利影响。我希望他们是故意的。 ^^
Update: Please disregard my post below. Use the original version of the custom auth backend and add
django.contrib.auth.backends.ModelBackend
as a second (fallback) backend under the custom one inAUTHENTICATION_BACKENDS
in yoursettings.py
. It has the same effect and is much simpler.I now got rid of the patch and instead extended the custom auth backend that I linked to in my question to fall back on the methods of the original auth backend if the user can’t be found in the member table (my custom user). If this happens, a warning is issued (which can be a bit annoying when running the tests). Also, the messages tests cause a lot of exceptions, but they don’t seem to have any adverse effect on the tests. I hope they are intentional. ^^