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

tests: add logged_user context manager #84

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/pypnusershub/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from contextlib import contextmanager

from flask import current_app
from werkzeug.http import dump_cookie
from werkzeug.datastructures import Headers
Expand Down Expand Up @@ -30,6 +32,19 @@ def unset_logged_user(client):
client.environ_base.pop("HTTP_AUTHORIZATION")


@contextmanager
def logged_user(client, user):
"""
Usage:

with logged_user(client, user):
response = client.get(url)
"""
set_logged_user(client, user)
yield
unset_logged_user(client)


# retro compatibility for cookie auth
unset_logged_user_cookie = unset_logged_user

Expand Down