I've got a problem using a login decorator in my django tests. Many tests start with
self.client.login(username='foo', password='bar')
So, the login works in principle; But now I like to refactor this line of code into a decorator login, just for fun:
def login(fn):
def wrapper(self):
self.client.login(username='foo', password='bar')
return fn(self)
return wrapper
But the then failing tests show me that the user 'foo' is not logged in even self.client.login returns True.
One more mysterious thing is, when I now leave self.client.login from the decorator such that the decorator does nothing but wrapping, a normal login from within the decorated test method is then not possible anymore also!
I think there is some context or scope problem with the test client. Have you any idea what the probem can be? P.S.: The story is all about python2.7 and django-1.3.1.