Skip to content

Commit

Permalink
tests: add logged_user context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Dec 18, 2023
1 parent d8749fe commit 2adb676
Showing 1 changed file with 15 additions and 0 deletions.
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 @@ -26,6 +28,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

0 comments on commit 2adb676

Please sign in to comment.