Coverage for middle_layer/review/domain_layer/services/validate_cd_state_change_service.py: 100.00%

20 statements  

« 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/>. 

17 

18 

19def validate_conflict_declaration_state_change( 

20 current_state: str, desired_state: str, is_reason_empty: bool, has_reason_changed: bool, is_tta_member: bool = False 

21) -> str: 

22 """Validate the given ConflictDeclaration state transition 

23 

24 :param current_state: State to transition from 

25 :param desired_state: State to transition to 

26 :param is_reason_empty: Whether or not the ConflictDeclaration's reason field is empty 

27 :param has_reason_changed: whether or not the reason has changed 

28 :param is_tta_member: Whether or not the requesting user is a TTA Member 

29 :return: "" if the specified state transition is supported, otherwise a helpful message 

30 """ 

31 # Default for unsupported destination state or unknown current state 

32 msg = f"Invalid ConflictDeclaration state transition requested: {current_state}->{desired_state}" 

33 

34 if current_state == desired_state and current_state != "Unknown": 

35 msg = "" 

36 if is_tta_member: 

37 if current_state == "Unknown" and desired_state in ["Available", "Conflicted", "Unknown"]: 

38 msg = "" 

39 elif current_state == "AutomaticallyConflicted" and desired_state in ["Available", "Unknown"]: 

40 msg = "" 

41 elif current_state == "Available" and desired_state in ["Conflicted", "Unknown"]: 

42 msg = "" 

43 elif current_state == "Conflicted" and desired_state in ["Available", "Unknown"]: 

44 msg = "" 

45 else: 

46 if current_state == "Unknown" and desired_state in ["Available", "Conflicted"]: 

47 msg = "" 

48 if current_state != "Unknown" and desired_state == "Conflicted" and has_reason_changed: 

49 msg = "ScienceReviewers cannot alter the reason on their ConflictDeclarations" 

50 

51 if desired_state == "Conflicted" and is_reason_empty: 

52 msg = "Conflicted state requires a non-empty reason to be provided" 

53 return msg