远程认证单元测试

编程入门 行业动态 更新时间:2024-10-24 16:25:47
本文介绍了远程认证单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一套是我写的,而我的应用程序使用Django的默认身份验证是测试,但现在我已经加入Atlassian的人群作为身份验证方法,这些测试失败,现在,主要是因为人群服务器是不存在的,当我想从家里跑我的测试。

I have a suite of tests that I wrote while my app was using Django's default authentication, but now I've added Atlassian Crowd as the authentication method and those tests now fail, mainly because the Crowd server isn't there when I want to run my tests from home.

每个应用程序有此在它的设置()方法

Each app has this in it's Setup() method

def setUp(self): """Set up the shared test data.""" self.client.login(username='admin', password='letmein')

我的工作围绕它的那一刻被注释掉AUTHENTICATION_BACKENDS,但不会CI服务器上运行。

I'm working around it at the moment by commenting out the AUTHENTICATION_BACKENDS, but that isn't going to work on the CI server.

我不认为我得到的错误是很重要的,但对于完整性:

I don't think the error I'm getting is important, but for completeness:

URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>

我已经尝试添加这两种身份验证的后端到AUTHENTICATION_BACKENDS,我仍然得到相同的结果。

I've tried adding both auth backends into AUTHENTICATION_BACKENDS and I still get the same results.

我有哪些选择获取这些测试通过?

What are my options for getting these tests to pass?

有没有办法来强制进行登录的用户?我能以某种方式模拟auth对象?

Is there any way to force the user to be logged in? Can I mock the auth object somehow?

我可以把在制定检查它是否在测试模式下运行围绕AUTHENTICATION_BACKENDS部分的一些检查?但当时我正在为我的测试中的特殊情况和那种失败的对象。

Could I put some check around the AUTHENTICATION_BACKENDS section in setting to check if it's running in test mode? but then I'm writing special cases for my tests and that kind of defeats the object.

推荐答案

您可以修改 AUTHENTICATION_BACKENDS 在设置设置方法,再改回拆卸。这question's接受的答案具有只是一个例子,但有不同的设置。

You could change the AUTHENTICATION_BACKENDS setting in the setUp method, then change it back in tearDown. This question's accepted answer has an example just that, but with a different setting.

更多推荐

远程认证单元测试

本文发布于:2023-06-13 09:31:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/678944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!