Coverage for middle_layer/common/application_layer/orm_repositories/orm_model.py: 100.00%

21 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 

19from copy import copy 

20 

21from sqlalchemy import Boolean, Column, DateTime, Float, ForeignKey, Integer, MetaData, String, Table, event 

22from sqlalchemy.orm import backref, registry, relationship 

23 

24from closeout.domain_layer.entities.prototype_project import PrototypeProject 

25from common.domain_layer.entities.base import Base 

26from propose.domain_layer.entities.observation_specification import ScanIntent 

27from propose.domain_layer.entities.proposal import Proposal 

28from propose.domain_layer.entities.reference_target import ReferenceTarget 

29from propose.domain_layer.entities.science_target import ScienceTarget 

30from review.domain_layer.entities.conflict_state import ConflictState 

31from solicit.domain_layer.entities.solicitation import ScienceCategory, Solicitation 

32 

33 

34def _map_orm() -> MetaData: 

35 """Construct the ORM 

36 

37 NB: order_by's use a function returning the attribute to order by in order to avoid order-of-declaration issues 

38 Source: https://docs.sqlalchemy.org/en/14/orm/relationship_api.html#sqlalchemy.orm.relationship 

39 """ 

40 mapper_registry = registry() 

41 metadata = Base.metadata 

42 

43 proposal = metadata.tables["proposals"] 

44 

45 scan_intent = Table( 

46 "scan_intents", 

47 metadata, 

48 Column("name", String, primary_key=True), 

49 Column("description", String), 

50 ) 

51 

52 temporal_references = Table("temporal_references", metadata, Column("name", String, primary_key=True)) 

53 published_destinations = Table("publication_destinations", metadata, Column("name", String, primary_key=True)) 

54 

55 mapper_registry.map_imperatively(ScanIntent, scan_intent) 

56 

57 return metadata 

58 

59 

60mapped_metadata = _map_orm() # This is a Singleton; mapping should only happen once ever