diff --git a/audbackend/core/artifactory.py b/audbackend/core/artifactory.py index a8dfa9c0..d5a4e70d 100644 --- a/audbackend/core/artifactory.py +++ b/audbackend/core/artifactory.py @@ -1,3 +1,4 @@ +import dohq_artifactory import requests import typing @@ -54,12 +55,8 @@ def _exists( ) -> bool: r"""Check if file exists on backend.""" try: - # Can lead to - # RuntimeError: 404 page not found - # or - # requests.exceptions.HTTPError: 403 Client Error return audfactory.path(path).exists() - except self._non_existing_path_error: # pragma: nocover + except self._non_existing_path_error: return False def _get_file( @@ -89,7 +86,7 @@ def _glob( path = audfactory.path(url) try: result = [str(x) for x in path.glob(pattern)] - except self._non_existing_path_error: # pragma: nocover + except self._non_existing_path_error: result = [] return result @@ -130,17 +127,22 @@ def _versions( group_id = audfactory.path_to_group_id(folder) return audfactory.versions(self.host, self.repository, group_id, name) - _non_existing_path_error = (RuntimeError, requests.exceptions.HTTPError) + _non_existing_path_error = ( + RuntimeError, + requests.exceptions.HTTPError, + dohq_artifactory.exception.ArtifactoryException, + ) r"""Error expected for non-existing paths. If a user has no permission to a given path - or the path does not exists :func:`audfactory.path` - might return a - ``RuntimeError: 404 page not found`` + or the path does not exists + :func:`audfactory.path` might return a + ``RuntimeError``, + ``requests.exceptions.HTTPError`` + for ``dohq_artifactory<0.8`` or - ``requests.exceptions.HTTPError: 403 Client Error`` - error, - which might depend on the instaleld ``dohq-artifactory`` - version. So we better catch both of them. + ``artifactory.exception.ArtifactoryException`` + for ``dohq_artifactory>=0.8``. + So we better catch all of them. """ diff --git a/setup.cfg b/setup.cfg index a5495198..0e41e934 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,7 +29,7 @@ classifiers = packages = find: install_requires = audeer >=1.17.1 - audfactory >=1.0.10 + audfactory >=1.0.12 setup_requires = setuptools_scm diff --git a/tests/conftest.py b/tests/conftest.py index f447fe99..14169507 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -42,3 +42,20 @@ def cleanup_session(): ) if url.exists(): url.unlink() + + +@pytest.fixture(scope='function', autouse=False) +def no_artifactory_access_rights(): + current_username = os.environ.get('ARTIFACTORY_USERNAME', False) + current_api_key = os.environ.get('ARTIFACTORY_API_KEY', False) + os.environ['ARTIFACTORY_USERNAME'] = 'non-existing-user' + os.environ['ARTIFACTORY_API_KEY'] = 'non-existing-password' + yield + if current_username: + os.environ["ARTIFACTORY_USERNAME"] = current_username + else: + del os.environ['ARTIFACTORY_USERNAME'] + if current_api_key: + os.environ['ARTIFACTORY_API_KEY'] = current_api_key + else: + del os.environ['ARTIFACTORY_API_KEY'] diff --git a/tests/test_artifactory.py b/tests/test_artifactory.py new file mode 100644 index 00000000..e0d1728c --- /dev/null +++ b/tests/test_artifactory.py @@ -0,0 +1,22 @@ +import pytest + +import audbackend + + +BACKEND = audbackend.Artifactory( + pytest.ARTIFACTORY_HOST, + pytest.REPOSITORY_NAME, +) + + +def test_exists(no_artifactory_access_rights): + remote_file = BACKEND.join( + pytest.ID, + 'file.txt', + ) + version = '1.0.0' + assert not BACKEND.exists(remote_file, version) + + +def test_glob(no_artifactory_access_rights): + assert BACKEND.glob('file*') == []