Skip to content

Commit

Permalink
Update usage for auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Jan 16, 2025
1 parent f550c6d commit a4481df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
21 changes: 21 additions & 0 deletions databroker/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,24 @@ def delete_dm():
@pytest.fixture(params=['scalar', 'image', 'external_image'])
def detector(request, hw):
return getattr(hw, SIM_DETECTORS[request.param])


@pytest.fixture(autouse=True)
def set_tiled_cache_dir():
"""
Use a tmpdir instead of ~/.cache/tiled/tokens
"""
# Do not use tempdir pytest fixture because it would use the same tmpdir
# as the one used by the test, and mix the files up.
# Windows will not remove the directory while the http_response_cache.db
# is still open. It is closed by transport shutdown, but not all tests
# correctly shut down the transport. This is probably related to the
# thread-leaking issue.
# This option was added to TemporaryDirectory in Python 3.10
kwargs = {}
if sys.platform.startswith("win") and sys.version_info >= (3, 10):
kwargs["ignore_cleanup_errors"] = True
with tempfile.TemporaryDirectory(**kwargs) as tmpdir:
os.environ["TILED_CACHE_DIR"] = str(tmpdir)
yield
del os.environ["TILED_CACHE_DIR"]
4 changes: 2 additions & 2 deletions databroker/tests/test_access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def test_access_policy_example(tmpdir):
}
],
}
with Context.from_app(build_app_from_config(config), token_cache=tmpdir) as context:
with Context.from_app(build_app_from_config(config)) as context:
with enter_username_password("alice", "secret"):
client = from_context(context, prompt_for_reauthentication=True)
client = from_context(context)

def post_document(name, doc):
client.post_document(name, doc)
Expand Down
8 changes: 4 additions & 4 deletions databroker/tests/test_validate_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_padding(tmpdir, shape, expected_shape):
)
direct_img.img.name = "img"

with Context.from_app(build_app(adapter), token_cache=tmpdir) as context:
with Context.from_app(build_app(adapter)) as context:
client = from_context(context)

def post_document(name, doc):
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_custom_chunking(tmpdir, chunks, shape, expected_chunks):
)
direct_img.img.name = "img"

with Context.from_app(build_app(adapter), token_cache=tmpdir) as context:
with Context.from_app(build_app(adapter)) as context:
client = from_context(context, "dask")

def post_document(name, doc):
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_validate_shape_exceptions(tmpdir, shape, expected_shape):
)
direct_img.img.name = "img"

with Context.from_app(build_app(adapter), token_cache=tmpdir) as context:
with Context.from_app(build_app(adapter)) as context:
client = from_context(context)

def post_document(name, doc):
Expand All @@ -130,7 +130,7 @@ def custom_validate_shape(key, data, expected_shape):

adapter = MongoAdapter.from_mongomock(validate_shape=custom_validate_shape)

with Context.from_app(build_app(adapter), token_cache=tmpdir) as context:
with Context.from_app(build_app(adapter)) as context:
client = from_context(context)

def post_document(name, doc):
Expand Down

0 comments on commit a4481df

Please sign in to comment.