You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
795 B
Python
20 lines
795 B
Python
from src.context import set_request_id, get_request_id, set_user_id, get_user_id
|
|
|
|
def test_request_id_context():
|
|
test_id = "test-request-id-123"
|
|
token = set_request_id(test_id)
|
|
assert get_request_id() == test_id
|
|
# Note: ContextVar is thread/task local, so this works within the same thread
|
|
|
|
def test_user_id_context():
|
|
test_uid = "user-456"
|
|
set_user_id(test_uid)
|
|
assert get_user_id() == test_uid
|
|
|
|
def test_context_default_none():
|
|
# Since we are in a fresh test, these should be None if not set
|
|
# (Actually might depend on if other tests set them, but let's assume isolation)
|
|
# In a real pytest setup, isolation is guaranteed if they were set in other tests
|
|
# because they are ContextVars.
|
|
assert get_request_id() is None or get_request_id() != ""
|