Beispiel #1
0
    def test_edit_exam_teacher(self):
        """Teacher edit their exam properly"""
        exam = Exam.query.first()
        teacher = Teacher.get_by_id(exam.author_id)
        # Generate a header for a teacher
        token = generate_user_token(teacher.username, TEACHER_PERMISSIONS)
        from_date = datetime.now().replace(microsecond=0)
        exam_body = {
            'title': '',
            'description': '',
            'exercises': '[]',
            'exam_duration': 300,
            'shuffle_exercises': True,
            'max_retries': 1,
            'from_date': from_date,
            'to_date': from_date + timedelta(days=10)
        }
        res = self.client.patch(f'/api/v1/exams/{exam.id}',
                                headers={'Content-Type': 'application/json',
                                         'Authorization': f'bearer {token}'},
                                json=exam_body)
        self.assertEqual(res.status_code, 200, res.get_json())
        data = res.get_json()
        self.check_fields_list(data, ['success', 'updated'])
        self.assertTrue(data['success'])
        self.assertEqual(data['updated'], exam.id)

        exam = Exam.get_by_id(exam.id)
        for key, value in exam_body.items():
            self.assertEqual(value, getattr(exam, key), f'{key}: {value}')
Beispiel #2
0
 def test_delete_exam_teacher(self):
     """Teacher archiving their exam"""
     exam = Exam.query.first()
     new_exam_dict = generate_random_exam(exam.author_id)
     new_exam = Exam(**new_exam_dict)
     new_exam.insert()
     try:
         teacher = Teacher.get_by_id(new_exam.author_id)
         token = generate_user_token(teacher.username, TEACHER_PERMISSIONS)
         res = self.client.delete(f'/api/v1/exams/{new_exam.id}',
                                  headers={
                                      'Content-Type': 'application/json',
                                      'Authorization': f'bearer {token}'})
         self.assertEqual(res.status_code, 200, res.get_json())
         data = res.get_json()
         self.check_fields_list(data, ['success', 'deleted'])
         self.assertTrue('success')
         self.assertEqual(data['deleted'], new_exam.id)
         self.assertIsNone(Exam.get_by_id(new_exam.id))
     finally:
         new_exam.delete()