Coverage for middle_layer/propose/application_layer/orm_repositories/proposal_copy.py: 100.00%

29 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2026-04-13 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 datetime import datetime, timezone 

19 

20from sqlalchemy.orm import Session 

21 

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

23from propose.domain_layer.entities.proposal import ProposalCopy 

24from propose.domain_layer.repositories.proposal import ProposalCopyRepository 

25 

26 

27class ProposalCopyORMRepository(ProposalCopyRepository): 

28 def __init__(self, session: Session): 

29 self.session = session 

30 

31 def by_id(self, proposal_copy_id: int) -> ProposalCopy: 

32 return get_object_by_id(self.session, proposal_copy_id, ProposalCopy, ProposalCopy.proposal_copy_id) 

33 

34 def list_all(self) -> list[ProposalCopy]: 

35 return list_entities(self.session, ProposalCopy, ProposalCopy.proposal_copy_id) 

36 

37 def add(self, proposal_copy: ProposalCopy) -> int: 

38 proposal_copy.modified_timestamp = datetime.now(timezone.utc) 

39 add_entity(self.session, proposal_copy) 

40 return proposal_copy.proposal_copy_id 

41 

42 def update(self, proposal_copy: ProposalCopy) -> None: 

43 p = self.by_id(proposal_copy.proposal_copy_id) 

44 p.title = proposal_copy.title 

45 p.abstract = proposal_copy.abstract 

46 p.scientific_justification = proposal_copy.scientific_justification 

47 p.proposal_id = proposal_copy.proposal_id 

48 proposal_copy.modified_timestamp = datetime.now(timezone.utc) 

49 p.science_category = proposal_copy.science_category 

50 p.proposal_class = proposal_copy.proposal_class 

51 self.session.flush() 

52 

53 def delete(self, proposal_copy: ProposalCopy) -> None: 

54 self.session.delete(proposal_copy) 

55 self.session.flush()