Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting and setting the current user while testing #56

Open
ShmuelTreiger opened this issue Nov 29, 2021 · 3 comments
Open

Getting and setting the current user while testing #56

ShmuelTreiger opened this issue Nov 29, 2021 · 3 comments

Comments

@ShmuelTreiger
Copy link

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.

@ivan-price-acted
Copy link

+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

@ShmuelTreiger
Copy link
Author

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

@aidanlister
Copy link

Django-CRUM has a testing middleware for inspiration in case anyone adopts this package:
https://django-crum.readthedocs.io/en/latest/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants