Coverage for /usr/lib/python3.10/site-packages/hyd/backend/version/models.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.0.3, created at 2023-02-06 00:31 +0000

1import datetime as dt 

2from typing import TypedDict 

3 

4from fastapi import status 

5from sqlalchemy import Column, ForeignKey, Integer, String 

6from sqlalchemy.orm import Mapped, relationship 

7 

8from hyd.backend.db import EXTEND_EXISTING, DeclarativeMeta 

9from hyd.backend.project.models import ProjectEntry 

10from hyd.backend.util.const import MAX_LENGTH_STR_ID 

11from hyd.backend.util.models import ( 

12 BASE_API_RESPONSE_SCHEMA, 

13 DETAIL_STR, 

14 NameStr, 

15 PrimaryKey, 

16 TimeStampMixin, 

17) 

18 

19#################################################################################################### 

20#### SQLAlchemy table definitions 

21#################################################################################################### 

22 

23 

24class VersionEntry(DeclarativeMeta, TimeStampMixin): 

25 __tablename__ = "version_table" 

26 __table_args__ = {"extend_existing": EXTEND_EXISTING} 

27 

28 project_id: Mapped[PrimaryKey] = Column( 

29 Integer, ForeignKey("project_table.id"), primary_key=True 

30 ) 

31 version: Mapped[NameStr] = Column(String(length=MAX_LENGTH_STR_ID), primary_key=True) 

32 

33 filename: Mapped[NameStr] = Column(String(length=MAX_LENGTH_STR_ID)) 

34 content_type: Mapped[NameStr] = Column(String(length=MAX_LENGTH_STR_ID)) 

35 

36 project_entry: Mapped[ProjectEntry] = relationship( 

37 "ProjectEntry", back_populates="version_entries" 

38 ) 

39 

40 tag_entries: Mapped[list["TagEntry"]] = relationship( 

41 "TagEntry", back_populates="version_entry", viewonly=True 

42 ) 

43 

44 

45#################################################################################################### 

46#### Response schema 

47#################################################################################################### 

48 

49 

50class VersionResponseSchema(TypedDict): 

51 project_id: PrimaryKey 

52 version: NameStr 

53 created_at: dt.datetime 

54 tags: list[NameStr] 

55 

56 

57#################################################################################################### 

58#### OpenAPI definitions 

59#################################################################################################### 

60 

61 

62API_V1_UPLOAD__POST = { 

63 **BASE_API_RESPONSE_SCHEMA, 

64 status.HTTP_200_OK: {"model": VersionResponseSchema}, 

65 status.HTTP_400_BAD_REQUEST: DETAIL_STR, 

66} 

67 

68 

69API_V1_LIST__GET = { 

70 **BASE_API_RESPONSE_SCHEMA, 

71 status.HTTP_200_OK: {"model": list[VersionResponseSchema]}, 

72} 

73 

74 

75API_V1_DELETE__DELETE = { 

76 **BASE_API_RESPONSE_SCHEMA, 

77 status.HTTP_200_OK: {"model": VersionResponseSchema}, 

78 status.HTTP_400_BAD_REQUEST: DETAIL_STR, 

79}