-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeneral_test.py
591 lines (536 loc) · 28.3 KB
/
general_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
# Bep Marketplace ELE
# Copyright (c) 2016-2022 Kolibri Solutions
# License: See LICENSE file or https://github.com/KolibriSolutions/BepMarketplace/blob/master/LICENSE
#
"""
General functions/classes used in tests.
"""
import re
import sys
import traceback
from datetime import datetime, timedelta
from django.conf import settings
from django.contrib.auth.models import User, Group
from django.test import TestCase, Client
from django.test import override_settings
from django.urls import reverse
from django.utils import timezone
from django.utils.module_loading import import_module
from general_view import get_timephase_number
from index.models import UserMeta, UserAcceptedTerms, Track
from presentations.models import PresentationOptions, PresentationTimeSlot, PresentationSet, Room
from proposals.models import Proposal
from results.models import ResultOptions
from students.models import Distribution
from support.models import GroupAdministratorThrough, CapacityGroup
from timeline.models import TimeSlot, TimePhase
TEST_HTML_VALID = False
#
# if TEST_HTML_VALID:
# from htmlvalidator.client import ValidatingClient
# disable cache for all tests
@override_settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}},
EMAIL_BACKEND='django.core.mail.backends.filebased.EmailBackend', EMAIL_FILE_PATH='./test_mail.log',
MIDDLEWARE_CLASSES=[mc for mc in settings.MIDDLEWARE
if mc != 'tracking.middleware.TelemetryMiddleware'],
)
# @override_settings(
# HTMLVALIDATOR_ENABLED = True, # to test html valid
# # HTMLVALIDATOR_DUMPDIR = 'validationerrors/', # default it /tmp
# HTMLVALIDATOR_OUTPUT = 'stdout', # default is 'file'
# HTMLVALIDATOR_VNU_URL = 'http://localhost:8888/',
# HTMLVALIDATOR_FAILFAST = True,
# )
class ViewsTest(TestCase):
"""
Class with testclient to test views. Some functions to setup data in the database.
"""
def setUp(self):
"""
Setup test data, like users and groups.
"""
# whether to produce output, please override this on app level if debug is required.
self.debug = False
# to test that each page is at least tested once, check if all urls of the app are tested.
urlpatterns = import_module(self.app + '.urls', 'urlpatterns').urlpatterns
self.allurls = [x.name for x in urlpatterns]
# the client used for testing
if TEST_HTML_VALID:
self.client = ValidatingClient()
else:
self.client = Client()
# info string to show debug info in case of test assertion failure
self.info = {}
# The timeslot used for testing proposal of current timeslot
self.ts = TimeSlot(Begin=datetime.now(), End=datetime.now() + timedelta(days=3), Name='thisyear')
self.ts.save()
# The timephase used for testing. The Description is changed every test.
self.tp = TimePhase(Begin=datetime.now(), End=datetime.now() + timedelta(days=3), TimeSlot=self.ts,
Description=1)
self.tp.save()
# The timeslot used for testing proposal of next timeslot
self.nts = TimeSlot(Begin=datetime.now() + timedelta(days=300), End=datetime.now() + timedelta(days=500),
Name='nextyear')
self.nts.save()
# The timeslot used for testing proposal of previous timeslot
self.pts = TimeSlot(Begin=datetime.now() - timedelta(days=500), End=datetime.now() - timedelta(days=300),
Name='prevyear')
self.pts.save()
# Create capacity groups models
groups = (
("EES", "Electrical Energy Systems"),
("ECO", "Electro-Optical Communications"),
("EPE", "Electromechanics and Power Electronics"),
("ES", "Electronic Systems"),
("IC", "Integrated Circuits"),
("CS", "Control Systems"),
("SPS", "Signal Processing Systems"),
("PHI", "Photonic Integration"),
("EM", "Electromagnetics")
)
for group in groups:
self.c, created = CapacityGroup.objects.get_or_create(ShortName=group[0], FullName=group[1])
assert created
# Create groups and users
self.create_groups()
self.create_users()
# Track for automotive, with trackhead t-h. Automotive track must exist because it is special. (distributions)
th = User.objects.get(username='t-h')
self.track = Track(Name='Automotive', ShortName='AU', Head=th)
self.track.save()
grt = User.objects.get(username='t-4')
grr = User.objects.get(username='r-4')
# only read/write administration is tested. Not readonly.
g = GroupAdministratorThrough(User=grt, Super=True,
Group=CapacityGroup.objects.all()[0])
g.save()
g2 = GroupAdministratorThrough(User=grr, Super=True,
Group=CapacityGroup.objects.all()[1])
g2.save()
## setup matrix with all possible rights
# expected results:
# r=random, t=this(for this proposal)
# s=student, p=private-student, r=responsible, a=assistant, u=assistant_not_verified t=trackhead
# ta = assessor of presentation, 4=groupadministration, 5=studyadvisor, 6=profskill
# matrix with different types of permissions, set for each user of the array self.usernames
# permissions by user. The order is the order of self.usernames. User 'god' is disabled (not tested).
# usernames: r-1 t-1 r-h t-h r-2 t-2 t-u r-3 r-s t-p r-4 t-4 r-5 r-6 r-7 ra-1 ta-1 sup, ano
self.p_forbidden = [403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 302] # no one
self.p_superuser = [403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 200, 302] # no one
self.p_all = [200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 302] # everyone
self.p_anonymous = [200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200] # everyone
self.p_redirect = [302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, 302] # everyone
self.p_staff = [200, 200, 200, 200, 200, 200, 200, 200, 403, 403, 200, 200, 200, 200, 200, 200, 200, 200, 302] # all staff, general
self.p_staff_veri = [200, 200, 200, 200, 200, 200, 403, 200, 403, 403, 200, 200, 200, 200, 403, 200, 200, 200, 302] # all staff, without unverified, without type7
self.p_staff122u35 = [200, 200, 200, 200, 200, 200, 200, 200, 403, 403, 403, 403, 200, 403, 403, 200, 200, 200, 302] # all staff, for chooseedit list
self.p_staff_prop = [200, 200, 200, 200, 200, 200, 200, 200, 403, 403, 200, 200, 403, 403, 403, 200, 200, 200, 302] # all staff, to create proposals
# self.p_staff_prop_no4 = [200, 200, 200, 200, 200, 200, 200, 200, 403, 403, 403, 403, 403, 403, 403, 200, 200, 200, 302] # all staff to create but no type4
self.p_staff_prop_nou= [200, 200, 200, 200, 200, 200, 403, 200, 403, 403, 200, 200, 403, 403, 403, 200, 200, 200, 302] # all staff, to create proposals, no unverified
self.p_staff_stud = [200, 200, 200, 200, 200, 200, 403, 200, 403, 403, 403, 403, 403, 200, 403, 200, 200, 200, 302] # all staff that can see students (1,2,3,6)
self.p_all_this = [403, 200, 403, 200, 403, 200, 200, 200, 403, 403, 403, 200, 403, 403, 403, 403, 403, 200, 302] # staff of this proposal
self.p_all_this_pres= [403, 200, 403, 200, 403, 200, 200, 200, 403, 403, 403, 200, 403, 403, 403, 403, 200, 200, 302] # staff of this proposal including ta-1
self.p_all_this_dist= [403, 200, 403, 200, 403, 200, 403, 200, 403, 403, 403, 403, 403, 200, 403, 403, 403, 200, 302] # staff of this proposal, as distributed to r-s (not t-p!) and assessor. Also type6.
self.p_all_this_dist_stud= [403, 200, 403, 200, 403, 200, 403, 200, 200, 403, 403, 403, 403, 200, 403, 403, 403, 200, 302] # staff of this proposal, as distributed to r-s (not t-p!) and assessor. Also type6.
self.p_all_this_dist_ta=[403, 200, 403, 200, 403, 200, 403, 200, 403, 403, 403, 403, 403, 200, 403, 403, 200, 200, 302] # staff of this proposal, as distributed to r-s (not t-p!) and assessor. Also type6. and assessor
self.p_all_this_dist_ta_stud=[403, 200, 403, 200, 403, 200, 403, 200, 200, 403, 403, 403, 403, 200, 403, 403, 200, 200, 302] # staff of this proposal, as distributed to r-s (not t-p!) and assessor. Also type6. and assessor
self.p_no_assistant = [403, 200, 403, 200, 403, 403, 403, 200, 403, 403, 403, 200, 403, 403, 403, 403, 403, 200, 302] # staff of this proposal except assistants. For up/downgrading and edit proposal.
self.p_staff_prv_results=[403, 200, 403, 200, 403, 200, 403, 200, 403, 403, 403, 403, 403, 403, 403, 403, 403, 200, 302] # staff of this proposal except assistants including assessors. For results staff grading form, without assessor.
self.p_staff_results = [403, 200, 403, 200, 403, 200, 403, 200, 403, 403, 403, 403, 403, 403, 403, 403, 200, 200, 302] # staff of this proposal except assistants including assessors. For results staff grading form.
self.p_all_this_view = [403, 200, 403, 200, 403, 200, 200, 200, 403, 403, 403, 200, 403, 403, 403, 403, 403, 200, 302] # staff of this proposal including view only users (type4)
self.p_private = [403, 200, 403, 200, 403, 200, 200, 200, 403, 200, 403, 200, 403, 403, 403, 403, 403, 200, 302] # private proposal view status 4
self.p_private_pres= [403, 200, 403, 200, 403, 200, 200, 200, 403, 200, 403, 200, 403, 403, 403, 403, 200, 200, 302] # private proposal view status 4, in phase 7 or if presentation is public.
self.p_trackhead = [403, 403, 403, 200, 403, 403, 403, 200, 403, 403, 403, 200, 403, 403, 403, 403, 403, 200, 302] # trackhead of proposal and support
self.p_grade_final = [403, 403, 403, 200, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 200, 200, 302] # Trackhead and assessor can finalize grades.
self.p_track = [403, 403, 200, 200, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 302] # any trackhead
self.p_pending = [200, 200, 200, 200, 200, 200, 200, 403, 403, 403, 200, 200, 403, 403, 403, 200, 200, 200, 302] # staff with pending proposals
self.p_support = [403, 403, 403, 403, 403, 403, 403, 200, 403, 403, 403, 403, 403, 403, 403, 403, 403, 200, 302] # type3 support
self.p_support_prv = [403, 403, 403, 403, 403, 403, 403, 200, 403, 403, 403, 403, 403, 200, 403, 403, 403, 200, 302] # 3+6
self.p_cgadmin = [403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 200, 200, 403, 403, 403, 403, 403, 200, 302] # type4 (not superuser)
# self.p_study = [403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 200, 403, 403, 403, 403, 200, 302] # type5
self.p_prv = [403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 200, 200, 403, 403, 200, 302] # 6
self.p_student = [403, 403, 403, 403, 403, 403, 403, 403, 200, 200, 403, 403, 403, 403, 403, 403, 403, 403, 302] # any student
self.p_studentnotpriv= [403, 403, 403, 403, 403, 403, 403, 403, 200, 403, 403, 403, 403, 403, 403, 403, 403, 403, 302] # student without private proposal
self.p_download_share= [404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 403] # used to test filesdownload (with sharelink proposals)
self.p_404 = [404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 302] # used to test filesdownload
def create_groups(self):
"""
Create all groups for the system.
:param self:
:return:
"""
# setup all groups
self.group_names = [
'type1staff', # project responsible
'type2staff', # project assistant
'type2staffunverified', # unverified assistant
'type3staff', # support staff
'type4staff', # Capacity group administration
'type5staff', # Study advisor
'type6staff', # Prof skill administration
'type7staff', # STU/ESA assessor for presentations
]
for g in self.group_names:
group, created = Group.objects.get_or_create(name=g)
assert created
# make group object accessable as a class variable. < self.type1staff > etc.
setattr(self, g, group)
def create_users(self):
"""
Takes self.usernames and creates users based on this. The last character of the username determnines the group
WARNING: This only generates users and assign groups.
It does not assign roles (like groupadministration and trackhead models).
"""
# create testusers using the naming-patern: [r t]-[s p 1 2 u 3 t ]
# r=random (any person of the given type), t=this(for this project)
# 1=type1, 2=type2, 3=type3, s=Student, u=Unverified-type2, h=track-Head, p=Private-student
self.usernames = [
'r-1', # responsible staff
't-1', # responsible staff
'r-h', # responsible staff, trackhead
't-h', # responsible staff, trackhead
'r-2', # assistant
't-2', # assistant
't-u', # unverified assistant
'r-3', # support staff
'r-s', # student without private proposal
't-p', # student with private proposal
'r-4', # Capacity group administration of other group than tested proposal
't-4', # Capacity group administration of group of tested proposal
'r-5', # Study advisor
'r-6', # Prof skill administration
'r-7', # STU/ESA presentation assessor
'ra-1', # type1 and assessor of other project
'ta-1', # type1 and assessor of project
'sup', # god user (superuser)
'ano', # anonymous user
]
# Create the users and assign groups/roles.
self.users = {}
for n in self.usernames:
if n != 'ano':
u = User(username=n)
u.email = n + '@' + settings.STAFF_EMAIL_DOMAINS[0]
u.save()
x = n.split('-')[-1]
if x == '1':
u.groups.add(self.type1staff)
elif x == 'h': # trackhead
u.groups.add(self.type1staff)
elif x == '2':
u.groups.add(self.type2staff)
elif x == 'u':
u.groups.add(self.type2staffunverified)
elif x == '3':
u.groups.add(self.type3staff)
elif x == '4':
u.groups.add(self.type4staff)
elif x == '5':
u.groups.add(self.type5staff)
elif x == '6':
u.groups.add(self.type6staff)
elif x == '7':
u.groups.add(self.type7staff)
elif n == 'sup':
u.groups.add(self.type3staff)
u.is_superuser = True
u.is_staff = True
else: # student
u.email = n + '@' + settings.STUDENT_EMAIL_DOMAINS[0]
u.save()
self.users[n] = u
m = UserMeta(User=u,
EnrolledBEP=True, )
m.save()
m.TimeSlot.add(self.ts)
m.save()
ua = UserAcceptedTerms(User=u)
ua.save()
def links_in_view_test(self, sourceurl, skip=[]):
"""
Find all links in a response and check if they return status 200.
:param sourceurl: the page which is parsed to test the links on the page.
:param skip: urls to not test
:return:
"""
for user in self.users.values():
if self.debug:
print(user)
if (user.username == 't-u' or user.username == 'r-u') and \
self.tp.Description > 3:
# ignore unverfied assistants in later timephases
continue
if (user.username == 't-p' or user.username == 't-s') and \
self.tp.Description < 3:
# ignore students in first timephases
continue
self.client.force_login(user)
self.proposal.Status = 4
self.privateproposal.Status = 4
self.status = 4
self.proposal.save()
self.privateproposal.save()
self.view_test_status(sourceurl, 200)
response = self.client.get(sourceurl)
urls = re.findall('/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/',
str(response.content))
urls = [x for x in urls if (">" not in x
and "<" not in x
and "//" not in x
and "/static/" not in x
and "/logout/" not in x
and "tracking/live/" not in x
and "tracking/viewnumber/" not in x
and "js_error_hook" not in x
and x not in skip)]
for link in urls: # select the url in href for all a tags(links)
if link in skip:
continue
if self.debug:
print('url: {}'.format(link))
self.proposal.Status = 4
self.privateproposal.Status = 4
self.status = 4
self.proposal.save()
self.privateproposal.save()
self.info['user'] = user.username
self.view_test_status(link, 200)
self.client.logout()
def loop_phase_code_user(self, phases, codes):
"""
Loop over the given phases and test with all codes
:param phases:
:param codes: list of views and expected status codes
:return:
"""
assert isinstance(phases, list) or isinstance(phases, range)
for phase in phases:
if phase != get_timephase_number():
if phase == -1:
self.tp.Begin = datetime.now() + timedelta(days=1)
self.tp.save()
self.info['phase'] = 'No Phase'
else:
self.tp.Begin = datetime.now()
self.tp.Description = phase
self.tp.save()
self.info['phase'] = str(phase)
if self.debug:
print("Testing phase {}".format(phase))
self.loop_code_user(codes)
def loop_code_user(self, codes):
"""
Test all views for all users
:param codes: list of views and expected status codes
:return:
"""
for page, status in codes:
if self.debug:
self.info['reverse'] = str(page)
self.info['statuscodes'] = status
view = self.app + ":" + page[0]
if any(isinstance(i, list) for i in status):
# we're dealing with proposals status tests here
ProjectViewsTestGeneral.loop_user_status(self, view, status, page[1])
else:
# normal test without proposals
self.loop_user(view, status, page[1])
# remove the page from the list of urls of this app.
if page[0] in self.allurls: self.allurls.remove(page[0])
def loop_user(self, view, status, kw=None):
"""
Loop over the provided pages with status code for each user and test these.
:param view: name of the page, for reverse view
:param status: array of http status that is expected for each user
:param kw: keyword args for the given view.
:return:
"""
for i, username in enumerate(self.usernames):
self.info['user'] = username
self.info['kw'] = kw
if self.debug:
self.info['user-index'] = i
# log the user in
if username != 'ano':
u = User.objects.get(username=username)
if self.debug:
self.info['user-groups'] = u.groups.all()
self.info['user-issuper'] = u.is_superuser
self.client.force_login(u)
self.view_test_status(reverse(view, kwargs=kw), status[i])
if username != 'ano':
self.client.logout()
def view_test_status(self, link, expected):
"""
Test a given view
:param self: the instance for the testcase class, containing self.client, the testclient instance.
:param link: a link to a view to test
:param expected: the expected response code
:return:
"""
try:
response = self.client.get(link)
response_code = response.status_code
if response_code == 403 or expected == 403:
try:
exception = list(response.context[0])[0]["exception"]
except:
try:
exception = list(response.context[0])[0]["Message"]
except:
# exception = response.context # this is a large amount of information
exception = 'Reason not found in context!'
self.info['exception'] = exception
else:
if response_code == 404:
for d in response.context.dicts:
try:
self.info['exception'] = d['Message']
break
except:
continue
else:
self.info['exception'] = "no 403"
except Exception as e:
response_code = 500
print("Error: {}".format(e))
self.info['exception'] = '500'
traceback.print_exc(file=sys.stdout)
self.assertEqual(response_code, expected,
msg='Expected status code {} but got {} for {} info: {}.'
.format(expected, response_code, link, self.info))
class ProjectViewsTestGeneral(ViewsTest):
"""
Functions to test pages related to proposals/projects
"""
def setUp(self):
"""
Initialization test data for proposals/projects
:param self: self
:return:
"""
# create users and groups in parent function
super(ProjectViewsTestGeneral, self).setUp()
# Random track head r-h
rth = User.objects.get(username='r-h')
rt = Track(Name='Smart Sustainable', ShortName='SSS', Head=rth)
rt.save()
# The proposal used for testing
self.proposal = Proposal(Title="testproposal",
ResponsibleStaff=self.users.get('t-1'),
Group=CapacityGroup.objects.all()[0],
NumStudentsMin=1,
NumStudentsMax=1,
GeneralDescription="Test general description",
StudentsTaskDescription="Test student task description",
Status=1,
Track=self.track,
TimeSlot=self.ts,
)
self.proposal.save()
self.p = self.proposal.id
self.proposal.Assistants.add(self.users.get('t-2'))
self.proposal.Assistants.add(self.users.get('t-u'))
self.proposal.save()
# make private proposal
self.privateproposal = Proposal(Title="privateproposaltest",
ResponsibleStaff=self.users.get('t-1'),
Group=CapacityGroup.objects.all()[0],
NumStudentsMin=1,
NumStudentsMax=1,
GeneralDescription="Test general description",
StudentsTaskDescription="Test student task description",
Status=1,
Track=self.track,
TimeSlot=self.ts,
)
self.privateproposal.save()
self.ppriv = self.privateproposal.id
self.privateproposal.Assistants.add(self.users.get('t-2'))
self.privateproposal.Assistants.add(self.users.get('t-u'))
self.privateproposal.Private.add(self.users.get('t-p'))
self.privateproposal.save()
# make a distribution, this gets id 1.
self.distribution_random = Distribution(
Proposal=self.proposal,
Student=self.users['r-s'], # assign the student without private proposal
TimeSlot=self.ts,
)
self.distribution_random.save()
dp = Distribution(
Proposal=self.privateproposal,
Student=self.users['t-p'], # assign the student with private proposal
TimeSlot=self.ts,
)
dp.save()
self.results_options = ResultOptions(
TimeSlot=self.ts
)
self.results_options.save()
po = PresentationOptions(
TimeSlot=self.ts,
)
po.save()
r = Room(
Name='Test-room',
)
r.save()
# one presentation set with two presentationtimeslots. ta-1 is assessor of the set.
p = PresentationSet(
PresentationOptions=po,
PresentationRoom=r,
AssessmentRoom=r,
DateTime=timezone.now(),
)
p.save()
p.Assessors.add(self.users['ta-1'])
# presentation timeslot student r
ptsr = PresentationTimeSlot(
Presentations=p,
Distribution=self.distribution_random,
DateTime=timezone.now() + timedelta(hours=2)
)
ptsr.save()
# presentation timeslot student p
ptsp = PresentationTimeSlot(
Presentations=p,
Distribution=dp,
DateTime=timezone.now() + timedelta(hours=3)
)
ptsp.save()
def loop_user_status(self, view, status, kw=None):
"""
Test all users and proposal status for a given page. Called from self.all_pages_test()
:param view: name of the page, for reverse view
:param status: array of http status that is expected for each user
:param kw: keyword args for the given view.
:return:
"""
assert isinstance(status, list)
for i, username in enumerate(self.usernames):
self.info['user'] = username
self.info['kw'] = kw
if self.debug:
self.info['user-index'] = i
if username != 'ano':
# log the user in
u = User.objects.get(username=username)
if self.debug:
self.info['user-groups'] = u.groups.all()
self.info['user-issuper'] = u.is_superuser
self.client.force_login(u)
# check for each given status from the status-array
l = len(status)
for status0 in range(0, l):
self.status = status0 + 1
self.info['status'] = self.status
# Expected response code
expected = status[status0][i]
# Reset the project status, because it changes after a test call to upgrade/downgrade
self.proposal.Status = self.status
self.proposal.save()
self.privateproposal.Status = self.status
self.privateproposal.save()
self.view_test_status(reverse(view, kwargs=kw), expected)
# user logout
if username != 'ano':
self.client.logout()