3
3
# python load_test_db.py
4
4
5
5
import asyncio
6
- from datetime import datetime , timedelta
6
+ from datetime import date , datetime , timedelta
7
7
8
8
import sqlalchemy
9
9
from auth .crud import create_user_session
10
10
from database import SQLALCHEMY_TEST_DATABASE_URL , Base , DatabaseSessionManager
11
11
from officers .constants import OfficerPosition
12
- from officers .crud import update_officer_info , update_officer_term
13
- from officers .schemas import OfficerInfoData , OfficerTermData
12
+ from officers .crud import create_new_officer_info , create_new_officer_term , update_officer_info , update_officer_term
13
+ from officers .types import OfficerInfoData , OfficerTermData
14
14
from sqlalchemy .ext .asyncio import AsyncSession
15
15
16
16
@@ -68,7 +68,7 @@ async def load_test_officers_data(db_session: AsyncSession):
68
68
69
69
print ("add officer info" )
70
70
# this person has uploaded all of their info
71
- update_officer_info (db_session , OfficerInfoData (
71
+ await create_new_officer_info (db_session , OfficerInfoData (
72
72
legal_name = "Person A" ,
73
73
discord_id = str (88_1234_7182_4877_1111 ),
74
74
discord_name = "person_a_yeah" ,
@@ -80,7 +80,7 @@ async def load_test_officers_data(db_session: AsyncSession):
80
80
google_drive_email = "[email protected] " ,
81
81
))
82
82
# this person has not joined the CSSS discord, so their discord name & nickname could not be found
83
- update_officer_info (db_session , OfficerInfoData (
83
+ await create_new_officer_info (db_session , OfficerInfoData (
84
84
legal_name = "Person B" ,
85
85
discord_id = str (88_1234_7182_4877_2222 ),
86
86
discord_name = None ,
@@ -92,7 +92,7 @@ async def load_test_officers_data(db_session: AsyncSession):
92
92
google_drive_email = "[email protected] " ,
93
93
))
94
94
# this person has uploaded the minimal amount of information
95
- update_officer_info (db_session , OfficerInfoData (
95
+ await create_new_officer_info (db_session , OfficerInfoData (
96
96
legal_name = "Person C" ,
97
97
discord_id = None ,
98
98
discord_name = None ,
@@ -105,13 +105,12 @@ async def load_test_officers_data(db_session: AsyncSession):
105
105
))
106
106
await db_session .commit ()
107
107
108
-
109
- update_officer_term (db_session , OfficerTermData (
108
+ await create_new_officer_term (db_session , OfficerTermData (
110
109
computing_id = "abc11" ,
111
110
112
111
position = OfficerPosition .VicePresident .value ,
113
- start_date = datetime .today () - timedelta (days = 365 ),
114
- end_date = datetime .today () - timedelta (days = 1 ),
112
+ start_date = date .today () - timedelta (days = 365 ),
113
+ end_date = date .today () - timedelta (days = 1 ),
115
114
116
115
nickname = "the A" ,
117
116
favourite_course_0 = "CMPT 125" ,
@@ -123,11 +122,11 @@ async def load_test_officers_data(db_session: AsyncSession):
123
122
biography = "Hi! I'm person A and I do lots of cool things! :)" ,
124
123
photo_url = None , # TODO: this should be replaced with a default image
125
124
))
126
- update_officer_term (db_session , OfficerTermData (
125
+ await create_new_officer_term (db_session , OfficerTermData (
127
126
computing_id = "abc11" ,
128
127
129
128
position = OfficerPosition .ExecutiveAtLarge .value ,
130
- start_date = datetime .today (),
129
+ start_date = date .today (),
131
130
end_date = None ,
132
131
133
132
nickname = "the holy A" ,
@@ -140,12 +139,12 @@ async def load_test_officers_data(db_session: AsyncSession):
140
139
biography = "Hi! I'm person A and I want school to be over ; _ ;" ,
141
140
photo_url = None , # TODO: this should be replaced with a default image
142
141
))
143
- update_officer_term (db_session , OfficerTermData (
142
+ await create_new_officer_term (db_session , OfficerTermData (
144
143
computing_id = "abc33" ,
145
144
146
145
position = OfficerPosition .President .value ,
147
- start_date = datetime .today (),
148
- end_date = datetime .today () + timedelta (days = 365 ),
146
+ start_date = date .today (),
147
+ end_date = date .today () + timedelta (days = 365 ),
149
148
150
149
nickname = "CC" ,
151
150
favourite_course_0 = "CMPT 999" ,
@@ -157,13 +156,98 @@ async def load_test_officers_data(db_session: AsyncSession):
157
156
biography = "I'm person C..." ,
158
157
photo_url = None , # TODO: this should be replaced with a default image
159
158
))
159
+ # this officer term is not fully filled in
160
+ await create_new_officer_term (db_session , OfficerTermData (
161
+ computing_id = "abc22" ,
162
+
163
+ position = OfficerPosition .DirectorOfArchives .value ,
164
+ start_date = date .today (),
165
+ end_date = date .today () + timedelta (days = 365 ),
166
+
167
+ nickname = "Bee" ,
168
+ favourite_course_0 = "CMPT 604" ,
169
+ favourite_course_1 = None ,
170
+
171
+ favourite_pl_0 = "B" ,
172
+ favourite_pl_1 = "N/A" ,
173
+
174
+ biography = None ,
175
+ photo_url = None , # TODO: this should be replaced with a default image
176
+ ))
177
+ await db_session .commit ()
178
+
179
+ await update_officer_info (db_session , OfficerInfoData (
180
+ legal_name = "Person C ----" ,
181
+ discord_id = None ,
182
+ discord_name = None ,
183
+ discord_nickname = None ,
184
+
185
+ computing_id = "abc33" ,
186
+ # adds a phone number
187
+ phone_number = "123-456-7890" ,
188
+ github_username = None ,
189
+ google_drive_email = None ,
190
+ ))
191
+ await update_officer_term (db_session , OfficerTermData (
192
+ computing_id = "abc33" ,
193
+
194
+ position = OfficerPosition .President .value ,
195
+ start_date = date .today (),
196
+ end_date = date .today () + timedelta (days = 365 ),
197
+
198
+ nickname = "SEE SEE" ,
199
+ favourite_course_0 = "CMPT 999" ,
200
+ favourite_course_1 = "CMPT 354" ,
201
+
202
+ favourite_pl_0 = "C++" ,
203
+ favourite_pl_1 = "C" ,
204
+
205
+ biography = "You see, I'm person C..." ,
206
+ photo_url = None ,
207
+ ))
208
+ await db_session .commit ()
209
+
210
+ async def load_sysadmin (db_session : AsyncSession ):
211
+ print ("loading new sysadmin" )
212
+ # put your computing id here for testing purposes
213
+ SYSADMIN_COMPUTING_ID = "gsa92"
214
+
215
+ await create_new_officer_info (db_session , OfficerInfoData (
216
+ legal_name = "Gabe Schulz" ,
217
+ discord_id = None ,
218
+ discord_name = None ,
219
+ discord_nickname = None ,
220
+
221
+ computing_id = SYSADMIN_COMPUTING_ID ,
222
+ phone_number = None ,
223
+ github_username = None ,
224
+ google_drive_email = None ,
225
+ ))
226
+ await create_new_officer_term (db_session , OfficerTermData (
227
+ computing_id = SYSADMIN_COMPUTING_ID ,
228
+
229
+ position = OfficerPosition .SystemAdministrator .value ,
230
+ start_date = date .today () - timedelta (days = 365 ),
231
+ end_date = None ,
232
+
233
+ nickname = "Gabe" ,
234
+ favourite_course_0 = "CMPT 379" ,
235
+ favourite_course_1 = "CMPT 295" ,
236
+
237
+ favourite_pl_0 = "Rust" ,
238
+ favourite_pl_1 = "C" ,
239
+
240
+ biography = "The systems are good o7" ,
241
+ photo_url = None ,
242
+ ))
160
243
await db_session .commit ()
161
244
162
245
async def async_main (sessionmanager ):
163
246
await reset_db (sessionmanager ._engine )
164
247
async with sessionmanager .session () as db_session :
165
248
# load_test_auth_data
166
249
await load_test_officers_data (db_session )
250
+ await load_sysadmin (db_session )
167
251
168
252
if __name__ == "__main__" :
169
253
response = input (f"This will reset the { SQLALCHEMY_TEST_DATABASE_URL } database, are you okay with this? (y/N): " )
0 commit comments