django-currentuser icon indicating copy to clipboard operation
django-currentuser copied to clipboard

Getting and setting the current user while testing

Open ShmuelTreiger opened this issue 3 years ago • 3 comments

New to using this project, thanks for creating and maintaining it!

While creating tests for myself, I find myself wanting to set the current user. I've finally had success using the internal _set_current_user() method. It would be great if there were an external facing testing toolset to make this easier/more accessible. Happy to make a go at it, if there's interest.

ShmuelTreiger avatar Nov 29 '21 22:11 ShmuelTreiger

+1 @ShmuelTreiger may i suggest a context manager if you decide to implement this, eg.

with current_user('foobar'):
    objects.save()

we have noted that the client.login(user) in pytest 'works' however, so what you describe is only necessary for testing stuff outside of an api request.

-i

ivan-price-acted avatar Dec 31 '21 12:12 ivan-price-acted

Unfortunately, I've moved on from using this project, don't think I'm likely make a patch any time soon. Sorry.

ShmuelTreiger avatar Dec 31 '21 17:12 ShmuelTreiger