Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
    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)