开发者

Unit testing with remote authentication

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')

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开发者_StackOverflow] nodename nor servname provided, or not known>

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?

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

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜