Example #1
0
	def decorated_function(*args, **kwargs):
		try:
			e = exam.getExamByID(kwargs['examsid'])
		except KeyError:
			flash('warning|No exam key was specified.')
			return redirect(url_for('routes_user.dashboard'))
		if not e:
			flash('warning|Exam not found.')
			return redirect(url_for('routes_user.dashboard'))
		if e.coursesid != int(kwargs['coursesid']):
			flash('warning|The courses id does not match the exams id.')
			return redirect(url_for('routes_user.dashboard'))
		g.current_exam = e	# Some stuff
		return f(*args, **kwargs)
c2.addOrUpdateRole(u3.usersid, 'edit')
c3.addOrUpdateRole(u1.usersid, 'own')
c3.addOrUpdateRole(u1.usersid, 'edit')
c3.addOrUpdateRole(u1.usersid, 'own')
c4.addOrUpdateRole(u2.usersid, 'own')
assert c4.getRole(u2.usersid) == 'own'

# Add in some exams
e1 = exam.Exam(name='Exam 1', coursesid=c1.coursesid, layout='DDDD', show_coursename=True, show_directions=True, show_points=False, show_teachername=True)
e2 = exam.Exam(name='Exam 2', coursesid=c1.coursesid, layout='CCCC', show_coursename=True, show_directions=True, show_points=False, show_teachername=True)
e3 = exam.Exam(name='Exam 3', coursesid=c2.coursesid, layout='EDDD', show_coursename=True, show_directions=True, show_points=False, show_teachername=True)
e1.save() 
e2.save()
e3.save()
e3.save() # yes, twice: should run an UPDATE the second time
assert exam.getExamByID(e1.examsid).name == 'Exam 1'

# Add a few shares
key1 = e1.addShareKey()
key2 = e1.addShareKey()
assert key1 != key2
assert key1 in e1.getShareKeys()
assert len(e1.getShareKeys()) == 2
e1.deactivateShareKey(key1)
assert key1 not in e1.getShareKeys()
assert key1 in e1.getDeactivatedKeys()
assert key2 in e1.getShareKeys()

# Add a few sections
s1 = section.Section(name='Section 1', coursesid=c1.coursesid)
s2 = section.Section(name='Section 2', coursesid=c1.coursesid)