远程认证单元测试 [英] Unit testing with remote authentication

查看:123
本文介绍了远程认证单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一套是我写的,而我的应用程序使用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 设置设置方法,再改回拆卸。这<一个href=\"http://stackoverflow.com/questions/913549/how-to-unit-test-with-different-settings-in-django\">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.

这篇关于远程认证单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆