Skip to content
Snippets Groups Projects
Commit 3710cf16 authored by Cyril Danilevski's avatar Cyril Danilevski
Browse files

Add test for webservice.run_action

parent d26b8632
No related branches found
No related tags found
1 merge request!495Show clearer messages when running webservice in sim mode
......@@ -6,7 +6,10 @@ import pytest
from testpath import MockCommand
sys.path.insert(0, Path(__file__).parent / 'webservice')
from webservice.webservice import check_files, merge, parse_config, wait_on_transfer
import webservice # noqa: import not at top of file
from webservice.webservice import ( # noqa: import not at top of file
check_files, merge, parse_config, run_action, wait_on_transfer
)
@pytest.mark.requires_gpfs
......@@ -77,3 +80,26 @@ async def test_wait_on_transfer(tmp_path):
with mock_getfattr:
res = await wait_on_transfer(str(tmp_path), max_tries=1)
assert res is True
@pytest.mark.asyncio
@pytest.mark.parametrize(
'mode, cmd, retcode, expected',
[
('prod', ['CORRECT', '1', '2', '3', '4'], 1, "failed: failed executing"), # noqa
('prod', ['DARK', '1', '2', '3', '4'], 1, "failed: failed executing"),
('prod', ['CORRECT', '1', '2', '3', '4'], 0, "success: started correction"), # noqa
('prod', ['DARK', '1', '2', '3', '4'], 0, "success: started dark characterization"), # noqa
('sim', ['CORRECT', '1', '2', '3', '4'], 1, "success: simulated"),
('sim', ['DARK', '1', '2', '3', '4'], 1, "success: simulated"),
],
)
async def test_run_action(mode, cmd, retcode, expected):
job_db = mock.Mock()
async def mock_run_proc_async(*args):
return retcode, b'Submitted job: 42'
webservice.webservice.run_proc_async = mock_run_proc_async
ret = await run_action(job_db, cmd, mode, 1, 1, 1)
assert ret.lower().startswith(expected)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment