@@ -69,7 +69,10 @@ def test_project_leaders_not_empty(self):
69
69
response = self .client .get (url )
70
70
self .assertGreater (len (response .content ), LEN_BASE )
71
71
72
+
72
73
VERBOSE = False
74
+
75
+
73
76
class TraverseLinksTest (TestCase ):
74
77
75
78
def setUp (self ):
@@ -116,14 +119,17 @@ def setUpTestData(cls):
116
119
pm .set_project_status ("ACAD_00001" , "ACCEPT" )
117
120
pm .add_user_to_project ("ACAD_00001" , "dick" )
118
121
pm .add_user_to_project ("ACAD_00001" , "jane" )
119
- pm .add_tag_to_project ("ACAD_00001" , "rand1,rand2,education,student,policy" )
122
+ pm .add_tag_to_project (
123
+ "ACAD_00001" , "rand1,rand2,education,student,policy" )
120
124
121
125
pm .add_user_to_project ("ACAD_00002" , "jane" )
122
- pm .add_tag_to_project ("ACAD_00002" , "rand1,rand2,education,student,policy" )
126
+ pm .add_tag_to_project (
127
+ "ACAD_00002" , "rand1,rand2,education,student,policy" )
123
128
124
129
def test_traverse_urls (self ):
125
130
# Fill these lists as needed with your site specific URLs to check and to avoid
126
- to_traverse_list = ["/" , "/projects/" , "/students/" , "/educators/" , "/leaders/" ]
131
+ to_traverse_list = ["/" , "/projects/" ,
132
+ "/students/" , "/educators/" , "/leaders/" ]
127
133
to_avoid_list = ["javascript:history\.back()" , "https://*" ,
128
134
"javascript:history\.go\(-1\)" , "^mailto:.*" ]
129
135
@@ -227,7 +233,19 @@ def match_any(my_string, regexp_list):
227
233
228
234
class SecuredPageTestCase (TestCase ):
229
235
def setUp (self ):
230
- super ()
236
+ pm = OpenSUTDProjectManager ()
237
+ pm .create_project (project_uid = "ACAD_00001" ,
238
+ title = "OpenSUTD Web Platform" ,
239
+ caption = "Sample project 1" ,
240
+ category = "ACAD" ,
241
+ url = "https://github.com/OpenSUTD/web-platform-prototype" ,
242
+ poster_url = "https://via.placeholder.com/150" ,
243
+ featured_image = "https://via.placeholder.com/150" )
244
+
245
+ um = OpenSUTDUserManager ()
246
+ um .create_user ("tom" , display_name = "Tom Magnanti" ,
247
+ display_picture = "https://via.placeholder.com/150" ,
248
+ graduation_year = 2018 , pillar = "ISTD" )
231
249
232
250
def test_auth_approval_view (self ):
233
251
url = reverse ("projects:approval" )
@@ -240,15 +258,31 @@ def test_auth_submit_view(self):
240
258
self .assertEqual (response .status_code , 302 )
241
259
242
260
def test_auth_submit_reject (self ):
243
- url = reverse ("projects:reject" , args = ("rand " ,))
261
+ url = reverse ("projects:reject" , args = ("ACAD_00001 " ,))
244
262
response = self .client .get (url )
245
263
self .assertEqual (response .status_code , 302 )
246
264
247
265
def test_auth_submit_approve (self ):
248
- url = reverse ("projects:approve" , args = ("rand" ,))
266
+ url = reverse ("projects:approve" , args = ("ACAD_00001" ,))
267
+ response = self .client .get (url )
268
+ self .assertEqual (response .status_code , 302 )
269
+
270
+ def test_auth_user_edit (self ):
271
+ url = reverse ("projects:user_edit" , args = ("tom" ,))
249
272
response = self .client .get (url )
250
273
self .assertEqual (response .status_code , 302 )
251
274
275
+ def test_auth_project_edit (self ):
276
+ url = reverse ("projects:project_edit" , args = ("ACAD_00001" ,))
277
+ response = self .client .get (url )
278
+ self .assertEqual (response .status_code , 302 )
279
+
280
+ def test_auth_project_bypass (self ):
281
+ url = reverse ("projects:project_page_bypass" , args = ("ACAD_00001" ,))
282
+ response = self .client .get (url )
283
+ # actually a custom 404 page
284
+ self .assertEqual (response .status_code , 200 )
285
+
252
286
253
287
class SubmissionFormTest (TestCase ):
254
288
def setUp (self ):
@@ -259,21 +293,146 @@ def setUp(self):
259
293
graduation_year = 2018 , pillar = "ISTD" ,
260
294
password = "tompassword" )
261
295
262
- def test_submission_form_entry (self ):
263
296
self .client .login (username = "tom" , password = "tompassword" )
264
297
265
- # test user can actually get to the page
298
+ def test_submission_form_entry ( self ):
266
299
response = self .client .get (reverse ("projects:submit_new" ))
267
300
self .assertEqual (response .status_code , 200 )
268
301
269
302
# test submission mechanism
270
303
form = SubmissionForm ({"project_name" : "test" ,
271
304
"caption" : "test caption" ,
272
305
"category" : "ACAD" ,
273
- "featured_image" : "" ,
306
+ "featured_image" : "http://pluspng.com/img-png/user-png-icon-male-user-icon-512.png " ,
274
307
"github_url" : "https://github.com/OpenSUTD/web-platform-prototype" ,
308
+ "poster_url" : "http://pluspng.com/img-png/user-png-icon-male-user-icon-512.png" })
309
+
310
+ self .assertEqual (form .is_valid (), True )
311
+
312
+ def test_submission_form_entry_invalid (self ):
313
+ response = self .client .get (reverse ("projects:submit_new" ))
314
+ self .assertEqual (response .status_code , 200 )
315
+
316
+ # test submission mechanism
317
+ form = SubmissionForm ({"project_name" : "" ,
318
+ "caption" : "" ,
319
+ "category" : "" ,
320
+ "featured_image" : "" ,
321
+ "github_url" : "" ,
275
322
"poster_url" : "" })
276
323
324
+ self .assertEqual (form .is_valid (), False )
325
+
326
+ def test_submission_form_entry_not_github (self ):
327
+ response = self .client .get (reverse ("projects:submit_new" ))
328
+ self .assertEqual (response .status_code , 200 )
329
+
330
+ # test submission mechanism
331
+ form = SubmissionForm ({"project_name" : "test" ,
332
+ "caption" : "test caption" ,
333
+ "category" : "ACAD" ,
334
+ "featured_image" : "http://pluspng.com/img-png/user-png-icon-male-user-icon-512.png" ,
335
+ "github_url" : "https://lolcats.com/OpenSUTD/web-platform-prototype" ,
336
+ "poster_url" : "http://pluspng.com/img-png/user-png-icon-male-user-icon-512.png" })
337
+
338
+ self .assertEqual (form .is_valid (), False )
339
+
340
+
341
+ class UserProfileFormTest (TestCase ):
342
+ def setUp (self ):
343
+ self .client = Client ()
344
+ um = OpenSUTDUserManager ()
345
+ um .create_user ("tom" , display_name = "Tom Magnanti" ,
346
+ display_picture = "https://via.placeholder.com/150" ,
347
+ graduation_year = 2018 , pillar = "ISTD" ,
348
+ password = "tompassword" )
349
+ self .client .login (username = "tom" , password = "tompassword" )
350
+
351
+ def test_submission_form_entry (self ):
352
+ # test user can actually get to the page
353
+ response = self .client .get (
354
+ reverse ("projects:user_edit" , args = ("tom" ,)))
355
+ self .assertEqual (response .status_code , 200 )
356
+
357
+ # test submission mechanism
358
+ form = UserProfileForm ({"display_name" : "tom2" ,
359
+ "display_picture" : "http://pluspng.com/img-png/user-png-icon-male-user-icon-512.png" ,
360
+ "graduation_year" : 2019 ,
361
+ "pillar" : "ISTD" ,
362
+ "bio" : "Hi I am Tom" ,
363
+ "contact_email" :
"[email protected] " ,
364
+ "personal_links" : "tlkh.design" })
365
+
366
+ self .assertEqual (form .is_valid (), True )
367
+
368
+ def test_submission_form_entry_invalid (self ):
369
+ # test user can actually get to the page
370
+ response = self .client .get (
371
+ reverse ("projects:user_edit" , args = ("tom" ,)))
372
+ self .assertEqual (response .status_code , 200 )
373
+
374
+ # test submission mechanism
375
+ form = UserProfileForm ({"display_name" : "" ,
376
+ "display_picture" : "" ,
377
+ "graduation_year" : 2019 ,
378
+ "pillar" : "" ,
379
+ "bio" : "" ,
380
+ "contact_email" : "" ,
381
+ "personal_links" : "" })
382
+
383
+ self .assertEqual (form .is_valid (), False )
384
+
385
+
386
+ class ProjectEditFormTest (TestCase ):
387
+ def setUp (self ):
388
+ self .client = Client ()
389
+ um = OpenSUTDUserManager ()
390
+ um .create_user ("tom" , display_name = "Tom Magnanti" ,
391
+ display_picture = "https://via.placeholder.com/150" ,
392
+ graduation_year = 2018 , pillar = "ISTD" ,
393
+ password = "tompassword" )
394
+ pm = OpenSUTDProjectManager ()
395
+ pm .create_project (project_uid = "ACAD_00001" ,
396
+ title = "OpenSUTD Web Platform" ,
397
+ caption = "Sample project 1" ,
398
+ category = "ACAD" ,
399
+ url = "https://github.com/OpenSUTD/web-platform-prototype" ,
400
+ poster_url = "https://via.placeholder.com/150" ,
401
+ featured_image = "https://via.placeholder.com/150" )
402
+ pm .set_project_status ("ACAD_00001" , "ACCEPT" )
403
+
404
+ self .client .login (username = "tom" , password = "tompassword" )
405
+
406
+ def test_submission_form_entry_invalid (self ):
407
+ # test user can actually get to the page
408
+ response = self .client .get (
409
+ reverse ("projects:project_edit" , args = ("ACAD_00001" ,)))
410
+ self .assertEqual (response .status_code , 200 )
411
+
412
+ # test submission mechanism
413
+ form = ProjectEditForm ({"title" : "" ,
414
+ "caption" : "" ,
415
+ "featured_image" : "" ,
416
+ "url" : "" ,
417
+ "poster_url" : "" })
418
+
419
+ self .assertEqual (form .is_valid (), False )
420
+
421
+ def test_submission_form_entry (self ):
422
+ # test user can actually get to the page
423
+ response = self .client .get (
424
+ reverse ("projects:project_edit" , args = ("ACAD_00001" ,)))
425
+ self .assertEqual (response .status_code , 200 )
426
+
427
+ # test submission mechanism
428
+ form = ProjectEditForm ({"title" : "lalalal" ,
429
+ "caption" : "lalalal" ,
430
+ "featured_image" : "lalalal.com" ,
431
+ "url" : "https://github.com/OpenSUTD/web-platform-prototype" ,
432
+ "poster_url" : "lalalal.com" })
433
+
434
+ self .assertEqual (form .is_valid (), True )
435
+
277
436
278
437
class LogintoSecuredPageTestCase (TestCase ):
279
438
def setUp (self ):
@@ -283,17 +442,37 @@ def setUp(self):
283
442
display_picture = "https://via.placeholder.com/150" ,
284
443
graduation_year = 2018 , pillar = "ISTD" ,
285
444
password = "tompassword" )
445
+ pm = OpenSUTDProjectManager ()
446
+ pm .create_project (project_uid = "ACAD_00001" ,
447
+ title = "OpenSUTD Web Platform" ,
448
+ caption = "Sample project 1" ,
449
+ category = "ACAD" ,
450
+ url = "https://github.com/OpenSUTD/web-platform-prototype" ,
451
+ poster_url = "https://via.placeholder.com/150" ,
452
+ featured_image = "https://via.placeholder.com/150" )
286
453
287
- def test_login_approval_view (self ):
288
454
self .client .login (username = "tom" , password = "tompassword" )
455
+
456
+ def test_login_approval_view (self ):
289
457
response = self .client .get (reverse ("projects:approval" ))
290
458
self .assertEqual (response .status_code , 200 )
291
459
292
460
def test_login_submission_view (self ):
293
- self .client .login (username = "tom" , password = "tompassword" )
294
461
response = self .client .get (reverse ("projects:submit_new" ))
295
462
self .assertEqual (response .status_code , 200 )
296
463
464
+ def test_login_user_edit (self ):
465
+ url = reverse ("projects:user_edit" , args = ("tom" ,))
466
+ response = self .client .get (url )
467
+ self .assertEqual (response .status_code , 200 )
468
+
469
+ def test_login_project_edit (self ):
470
+ pm = OpenSUTDProjectManager ()
471
+ pm .set_project_status ("ACAD_00001" , "ACCEPT" )
472
+ url = reverse ("projects:project_edit" , args = ("ACAD_00001" ,))
473
+ response = self .client .get (url )
474
+ self .assertEqual (response .status_code , 200 )
475
+
297
476
298
477
class UserTestCase (TestCase ):
299
478
def setUp (self ):
@@ -442,7 +621,8 @@ def test_project_page_not_approved(self):
442
621
url = reverse ("projects:project_page" , args = ("ACAD_00001" ,))
443
622
response = self .client .get (url )
444
623
self .assertEqual (response .status_code , 200 )
445
- self .assertEqual ("Error 404: Page Not Found!" in str (response .content ), True )
624
+ self .assertEqual ("Error 404: Page Not Found!" in str (
625
+ response .content ), True )
446
626
self .assertGreater (len (response .content ), LEN_BASE )
447
627
448
628
def test_project_page_approved (self ):
0 commit comments