Question

I'm testing my views and would like to simulate logged in user with certain permissions.

I know that in django-webtest I can simulate logged in user like this:

self.app.get(reverse('profile'), user='bob')

Can i also pass in a group for this user? Or a list of permissions? If i will create a user in setUp and assign a group to him, can i simulate him logged in by passing his username like this:

self.app.get(reverse('profile'), user='user_with_certain_permissions')

or do i need to log him in first?

Was it helpful?

Solution

Yes, this should work. You may also pass User instance instead of username:

self.app.get(reverse("profile"), self.user_with_certain_permissions)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top