Coverage for middle_layer/allocate/domain_layer/entities/scheduling_priority.py: 92.31%

26 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# 

18from enum import Enum 

19 

20from sqlalchemy.dialects.postgresql import ENUM 

21from sqlalchemy.orm import Mapped, mapped_column 

22 

23from common.domain_layer.entities.base import Base 

24 

25 

26class SchedulingPriorityKind(Enum): 

27 POSITIVE = "POSITIVE" 

28 DECLINED = "DECLINED" 

29 NOT_PRIORITIZED = "NOT_PRIORITIZED" 

30 

31 

32class SchedulingPriority(Base): 

33 __tablename__ = "scheduling_priorities" 

34 

35 name: Mapped[str] = mapped_column(primary_key=True) 

36 description: Mapped[str] = mapped_column(nullable=False) 

37 kind: Mapped[SchedulingPriorityKind] = mapped_column( 

38 "kind", ENUM(SchedulingPriorityKind, name="scheduling_priority_kind"), nullable=False 

39 ) 

40 rank: Mapped[int] = mapped_column(nullable=False) 

41 color: Mapped[str] = mapped_column(nullable=False) 

42 

43 def __repr__(self) -> str: 

44 return f"<SchedulingPriority.{self.name}>" 

45 

46 def has_kind(self, kind: SchedulingPriorityKind) -> bool: 

47 return self.kind == kind 

48 

49 @property 

50 def is_positive(self) -> bool: 

51 return self.has_kind(SchedulingPriorityKind.POSITIVE) 

52 

53 @property 

54 def is_declined(self) -> bool: 

55 return self.has_kind(SchedulingPriorityKind.DECLINED) 

56 

57 @property 

58 def is_not_prioritized(self) -> bool: 

59 return self.has_kind(SchedulingPriorityKind.NOT_PRIORITIZED)