def test_faculty_see_submissions(self): if not self.users: self.extra_users() # Create an assignment self.assignment = Assignment(course=self.course, title='Test Assignment', description='Test', due_date=(datetime.date.today() - one_week).isoformat()) self.assignment.save() # Submit it self.submission = AssignmentSubmission( assignment=self.assignment, link='http://example.com', ) self.submission.save() self.submission.users.add(self.users[0]) # Set myself as the faculty for the course. self.course.faculty.add(self.user) self.course.save() response = self.c.get( reverse('courses:assignment_overview', args=[self.assignment.id])) self.assertEquals(len(response.context['submissions']), 1) self.course.faculty.remove(self.user) self.course.save()
def test_delete_submission(self): # We overrode the delete, so we should be testing it self.course.members.add(self.user) self.course.save() assignment = Assignment( course=self.course, title="Test Assignment", description='Test of the description <b>HERE</b>', due_date=(datetime.date.today() + one_week).isoformat()) assignment.save() submission = AssignmentSubmission(assignment=assignment, link="http://www.example.com", notes="Test notes.") submission.save() submission.users.add(self.user) submission.save() s_id = submission.id response = self.c.post(reverse('courses:delete_submission'), {'id': submission.id}) self.assertEquals( response.content, reverse('courses:assignment_overview', kwargs={'pk': assignment.id})) self.assertRaises(AssignmentSubmission.DoesNotExist, AssignmentSubmission.objects.get, pk=s_id)
def test_late(self): self.assignment = Assignment(course=self.course, title='Test Assignment', description='Test', due_date=(datetime.date.today() - one_week).isoformat()) self.assignment.save() self.submission = AssignmentSubmission(assignment=self.assignment, link='http://example.com') self.submission.save()
def test_list(self): assignment = Assignment(course = self.course, title = "Test Assignment", description = 'Test of the description <b>HERE</b>', due_date = (datetime.date.today() + one_week).isoformat()) assignment.save() # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() response = self.c.get(reverse('courses:assignments', kwargs = {'pk':self.course.id})) self.assertEquals(response.status_code, 200) self.assertEquals(response.context['assignments'][0], assignment) # Remove user self.course.faculty.remove(self.user)
def test_faculty_see_submissions(self): if not self.users: self.extra_users() # Create an assignment self.assignment = Assignment(course = self.course, title = 'Test Assignment', description = 'Test', due_date = (datetime.date.today() - one_week).isoformat() ) self.assignment.save() # Submit it self.submission = AssignmentSubmission(assignment = self.assignment, link = 'http://example.com', ) self.submission.save() self.submission.users.add(self.users[0]) # Set myself as the faculty for the course. self.course.faculty.add(self.user) self.course.save() response = self.c.get(reverse('courses:assignment_overview', args = [self.assignment.id])) self.assertEquals(len(response.context['submissions']), 1) self.course.faculty.remove(self.user) self.course.save()
def fill_database(grouped_dict, question_list): """ Fill the database with all specified course contents. :param grouped_dict: A dictionary with a list of each of the assessments and resources. :type grouped_dict: dict(str,list(dict(str, int))) :param question_list: A dictionary with questions. :type question_list: dict(int, list(dict(str, str))) """ for content_type, content in grouped_dict.items(): if content_type == 'assign': Assignment.objects.bulk_create([Assignment(course_id=a['course_id'], name=a['name'], external_id=a['external_id'], version_time=timezone.now()) for a in content]) elif content_type == 'quiz': Quiz.objects.bulk_create([Quiz(course_id=a['course_id'], name=a['name'], external_id=a['external_id'], version_time=timezone.now()) for a in content]) elif content_type == 'choice': Choice.objects.bulk_create([Choice(course_id=a['course_id'], name=a['name'], external_id=a['external_id'], version_time=timezone.now()) for a in content]) else: Resource.objects.bulk_create([Resource(external=False, version_time=timezone.now(), **a) for a in content]) quiz_list = dict(Quiz.objects.values_list("external_id", "pk")) for quiz_id in question_list: course = Quiz.objects.get(pk=quiz_list[quiz_id]).course Question.objects.bulk_create([Question(name=a['question_name'], external_id=a['question_id'], quiz_id=quiz_list[quiz_id], course=course, version_time=timezone.now()) for a in question_list[quiz_id]])
def test_delete_submission(self): # We overrode the delete, so we should be testing it self.course.members.add(self.user) assignment = Assignment(course = self.course, title = "Test Assignment", description = 'Test of the description <b>HERE</b>', due_date = (datetime.date.today() + one_week).isoformat()) assignment.save() submission = AssignmentSubmission(assignment = assignment, link = "http://www.example.com", notes = "Test notes.") submission.save() submission.users.add(self.user) submission.save() s_id = submission.id response = self.c.post(reverse('courses:delete_submission'), {'id': submission.id}) self.assertEquals(response.content, reverse('courses:assignment_overview', kwargs = {'pk': assignment.id})) self.assertRaises(AssignmentSubmission.DoesNotExist, AssignmentSubmission.objects.get, pk = s_id)
def parse_assignment_settings(self, settings): course_id = settings['COURSE_ID'] # assignment_number = settings['ASSIGNMENT_NUMBER'] uniqueString = settings['ASSIGNMENT_TITLE'].strip().upper() c = Course.objects.get(id=course_id) if not c: raise Exception('Course with id %s does not exist.' % (course_id)) try: a = Assignment.objects.get(Course=c, UniqueString=uniqueString) messages.info(self.request, 'Assigment already exists. Updating.') except: messages.info(self.request, 'Assigment does not exists. Creating.') a = Assignment(Course=c, Title=settings['ASSIGNMENT_TITLE']) a.Title = settings['ASSIGNMENT_TITLE'] activation_date = settings['ACTIVATION_DATE'] hard_date = settings['HARD_DATE'] if ('DUE_DATE' in settings.keys()): due_date = settings['DUE_DATE'] else: due_date = False if ('PENALTY_PERCENT' in settings.keys()): penalty_percent = settings['PENALTY_PERCENT'] else: penalty_percent = 0 if not penalty_percent: penalty_percent = 0 if activation_date: a.Activation_date = activation_date if hard_date: a.Hard_date = hard_date a.Due_date = hard_date a.Penalty_percent = penalty_percent if due_date: a.Due_date = due_date a.Penalty_percent = penalty_percent a.save() return a
def test_list(self): assignment = Assignment( course=self.course, title="Test Assignment", description='Test of the description <b>HERE</b>', due_date=(datetime.date.today() + one_week).isoformat()) assignment.save() # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() response = self.c.get( reverse('courses:assignments', kwargs={'pk': self.course.id})) self.assertEquals(response.status_code, 200) self.assertEquals(response.context['assignments'][0], assignment) # Remove user self.course.faculty.remove(self.user)
def test_late(self): self.assignment = Assignment(course = self.course, title = 'Test Assignment', description = 'Test', due_date = (datetime.date.today() - one_week).isoformat() ) self.assignment.save() self.submission = AssignmentSubmission(assignment = self.assignment, link = 'http://example.com') self.submission.save()
def create_assignment(request): course_code = request.GET.get('code') data = {'course_code': course_code} print course_code afile = None if request.method == 'POST' and request.FILES['afile']: afile = request.FILES['afile'] aname = request.POST['aname'] mmarks = request.POST['mmarks'] ddate = request.POST['ddate'] insts = request.POST['insts'] if afile is not None: ccourse = CurrentCourse.objects.get(course_code=course_code) faculty = Faculty.objects.get(username=request.user.username) if not check(dbx, course_code): create_folder(dbx, course_code) ass_folder = os.path.join(course_code, 'assignments') if not check(dbx, ass_folder): create_folder(dbx, ass_folder) result = result = upload_to_dropbox(dbx, afile, afile.name, course_code, datetime.datetime.now(), subfolder='assignments') assignment = Assignment(name=aname, course=ccourse, uploader=faculty, deadline=ddate, filename=afile.name, instructions=insts, max_marks=mmarks) assignment.save() print result return HttpResponseRedirect( "%s?code=%s" % (reverse('faculty:assignments'), course_code)) else: return render(request, 'faculty/create_assignment.html', data)
class AssignmentTest(test_utils.AuthenticatedTest): def setUp(self): super(AssignmentTest, self).setUp() self.semester = Semester(name='Spring', year = '2012', start = datetime.date(2012, 1, 1), end = datetime.date(2012, 5, 1)) self.semester.save() self.course = Course(title='Test Course', number = '101', section = '001', description = 'Test description of a course', semester = self.semester) self.course.save() def tearDown(self): super(AssignmentTest, self).tearDown() self.course.delete() self.semester.delete() def test_create(self): # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() # Test we get the form response = self.c.get(reverse('courses:new_assignment', kwargs = {'pk':self.course.id})) self.assertEquals(response.status_code, 200) response = self.c.post(reverse('courses:new_assignment', kwargs = {'pk':self.course.id}), {'course':self.course.id, 'title':'Test Assignment', 'description':'Test of the description <b>HERE</b>', 'due_date': (datetime.date.today() + one_week).isoformat()}) self.assertEquals(response.status_code, 302) # Remove user self.course.faculty.remove(self.user) def test_list(self): assignment = Assignment(course = self.course, title = "Test Assignment", description = 'Test of the description <b>HERE</b>', due_date = (datetime.date.today() + one_week).isoformat()) assignment.save() # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() response = self.c.get(reverse('courses:assignments', kwargs = {'pk':self.course.id})) self.assertEquals(response.status_code, 200) self.assertEquals(response.context['assignments'][0], assignment) # Remove user self.course.faculty.remove(self.user) def test_submit(self): # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() response = self.c.post(reverse('courses:new_assignment', kwargs = {'pk':self.course.id}), {'course':self.course.id, 'title':'Test Assignment', 'description':'Test of the description <b>HERE</b>', 'due_date': (datetime.date.today() + one_week).isoformat()}) # Remove user self.course.faculty.remove(self.user) self.course.members.add(self.user) self.course.save() assignment = Assignment.objects.get(course = self.course, title = 'Test Assignment') # Test submitting solution response = self.c.post(reverse('courses:submit_assignment', kwargs = {'pk':assignment.id}), {'link':'http://www.example.com', 'notes':'Test notes.',}) self.assertEquals(response.status_code, 302) self.course.members.remove(self.user) def test_faculty_see_submissions(self): if not self.users: self.extra_users() # Create an assignment self.assignment = Assignment(course = self.course, title = 'Test Assignment', description = 'Test', due_date = (datetime.date.today() - one_week).isoformat() ) self.assignment.save() # Submit it self.submission = AssignmentSubmission(assignment = self.assignment, link = 'http://example.com', ) self.submission.save() self.submission.users.add(self.users[0]) # Set myself as the faculty for the course. self.course.faculty.add(self.user) self.course.save() response = self.c.get(reverse('courses:assignment_overview', args = [self.assignment.id])) self.assertEquals(len(response.context['submissions']), 1) self.course.faculty.remove(self.user) self.course.save() def test_late(self): self.assignment = Assignment(course = self.course, title = 'Test Assignment', description = 'Test', due_date = (datetime.date.today() - one_week).isoformat() ) self.assignment.save() self.submission = AssignmentSubmission(assignment = self.assignment, link = 'http://example.com') self.submission.save() def test_delete_submission(self): # We overrode the delete, so we should be testing it self.course.members.add(self.user) self.course.save() assignment = Assignment(course = self.course, title = "Test Assignment", description = 'Test of the description <b>HERE</b>', due_date = (datetime.date.today() + one_week).isoformat()) assignment.save() submission = AssignmentSubmission(assignment = assignment, link = "http://www.example.com", notes = "Test notes.") submission.save() submission.users.add(self.user) submission.save() s_id = submission.id response = self.c.post(reverse('courses:delete_submission'), {'id': submission.id}) self.assertEquals(response.content, reverse('courses:assignment_overview', kwargs = {'pk': assignment.id})) self.assertRaises(AssignmentSubmission.DoesNotExist, AssignmentSubmission.objects.get, pk = s_id) def test_team_submit(self): if not self.users: self.extra_users() # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() response = self.c.post(reverse('courses:new_assignment', kwargs = {'pk':self.course.id}), {'course':self.course.id, 'title':'Test Assignment', 'description':'Test of the description <b>HERE</b>', 'due_date': (datetime.date.today() + one_week).isoformat()}) # Remove user self.course.faculty.remove(self.user) self.course.members.add(self.user) self.course.save() for user in self.users: self.course.members.add(user) self.course.save() assignment = Assignment.objects.get(course = self.course, title = 'Test Assignment') # Test submitting solution response = self.c.post(reverse('courses:team_submit_assignment', kwargs = {'pk':assignment.id}), {'link':'http://www.example.com', 'notes':'Test notes.', 'users':[user.id for user in self.users]}) self.assertEquals(response.status_code, 302) self.course.members.remove(self.user) for user in self.users: self.course.members.remove(user)
class AssignmentTest(test_utils.AuthenticatedTest): def setUp(self): super(AssignmentTest, self).setUp() self.semester = Semester(name='Spring', year='2012', start=datetime.date(2012, 1, 1), end=datetime.date(2012, 5, 1)) self.semester.save() self.course = Course(title='Test Course', number='101', section='001', description='Test description of a course', semester=self.semester) self.course.save() def tearDown(self): super(AssignmentTest, self).tearDown() self.course.delete() self.semester.delete() def test_create(self): # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() # Test we get the form response = self.c.get( reverse('courses:new_assignment', kwargs={'pk': self.course.id})) self.assertEquals(response.status_code, 200) response = self.c.post( reverse('courses:new_assignment', kwargs={'pk': self.course.id}), { 'course': self.course.id, 'title': 'Test Assignment', 'description': 'Test of the description <b>HERE</b>', 'due_date': (datetime.date.today() + one_week).isoformat() }) self.assertEquals(response.status_code, 302) # Remove user self.course.faculty.remove(self.user) def test_list(self): assignment = Assignment( course=self.course, title="Test Assignment", description='Test of the description <b>HERE</b>', due_date=(datetime.date.today() + one_week).isoformat()) assignment.save() # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() response = self.c.get( reverse('courses:assignments', kwargs={'pk': self.course.id})) self.assertEquals(response.status_code, 200) self.assertEquals(response.context['assignments'][0], assignment) # Remove user self.course.faculty.remove(self.user) def test_submit(self): # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() response = self.c.post( reverse('courses:new_assignment', kwargs={'pk': self.course.id}), { 'course': self.course.id, 'title': 'Test Assignment', 'description': 'Test of the description <b>HERE</b>', 'due_date': (datetime.date.today() + one_week).isoformat() }) # Remove user self.course.faculty.remove(self.user) self.course.members.add(self.user) self.course.save() assignment = Assignment.objects.get(course=self.course, title='Test Assignment') # Test submitting solution response = self.c.post( reverse('courses:submit_assignment', kwargs={'pk': assignment.id}), { 'link': 'http://www.example.com', 'notes': 'Test notes.', }) self.assertEquals(response.status_code, 302) self.course.members.remove(self.user) def test_faculty_see_submissions(self): if not self.users: self.extra_users() # Create an assignment self.assignment = Assignment(course=self.course, title='Test Assignment', description='Test', due_date=(datetime.date.today() - one_week).isoformat()) self.assignment.save() # Submit it self.submission = AssignmentSubmission( assignment=self.assignment, link='http://example.com', ) self.submission.save() self.submission.users.add(self.users[0]) # Set myself as the faculty for the course. self.course.faculty.add(self.user) self.course.save() response = self.c.get( reverse('courses:assignment_overview', args=[self.assignment.id])) self.assertEquals(len(response.context['submissions']), 1) self.course.faculty.remove(self.user) self.course.save() def test_late(self): self.assignment = Assignment(course=self.course, title='Test Assignment', description='Test', due_date=(datetime.date.today() - one_week).isoformat()) self.assignment.save() self.submission = AssignmentSubmission(assignment=self.assignment, link='http://example.com') self.submission.save() def test_delete_submission(self): # We overrode the delete, so we should be testing it self.course.members.add(self.user) self.course.save() assignment = Assignment( course=self.course, title="Test Assignment", description='Test of the description <b>HERE</b>', due_date=(datetime.date.today() + one_week).isoformat()) assignment.save() submission = AssignmentSubmission(assignment=assignment, link="http://www.example.com", notes="Test notes.") submission.save() submission.users.add(self.user) submission.save() s_id = submission.id response = self.c.post(reverse('courses:delete_submission'), {'id': submission.id}) self.assertEquals( response.content, reverse('courses:assignment_overview', kwargs={'pk': assignment.id})) self.assertRaises(AssignmentSubmission.DoesNotExist, AssignmentSubmission.objects.get, pk=s_id) def test_team_submit(self): if not self.users: self.extra_users() # Add client user as faculty member self.course.faculty.add(self.user) self.course.save() response = self.c.post( reverse('courses:new_assignment', kwargs={'pk': self.course.id}), { 'course': self.course.id, 'title': 'Test Assignment', 'description': 'Test of the description <b>HERE</b>', 'due_date': (datetime.date.today() + one_week).isoformat() }) # Remove user self.course.faculty.remove(self.user) self.course.members.add(self.user) self.course.save() for user in self.users: self.course.members.add(user) self.course.save() assignment = Assignment.objects.get(course=self.course, title='Test Assignment') # Test submitting solution response = self.c.post( reverse('courses:team_submit_assignment', kwargs={'pk': assignment.id}), { 'link': 'http://www.example.com', 'notes': 'Test notes.', 'users': [user.id for user in self.users] }) self.assertEquals(response.status_code, 302) self.course.members.remove(self.user) for user in self.users: self.course.members.remove(user)