Skip to content
Snippets Groups Projects
Commit 696b3e23 authored by Cyril Danilevski's avatar Cyril Danilevski :scooter: Committed by Karim Ahmed
Browse files

Update tests to take beamtime dates into account

parent db4399fc
No related branches found
No related tags found
1 merge request!725[webservice] Select partition based on beamtime dates
...@@ -21,6 +21,21 @@ 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, 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 @pytest.mark.requires_gpfs
def test_check_files(): def test_check_files():
...@@ -243,22 +258,33 @@ async def test_run_action(mode, cmd, retcode, expected, monkeypatch): ...@@ -243,22 +258,33 @@ async def test_run_action(mode, cmd, retcode, expected, monkeypatch):
@pytest.mark.asyncio @pytest.mark.asyncio
@pytest.mark.parametrize( @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, 'correct', 'A', [INVALID_BEAMTIME, VALID_BEAMTIME], 'upex-middle'), # active
('42', 'dark', 'R', 'upex-high'), # active ('42', 'dark', 'R', [INVALID_BEAMTIME, VALID_BEAMTIME], 'upex-high'), # active
(404, 'correct', 'FR', 'exfel'), # finished and reviewed (404, 'correct', 'FR', [INVALID_BEAMTIME, VALID_BEAMTIME], 'exfel'), # finished and reviewed
(404, 'dark', 'CLO', 'exfel'), # closed (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, async def test_get_slurm_partition(
action, proposal_number, action, mock_proposal_status, mock_beamtimes, expected_result
mock_proposal_status, ):
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 = mock.Mock()
response.status_code = 200 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 = mock.Mock()
client.get_proposal_by_number_api = mock.Mock( client.get_proposal_by_number_api = mock.Mock(
return_value=response) return_value=response)
...@@ -295,7 +321,11 @@ async def test_get_slurm_partition_run_age( ...@@ -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 for `get_proposal_by_number_api` AND `get_run_by_id_api`
response = mock.Mock() response = mock.Mock()
response.status_code = 200 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 = mock.Mock()
client.get_proposal_by_number_api = mock.Mock(return_value=response) client.get_proposal_by_number_api = mock.Mock(return_value=response)
......
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