diff --git a/tests/test_webservice.py b/tests/test_webservice.py index 157f516f1383f91bc8590006e2916f79022d1557..1092dab4aee72c9c023771d318a806405675f025 100644 --- a/tests/test_webservice.py +++ b/tests/test_webservice.py @@ -30,6 +30,14 @@ VALID_BEAMTIME = { "id": 772, } +FUTURE_BEAMTIME = { + "begin_at": (dt.datetime.today() + dt.timedelta(days=2)).isoformat(), + "description": None, + "end_at": (dt.datetime.today() + dt.timedelta(days=7)).isoformat(), + "flg_available": True, + "id": 772, + } + INVALID_BEAMTIME = { "begin_at": "1818-05-05T00:00:00.000+02:00", "description": "Karl", @@ -262,6 +270,7 @@ async def test_run_action(mode, cmd, retcode, expected, monkeypatch): 'proposal_number, action, mock_proposal_status, mock_beamtimes, expected_result', [ (42, 'correct', 'A', [INVALID_BEAMTIME, VALID_BEAMTIME], 'upex-middle'), # active + (42, 'correct', 'A', [INVALID_BEAMTIME, FUTURE_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 diff --git a/webservice/webservice.py b/webservice/webservice.py index ac31b65173090f083e73fb0a4e88311f4f3ead94..55a8a84ff09355c83b1fc7f12121976777126022 100644 --- a/webservice/webservice.py +++ b/webservice/webservice.py @@ -15,7 +15,7 @@ import sqlite3 import sys import urllib.parse from asyncio import get_event_loop, shield -from datetime import datetime, timezone +from datetime import datetime, timezone, timedelta from getpass import getuser from pathlib import Path from typing import Any, Dict, List, Optional, Tuple, Union @@ -581,7 +581,8 @@ async def get_slurm_partition( beamtimes = response.json().get('beamtimes', []) now = datetime.now().timestamp() for beamtime in beamtimes: - begin = datetime.fromisoformat(beamtime['begin_at']).timestamp() + begin = datetime.fromisoformat(beamtime['begin_at']) + begin = (begin - timedelta(days=2)).timestamp() # 2 days setup time before beamtime end = datetime.fromisoformat(beamtime['end_at']).timestamp() if begin <= now <= end: active_now = True