3

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] 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.

Stuart Grimshaw
  • 1,541
  • 1
  • 18
  • 41

1 Answers1

4

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.

Community
  • 1
  • 1
Evan Porter
  • 2,987
  • 3
  • 32
  • 44
  • This does work, but is this really the best way to do it? What's the difference between changing settings from the tests or detecting in your setting what env. you're running in? Either way you're not really testing the code as it runs in production. – Stuart Grimshaw Jun 06 '11 at 00:03
  • If you're testing authentication part, you're correct. If you just want to test the code itself, not the mechanism that protects it, then this might be the solution. – Evan Porter Jun 06 '11 at 03:29
  • That's true, I suppose in that respect it's not too disimilar to using mocks. – Stuart Grimshaw Jun 06 '11 at 08:53