Skip to content

Commit

Permalink
fix test_access_policy_example
Browse files Browse the repository at this point in the history
  • Loading branch information
gwbischof committed Oct 29, 2024
1 parent 23fd04a commit df30433
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
19 changes: 0 additions & 19 deletions databroker/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,3 @@ def delete_dm():
@pytest.fixture(params=['scalar', 'image', 'external_image'])
def detector(request, hw):
return getattr(hw, SIM_DETECTORS[request.param])


@pytest.fixture
def enter_password(monkeypatch):
"""
Return a context manager that overrides getpass, used like:
>>> with enter_password(...):
... # Run code that calls getpass.getpass().
"""

@contextlib.contextmanager
def f(password):
original = getpass.getpass
monkeypatch.setattr("getpass.getpass", lambda: password)
yield
monkeypatch.setattr("getpass.getpass", original)

return f
8 changes: 4 additions & 4 deletions databroker/tests/test_access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from bluesky.plans import count
from tiled.client import Context, from_context
from tiled.server.app import build_app_from_config

from tiled._tests.utils import enter_username_password
from ..mongo_normalized import MongoAdapter, SimpleAccessPolicy


Expand All @@ -22,7 +22,7 @@ def __init__(self, *args, **kwargs):
InstrumentedMongoAdapter.from_mongomock(access_policy=access_policy)


def test_access_policy_example(tmpdir, enter_password):
def test_access_policy_example(tmpdir):

config = {
"authentication": {
Expand Down Expand Up @@ -52,8 +52,8 @@ def test_access_policy_example(tmpdir, enter_password):
],
}
with Context.from_app(build_app_from_config(config), token_cache=tmpdir) as context:
with enter_password("secret"):
client = from_context(context, username="alice", prompt_for_reauthentication=True)
with enter_username_password("alice", "secret"):
client = from_context(context, prompt_for_reauthentication=True)

def post_document(name, doc):
client.post_document(name, doc)
Expand Down

0 comments on commit df30433

Please sign in to comment.