class UpdateQuizTest(CourseTestMixin, TestCase): def setUp(self): self.setup_course() self.quiz = QuizFactory(course=self.course) def test_update_quiz(self): url = reverse('update-quiz', kwargs={'pk': self.quiz.pk}) self.client.login(username=self.faculty.username, password='******') response = self.client.get(url) self.assertEqual(response.status_code, 200) response = self.client.post(url, {'title': 'Alpha'}) self.assertEqual(response.status_code, 200) response = self.client.post( url, { 'title': 'Alpha', 'description': 'Quiz updated.', 'multiple_attempts': 3, 'show_answers': 2, 'randomize': True, 'scoring_scheme': 0, 'course': self.quiz.course.pk }) self.quiz.refresh_from_db() self.assertEqual(self.quiz.title, 'Alpha') self.assertEqual(self.quiz.description, 'Quiz updated.') self.assertEqual(self.quiz.multiple_attempts, 3) self.assertTrue(self.quiz.randomize) self.assertEqual(self.quiz.show_answers, 2) self.assertEqual(self.quiz.scoring_scheme, 0)
def test_ordered_questions(self): quiz = QuizFactory(course=self.course, scoring_scheme=0) QuestionFactory(quiz=quiz) QuestionFactory(quiz=quiz) q1 = quiz.question_set.first() # ordinality of q2 is -1 q2 = quiz.question_set.last() q1.ordinality = 1 q1.save() first = quiz.ordered_questions().first() self.assertEqual(quiz.question_set.first().ordinality, 1) self.assertEqual(first, q2)
def setUp(self): self.setup_course() self.quiz = QuizFactory(course=self.course) self.question1 = QuestionFactory(quiz=self.quiz) self.question2 = QuestionFactory(quiz=self.quiz) self.view = LTIAssignmentView() self.view.request = RequestFactory().get('/', {}) self.view.request.user = self.student self.view.kwargs = {}
def test_clone(self): q = QuizFactory(course=self.course, title='cloned quiz') q.question = QuestionFactory(quiz=q) c = q.clone() self.assertNotEqual(q.pk, c.pk) self.assertEqual(q.title, 'cloned quiz') self.assertEqual(c.title, 'cloned quiz (clone)') self.assertEqual(q.scoring_scheme, c.scoring_scheme) self.assertEqual(q.question_set.count(), c.question_set.count()) self.assertNotEqual(q.question_set.first().pk, c.question_set.first().pk) quiz_q = q.question_set.first() clone_q = c.question_set.first() self.assertEqual(quiz_q.marker_set.count(), clone_q.marker_set.count()) self.assertNotEqual(quiz_q.marker_set.first().pk, clone_q.marker_set.first().pk)
def test_whodidit(self): author = UserFactory() quiz = QuizFactory() self.assertEqual(quiz.created_by, None) self.assertEqual(quiz.modified_by, None) mw = WhoDidItMiddleware(get_response) url = reverse('quiz-detail', kwargs={'pk': quiz.pk}) # get operations should leave the object unchanged request = RequestFactory().get(url) request.user = author mw.__call__(request) quiz.refresh_from_db() self.assertEqual(quiz.created_by, None) self.assertEqual(quiz.modified_by, None) # post operations should save the request.user request = RequestFactory().post(url) request.user = author mw.__call__(request) quiz.refresh_from_db() self.assertEqual(quiz.created_by, author) self.assertEqual(quiz.modified_by, author)
def setUp(self): self.setup_course() self.quiz = QuizFactory(course=self.course) self.question1 = QuestionFactory(quiz=self.quiz) self.question2 = QuestionFactory(quiz=self.quiz) self.submission = QuizSubmissionFactory(quiz=self.quiz, user=self.student) self.view = LTISpeedGraderView() self.view.request = RequestFactory().get('/', {}) self.view.request.user = self.student self.view.kwargs = {}
def test_get_data_submitted_twice(self): self.view.kwargs['pk'] = self.quiz.id self.quiz2 = QuizFactory(course=self.course) self.question1 = QuestionFactory(quiz=self.quiz2) self.question2 = QuestionFactory(quiz=self.quiz2) submission = QuizSubmissionFactory(quiz=self.quiz, user=self.student) QuizSubmissionFactory(quiz=self.quiz2, user=self.student) self.view.kwargs['submission_id'] = submission.id response = self.view.get(self.view.request) self.assertFalse(response.context_data['is_faculty']) self.assertEqual(response.context_data['quiz'], self.quiz) self.assertEqual(response.context_data['submission'], submission)
def test_permissions(self): self.setup_course() alt_course = CourseFactory.create() alt_student = UserFactory() alt_faculty = UserFactory() alt_course.group.user_set.add(alt_student) alt_course.group.user_set.add(alt_faculty) alt_course.faculty_group.user_set.add(alt_faculty) quiz = QuizFactory(course=self.course) mixin = UpdateQuizPermissionMixin() mixin.request = RequestFactory().get('/') # failure - quiz does not exist mixin.kwargs = {'pk': 42} self.assertFalse(mixin.test_func()) # success - faculty in our course can edit & delete mixin.kwargs = {'pk': quiz.pk} mixin.request.user = self.faculty self.assertTrue(mixin.test_func()) # failure - student in our course cannot edit or delete mixin.request.user = self.student self.assertFalse(mixin.test_func()) # failure - faculty from another course cannot edit or delete mixin.request.user = alt_faculty self.assertFalse(mixin.test_func()) # failure - student from another course cannot edit or delete mixin.request.user = alt_student self.assertFalse(mixin.test_func()) # failure - superusers can't randomly edit or delete either mixin.request.user = UserFactory(is_staff=True, is_superuser=True) self.assertFalse(mixin.test_func())
def setUp(self): self.setup_course() self.quiz = QuizFactory(course=self.course)
def setUp(self): self.setup_course() self.quiz = QuizFactory(course=self.course) self.question1 = QuestionFactory(quiz=self.quiz) self.submission = QuizSubmissionFactory(quiz=self.quiz, user=self.student)
def setUp(self): self.setup_course() self.quiz = QuizFactory(course=self.course) self.question1 = QuestionFactory(quiz=self.quiz) self.submissions = []
def setUp(self): self.setup_course() self.quiz = QuizFactory(course=self.course) self.question = QuestionFactory(quiz=self.quiz)
class QuizSubmissionTest(CourseTestMixin, TestCase): def setUp(self): self.setup_course() self.quiz = QuizFactory(course=self.course) self.question1 = QuestionFactory(quiz=self.quiz) self.question2 = QuestionFactory(quiz=self.quiz) def test_score_easy_quiz(self): self.quiz.scoring_scheme = 0 self.quiz.save() submission = QuizSubmissionFactory(quiz=self.quiz, user=self.student) response = submission.questionresponse_set.get(question=self.question1) response.selected_position = 4 response.save() correct_marker = response.questionresponsemarker_set.get( marker__correct=True) correct_marker.ordinal = 2 correct_marker.save() self.assertEqual(response.user_question_points(), 0) response = submission.questionresponse_set.get(question=self.question2) response.selected_position = 4 response.save() correct_marker = response.questionresponsemarker_set.get( marker__correct=True) correct_marker.ordinal = 1 correct_marker.save() self.assertEqual(response.user_question_points(), 5) self.assertEqual(submission.user_points(), 5) self.assertEqual(submission.user_score(), 0.5) self.assertEqual(submission.user_score_percent(), 50) def test_score_medium_quiz(self): self.quiz.scoring_scheme = 1 self.quiz.save() self.assertEqual(self.quiz.question_set.count(), 2) submission = QuizSubmissionFactory(quiz=self.quiz, user=self.student) response = submission.questionresponse_set.get(question=self.question1) response.selected_position = 1 response.save() correct_marker = response.questionresponsemarker_set.get( marker__correct=True) correct_marker.ordinal = 2 correct_marker.save() self.assertEqual(response.user_question_points(), -2) self.assertEqual(submission.questionresponse_set.count(), 2) response = submission.questionresponse_set.get(question=self.question2) response.selected_position = 5 response.save() correct_marker = response.questionresponsemarker_set.get( marker__correct=True) correct_marker.ordinal = 1 correct_marker.save() self.assertEqual(response.user_question_points(), 2) self.assertEqual(submission.questionresponse_set.count(), 2) self.assertEqual(submission.user_points(), 0) self.assertEqual(submission.user_score(), 0.0) self.assertEqual(submission.user_score_percent(), 0) def test_i_dont_know(self): submission = QuizSubmissionFactory(quiz=self.quiz, user=self.student) response = submission.questionresponse_set.get(question=self.question1) response.selected_position = 12 response.save() correct_marker = response.questionresponsemarker_set.get( marker__correct=True) correct_marker.ordinal = 2 correct_marker.save() self.assertEqual(response.user_question_points(), 0) response = submission.questionresponse_set.get(question=self.question2) response.selected_position = 12 response.save() correct_marker = response.questionresponsemarker_set.get( marker__correct=True) correct_marker.ordinal = 1 correct_marker.save() self.assertEqual(response.user_question_points(), 0) self.assertEqual(submission.user_points(), 0) self.assertEqual(submission.user_score(), 0.0) self.assertEqual(submission.user_score_percent(), 0)
def test_lowest_question_points(self): quiz = QuizFactory(course=self.course, scoring_scheme=0) QuestionFactory(quiz=quiz) q1 = quiz.question_set.first() self.assertEqual(q1.lowest_question_points(), 0)
def test_show_answers_verbose(self): quiz = QuizFactory(course=self.course, show_answers=0) self.assertEqual(quiz.show_answers_verbose(), 'Never') quiz.show_answers = 1 self.assertEqual(quiz.show_answers_verbose(), 'Immediately after quiz submission')
def test_total_points(self): quiz = QuizFactory(course=self.course, scoring_scheme=0) QuestionFactory(quiz=quiz) QuestionFactory(quiz=quiz) self.assertEqual(quiz.total_points(), 10) quiz.scoring_scheme = 1 quiz.save() self.assertEqual(quiz.total_points(), 6) quiz.scoring_scheme = 2 quiz.save() self.assertEqual(quiz.total_points(), 6)