@@ -87,7 +87,7 @@ async def test_read_elections(database_setup):
8787# API endpoint testing (without AUTH)--------------------------------------
8888@pytest .mark .anyio
8989async def test_endpoints (client , database_setup ):
90- response = await client .get ("/elections/list " )
90+ response = await client .get ("/elections" )
9191 assert response .status_code == 200
9292 assert response .json () != {}
9393
@@ -120,9 +120,8 @@ async def test_endpoints(client, database_setup):
120120 })
121121 assert response .status_code == 401 # unauthorized access to create an election
122122
123- response = await client .post ("/elections/register " , json = {
123+ response = await client .post ("/elections/registration/{test-election-1} " , json = {
124124 "computing_id" : "1234567" ,
125- "election_name" : "test-election-1" ,
126125 "position" : "president" ,
127126 })
128127 assert response .status_code == 401 # unauthorized access to register candidates
@@ -171,7 +170,7 @@ async def test_endpoints_admin(client, database_setup):
171170 client .cookies = { "session_id" : session_id }
172171
173172 # test that more info is given if logged in & with access to it
174- response = await client .get ("/elections/list " )
173+ response = await client .get ("/elections" )
175174 assert response .status_code == 200
176175 assert response .json () != {}
177176
@@ -190,54 +189,46 @@ async def test_endpoints_admin(client, database_setup):
190189 assert response .status_code == 200
191190
192191 # ensure that authorized users can create an election
193- response = await client .post ("/elections/testElection4" , json = {
194- "election_type" : "general_election" ,
192+ response = await client .post ("/elections" , json = {
193+ "name" : "testElection4" ,
194+ "type" : "general_election" ,
195195 "datetime_start_nominations" : (datetime .now () - timedelta (days = 1 )).isoformat (),
196196 "datetime_start_voting" : (datetime .now () + timedelta (days = 7 )).isoformat (),
197197 "datetime_end_voting" : (datetime .now () + timedelta (days = 14 )).isoformat (),
198- "available_positions" : "president, treasurer" ,
198+ "available_positions" : [ "president" , " treasurer"] ,
199199 "survey_link" : "https://youtu.be/dQw4w9WgXcQ?si=kZROi2tu-43MXPM5"
200200 })
201201 assert response .status_code == 200
202202 # ensure that user can create elections without knowing each position type
203- response = await client .post ("/elections/byElection4" , json = {
204- "election_type" : "by_election" ,
203+ response = await client .post ("/elections" , json = {
204+ "name" : "byElection4" ,
205+ "type" : "by_election" ,
205206 "datetime_start_nominations" : (datetime .now () - timedelta (days = 1 )).isoformat (),
206207 "datetime_start_voting" : (datetime .now () + timedelta (days = 7 )).isoformat (),
207208 "datetime_end_voting" : (datetime .now () + timedelta (days = 14 )).isoformat (),
208209 "survey_link" : "https://youtu.be/dQw4w9WgXcQ?si=kZROi2tu-43MXPM5"
209210 })
210211 assert response .status_code == 200
211212
212- # try creating an invalid election name
213- response = await client .post ("/elections/list" , json = {
214- "election_type" : "by_election" ,
215- "datetime_start_nominations" : (datetime .now () - timedelta (days = 1 )).isoformat (),
216- "datetime_start_voting" : (datetime .now () + timedelta (days = 7 )).isoformat (),
217- "datetime_end_voting" : (datetime .now () + timedelta (days = 14 )).isoformat (),
218- "survey_link" : "https://youtu.be/dQw4w9WgXcQ?si=kZROi2tu-43MXPM5"
219- })
220- assert response .status_code == 400
221-
222-
223-
224-
225213 # try to register for a past election -> should say nomination period expired
226- response = await client .post ("/elections/registration/test election 1" , json = {
214+ testElection1 = "test election 1"
215+ response = await client .post (f"/elections/registration/{ testElection1 } " , json = {
216+ "computing_id" : load_test_db .SYSADMIN_COMPUTING_ID ,
227217 "position" : "president" ,
228218 })
229219 assert response .status_code == 400
230220 assert "nomination period" in response .json ()["detail" ]
231221
232- # try to register for an invalid position
222+ # try to register for an invalid position will just throw a 422
233223 response = await client .post (f"/elections/registration/{ election_name } " , json = {
224+ "computing_id" : load_test_db .SYSADMIN_COMPUTING_ID ,
234225 "position" : "CEO" ,
235226 })
236- assert response .status_code == 400
237- assert "invalid position" in response .json ()["detail" ]
227+ assert response .status_code == 422
238228
239229 # try to register in an unknown election
240230 response = await client .post ("/elections/registration/unknownElection12345" , json = {
231+ "computing_id" : load_test_db .SYSADMIN_COMPUTING_ID ,
241232 "position" : "president" ,
242233 })
243234 assert response .status_code == 404
@@ -247,6 +238,7 @@ async def test_endpoints_admin(client, database_setup):
247238
248239 # register for an election correctly
249240 response = await client .post (f"/elections/registration/{ election_name } " , json = {
241+ "computing_id" : "jdo12" ,
250242 "position" : "president" ,
251243 })
252244 assert response .status_code == 200
@@ -256,6 +248,7 @@ async def test_endpoints_admin(client, database_setup):
256248
257249 # duplicate registration
258250 response = await client .post (f"/elections/registration/{ election_name } " , json = {
251+ "computing_id" : "jdo12" ,
259252 "position" : "president" ,
260253 })
261254 assert response .status_code == 400
0 commit comments