Skip to content

Commit

Permalink
Fixtures for WebDAV based tests
Browse files Browse the repository at this point in the history
These replace the old `serve_path_via_webdav` approach. This new
approach is more convenient, and has better test isolation.

Demo follows in next commit.

Ping datalad#295
  • Loading branch information
mih committed Mar 7, 2023
1 parent 49e4953 commit 54a7202
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions datalad_next/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
dataset,
#function-scope, Dataset instance with underlying repository
existing_dataset,
# session-scope, standard webdav credential (full dict)
webdav_credential,
# function-scope, serve a local temp-path via WebDAV
webdav_server,
)
38 changes: 38 additions & 0 deletions datalad_next/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datalad_next.datasets import Dataset
from datalad_next.tests.utils import (
SkipTest,
WebDAVPath,
external_versions,
get_git_config_global_fpath,
md5sum,
Expand Down Expand Up @@ -202,3 +203,40 @@ def existing_dataset(dataset):
"""
dataset.create(result_renderer='disabled')
yield dataset


@pytest.fixture(autouse=False, scope="session")
def webdav_credential():
yield dict(
name='dltest-my&=webdav',
user='datalad',
secret='secure',
type='user_password',
)


@pytest.fixture(autouse=False, scope="function")
def webdav_server(tmp_path_factory, webdav_credential):
"""Provides a WebDAV server, serving a temporary directory
The fixtures yields an instance of ``WebDAVPath``, provides the
following essential attributes:
- ``path``: ``Path`` instance of the served temporary directory
- ``url``: HTTP URL to access the WebDAV server
Server access requires HTTP Basic authentication with the credential
provided by the ``webdav_credential`` fixture.
"""
auth = (webdav_credential['user'], webdav_credential['secret'])
# must use the factory to get a unique path even when a concrete
# test also uses `tmp_path`
path = tmp_path_factory.mktemp("webdav")
# this looks a little awkward, but is done to avoid a change in
# WebDAVPath. It would be better to have WebDAVPath directly
# set `.url` internally, but that would require adjusting
# the old `serve_path_via_webdav`
server = WebDAVPath(path, auth=auth)
with server as server_url:
server.url = server_url
yield server

0 comments on commit 54a7202

Please sign in to comment.