Beispiel #1
0
    def setUp(self):
        self.user = create_user("user", "password", "*****@*****.**")
        self.client.force_authenticate(user=self.user)

        self.quiz_unpublished = create_quiz(name="quiz 2")
        self.quiz_published = create_quiz(name="quiz 1",
                                          date_published=timezone.now())

        self.question_1 = create_question(
            quiz=self.quiz_published,
            question="What is your favourite color?",
            explanation="Some explanation")
        self.question_2 = create_question(quiz=self.quiz_published,
                                          question="What is your name?",
                                          explanation="Some explanation")

        self.answer_1 = create_question_answer(question=self.question_1,
                                               content='Answer 1',
                                               is_correct=False)
        self.answer_2 = create_question_answer(question=self.question_1,
                                               content='Answer 2',
                                               is_correct=True)
Beispiel #2
0
    def test_get_question_detail_for_not_author(self):
        """Assure questions detail is returned for not author."""
        quiz = create_quiz(name='name',
                           creator=self.user_2,
                           date_published=timezone.now())

        question = create_question(quiz=quiz,
                                   question='...',
                                   explanation='...')

        response = self.client.get(
            reverse('question_detail', args=(quiz.id, question.id)))

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['question'], '...')
Beispiel #3
0
    def setUp(self):
        self.user = create_user(username='******',
                                password='******',
                                email='*****@*****.**')
        self.user_2 = create_user(username='******',
                                  password='******',
                                  email='*****@*****.**')
        self.client.force_authenticate(user=self.user)

        self.quiz = create_quiz(name='Quiz 1', creator=self.user)
        self.question = create_question(quiz=self.quiz,
                                        question='...',
                                        explanation='...')
        self.answer = create_question_answer(question=self.question,
                                             content='...',
                                             is_correct=True)
Beispiel #4
0
    def test_update_question_not_author(self):
        """Assure only author can update question."""
        quiz = create_quiz(name='name', creator=self.user_2)
        question = create_question(quiz=quiz,
                                   question='...',
                                   explanation='...')

        payload_data = {
            'question': 'New one ...',
            'explanation': 'changed explanation'
        }
        response = self.client.put(reverse('question_detail',
                                           args=(quiz.id, question.id)),
                                   data=payload_data)
        question_obj = Question.objects.get(pk=question.id)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(question_obj.question, "...")
Beispiel #5
0
    def test_update_question_by_author(self):
        """Assure author of quiz can update one of its questions."""
        quiz = create_quiz(name='name', creator=self.user)
        question = create_question(quiz=quiz,
                                   question='...',
                                   explanation='...')

        payload_data = {
            'question': 'New one ...',
            'explanation': 'changed explanation'
        }
        response = self.client.put(reverse('question_detail',
                                           args=(quiz.id, question.id)),
                                   data=payload_data)
        question_obj = Question.objects.get(pk=question.id)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(question_obj.question, "New one ...")
        self.assertEqual(response.data['question'], "New one ...")