Coverage for middle_layer/review/domain_layer/services/validate_isr_state_change_service.py: 100.00%
21 statements
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
1# Copyright 2024 Associated Universities, Inc.
2#
3# This file is part of Telescope Time Allocation Tools (TTAT).
4#
5# TTAT is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# any later version.
9#
10# TTAT is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with TTAT. If not, see <https://www.gnu.org/licenses/>.
19def validate_isr_state_change(
20 current_state: str, desired_state: str, is_tta_member: bool, is_finalize_call: bool
21) -> str:
22 """Validate the given IndividualScienceReview state transition
24 :param current_state: State to transition from
25 :param desired_state: State to transition to
26 :param is_tta_member: Whether or not the user requesting the given state change is a TTA member
27 :param is_finalize_call: Whether the caller is using this state transition to finalize an ISR or save progress on it
28 :return: "" if the specified state transition is supported, else a helpful message
29 """
30 msg = f"Invalid IndividualScienceReview state transition requested: {current_state}->{desired_state}"
31 if is_tta_member:
32 if desired_state == "Finalized" and current_state not in ["Finalized", "Blank"]:
33 msg = ""
34 elif desired_state not in ["Finalized", "Closed"] and is_finalize_call:
35 msg = "Can only finalize or close IndividualScienceReviews right now"
36 elif desired_state in ["Closed", "Saved", "Completed"]:
37 msg = ""
38 else:
39 if current_state == "Finalized":
40 msg = "IndividualScienceReview is already finalized"
41 elif desired_state == "Finalized" and is_finalize_call:
42 if current_state not in ["Blank"]:
43 msg = ""
44 elif is_finalize_call:
45 msg = "Can only finalize IndividualScienceReviews right now"
46 elif desired_state == "Finalized":
47 msg = "Can't finalize IndividualScienceReviews right now"
48 elif desired_state in ["Saved", "Completed"] and current_state != "Closed":
49 msg = ""
50 return msg