diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 687b779fc369965d8789ef9f3ebc1c56222cd1d0..cc359a71f1d6bd3d7bd696179bc435cb7c4c4b65 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,5 +8,5 @@ pytest: stage: test script: - python3 -m pip install --user -r requirements.txt - - python3 -m pip install --user pytest + - python3 -m pip install --user pytest pytest-asyncio testpath - pytest -vv tests/test_* diff --git a/tests/test_webservice.py b/tests/test_webservice.py index bd482d4e8c6a39c6b89b15da7f8a561ed13c9109..78b94192d25d6a15c97cd9736a60bd28bfe050dc 100644 --- a/tests/test_webservice.py +++ b/tests/test_webservice.py @@ -1,10 +1,14 @@ import sys from pathlib import Path +from testpath import MockCommand +from unittest import mock import pytest sys.path.insert(0, Path(__file__).parent / 'webservice') -from webservice.webservice import check_files, merge, parse_config # noqa +from webservice.webservice import ( + check_files, merge, parse_config, wait_on_transfer, +) def test_check_files(): @@ -63,3 +67,14 @@ def test_parse_config(): with pytest.raises(ValueError): config = {'somekey': 'a value'} config = parse_config(cmd, config) + + +@pytest.mark.asyncio +async def test_wait_on_transfer(tmp_path): + mock_getfattr = MockCommand( + 'getfattr', + content="""#!{}\nprint('user.status="dCache"')""".format(sys.executable) + ) + with mock.patch('asyncio.sleep'), mock_getfattr: + res = await wait_on_transfer(tmp_path, max_tries=1) + assert res is True