Skip to content
Snippets Groups Projects

[webservice] Select partition based on beamtime dates

Merged Cyril Danilevski requested to merge feat/proposal_date_slurm_partition into master
+ 42
12
@@ -7,7 +7,7 @@ from unittest import mock
import pytest
sys.path.insert(0, Path(__file__).parent / 'webservice')
sys.path.insert(0, Path(__file__).parent / "webservice")
import webservice # noqa: import not at top of file
from webservice.messages import MigrationError # noqa: import not at top
from webservice.webservice import ( # noqa: import not at top of file
@@ -21,6 +21,21 @@ from webservice.webservice import ( # noqa: import not at top of file
config,
)
VALID_BEAMTIME = {
"begin_at": (dt.datetime.today() - dt.timedelta(days=1)).isoformat(),
"description": None,
"end_at": (dt.datetime.today() + dt.timedelta(days=1)).isoformat(),
"flg_available": True,
"id": 772,
}
INVALID_BEAMTIME = {
"begin_at": "1818-05-05T00:00:00.000+02:00",
"description": "Karl",
"end_at": "1883-03-14T00:00:00.000+02:00",
"flg_available": True,
"id": 773,
}
@pytest.mark.requires_gpfs
def test_check_files():
@@ -243,22 +258,33 @@ async def test_run_action(mode, cmd, retcode, expected, monkeypatch):
@pytest.mark.asyncio
@pytest.mark.parametrize(
'proposal_number, action, mock_proposal_status, expected_result',
"proposal_number, action, mock_proposal_status, mock_beamtimes, expected_result",
[
(42, 'correct', 'A', 'upex-middle'), # active
('42', 'dark', 'R', 'upex-high'), # active
(404, 'correct', 'FR', 'exfel'), # finished and reviewed
(404, 'dark', 'CLO', 'exfel'), # closed
(42, "correct", "A", [INVALID_BEAMTIME, VALID_BEAMTIME], "upex-middle"), # active
("42", "dark", "R", [INVALID_BEAMTIME, VALID_BEAMTIME], "upex-high"), # active
(404, "correct", "FR", [INVALID_BEAMTIME, VALID_BEAMTIME], "exfel"), # finished and reviewed
(404, "dark", "CLO", [INVALID_BEAMTIME, VALID_BEAMTIME], "exfel"), # closed
(42, "correct", "A", [INVALID_BEAMTIME, INVALID_BEAMTIME], "exfel"), # active
(42, "correct", "A", [INVALID_BEAMTIME], "exfel"), # active but not in beamtime
(42, "correct", "A", [VALID_BEAMTIME], "upex-middle"), # active
("42", "dark", "R", [VALID_BEAMTIME, {}], "upex-high"), # active
(42, "correct", "A", [], "exfel"), # active, no beatime?
(42, "correct", "A", None, "exfel"), # active, no beatime?
],
)
async def test_get_slurm_partition(proposal_number,
action,
mock_proposal_status,
expected_result):
async def test_get_slurm_partition(
proposal_number, action, mock_proposal_status, mock_beamtimes, expected_result
):
return_value = {
"flg_beamtime_status": mock_proposal_status,
}
if mock_beamtimes is not None: # Test that we handle missing field
return_value["beamtimes"] = mock_beamtimes
response = mock.Mock()
response.status_code = 200
response.json = mock.Mock(return_value={'flg_beamtime_status': mock_proposal_status})
response.json = mock.Mock(return_value=return_value)
client = mock.Mock()
client.get_proposal_by_number_api = mock.Mock(
return_value=response)
@@ -295,7 +321,11 @@ async def test_get_slurm_partition_run_age(
# response for `get_proposal_by_number_api` AND `get_run_by_id_api`
response = mock.Mock()
response.status_code = 200
response.json = lambda: {"flg_beamtime_status": "A", "begin_at": run_str}
response.json = lambda: {
"flg_beamtime_status": "A",
"begin_at": run_str,
"beamtimes": [INVALID_BEAMTIME, VALID_BEAMTIME],
}
client = mock.Mock()
client.get_proposal_by_number_api = mock.Mock(return_value=response)
Loading