Coverage for middle_layer/solicit/application_layer/orm_repositories/proposal_class.py: 100.00%

23 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 sqlalchemy import update 

19from sqlalchemy.orm import Session 

20 

21from common.application_layer.orm_repositories import add_entity, get_object_by_id, list_entities 

22from solicit.domain_layer.entities.solicitation import ProposalClass 

23from solicit.domain_layer.repositories.solicitation import ProposalClassRepository 

24 

25 

26class ProposalClassORMRepository(ProposalClassRepository): 

27 def __init__(self, session: Session): 

28 self.session = session 

29 

30 def by_id(self, proposal_class_id: int) -> ProposalClass: 

31 return get_object_by_id(self.session, proposal_class_id, ProposalClass, ProposalClass.proposal_class_id) 

32 

33 def by_name(self, proposal_class_name: str) -> ProposalClass: 

34 return self.session.query(ProposalClass).filter_by(proposal_class_name=proposal_class_name).first() 

35 

36 def list_all(self) -> list[ProposalClass]: 

37 return list_entities(self.session, ProposalClass, ProposalClass.proposal_class_name) 

38 

39 def add(self, proposal_class: ProposalClass) -> int: 

40 add_entity(self.session, proposal_class) 

41 return proposal_class.proposal_class_id 

42 

43 def update(self, proposal_class: ProposalClass) -> None: 

44 self.session.execute( 

45 update(ProposalClass) 

46 .where(ProposalClass.proposal_class_id == proposal_class.proposal_class_id) 

47 .values(proposal_class_name=proposal_class.proposal_class_name) 

48 ) 

49 self.session.flush() 

50 

51 def delete(self, proposal_class: ProposalClass) -> None: 

52 self.session.delete(proposal_class) 

53 self.session.flush()