Coverage for src/cstlcore/debug/router.py: 0%

42 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2026-02-19 12:46 +0000

1import uuid 

2 

3from fastapi import APIRouter, Depends 

4from sqlmodel import Session 

5 

6from cstlcore.collections.models import Collection 

7from cstlcore.constellations.models import Constellation 

8from cstlcore.database.engine import SQLModel, engine 

9from cstlcore.memberships.dependencies import get_session 

10from cstlcore.memberships.models import AccessEnum, ConstellationMembership 

11from cstlcore.security.password import get_password_hash 

12from cstlcore.users.models import User 

13 

14router = APIRouter() 

15 

16 

17@router.post("/debug/populate") 

18async def populate(session: Session = Depends(get_session)): 

19 SQLModel.metadata.drop_all(engine) 

20 SQLModel.metadata.create_all(engine) 

21 

22 luke = User( 

23 email="luke@starwars.com", 

24 name="Luke Skywalker", 

25 password_hash=get_password_hash("password"), 

26 email_verified=True, 

27 ) 

28 

29 leia = User( 

30 email="leia@starwars.com", 

31 name="Leia Organa", 

32 password_hash=get_password_hash("password"), 

33 email_verified=True, 

34 ) 

35 

36 constellation_star_wars = Constellation( 

37 id=uuid.UUID("0be5f2a0-1e2a-440d-82e8-40eecde2de6e"), 

38 name="Star Wars", 

39 description="A constellation about the Star Wars universe.", 

40 ) 

41 constellation_luke = Constellation( 

42 name="Luke's Constellation", 

43 description="A constellation created by Luke Skywalker.", 

44 ) 

45 constellation_leia = Constellation( 

46 name="Leia's Constellation", 

47 description="A constellation created by Leia Organa.", 

48 ) 

49 session.add_all( 

50 [luke, leia, constellation_star_wars, constellation_luke, constellation_leia] 

51 ) 

52 session.commit() 

53 session.refresh(luke) 

54 session.refresh(leia) 

55 session.refresh(constellation_star_wars) 

56 session.refresh(constellation_luke) 

57 session.refresh(constellation_leia) 

58 

59 membership = ConstellationMembership( 

60 user_id=luke.id, 

61 constellation_id=constellation_star_wars.id, 

62 access=AccessEnum.OWNER, 

63 ) 

64 membership2 = ConstellationMembership( 

65 user_id=leia.id, 

66 constellation_id=constellation_star_wars.id, 

67 access=AccessEnum.READ, 

68 ) 

69 membership3 = ConstellationMembership( 

70 user_id=luke.id, 

71 constellation_id=constellation_luke.id, 

72 access=AccessEnum.OWNER, 

73 ) 

74 membership4 = ConstellationMembership( 

75 user_id=leia.id, 

76 constellation_id=constellation_leia.id, 

77 access=AccessEnum.OWNER, 

78 ) 

79 session.add_all([membership, membership2, membership3, membership4]) 

80 session.commit() 

81 

82 collection1 = Collection( 

83 id=uuid.UUID("e5a2db13-4be4-4a5c-97bd-15c2e1e608ae"), 

84 name="The Phantom Menace", 

85 description="The first episode of the Star Wars saga.", 

86 constellation_id=constellation_star_wars.id, 

87 ) 

88 collection2 = Collection( 

89 name="Attack of the Clones", 

90 description="The second episode of the Star Wars saga.", 

91 constellation_id=constellation_star_wars.id, 

92 ) 

93 collection3 = Collection( 

94 name="Revenge of the Sith", 

95 description="The third episode of the Star Wars saga.", 

96 constellation_id=constellation_star_wars.id, 

97 ) 

98 

99 session.add_all([collection1, collection2, collection3]) 

100 session.commit() 

101 session.refresh(collection1) 

102 session.refresh(collection2) 

103 session.refresh(collection3) 

104 

105 return {"ok": True}