Beispiel #1
0
    def test_list(self):
        course2 = factory.Course(author=self.teacher)
        factory.Assignment(courses=[self.course])
        factory.Assignment(courses=[self.course, course2])
        assignment = factory.Assignment()

        resp = api.get(self,
                       'assignments',
                       params={'course_id': self.course.pk},
                       user=self.teacher)['assignments']
        assert len(resp) == 2, 'All connected courses should be returned'
        resp = api.get(self,
                       'assignments',
                       params={'course_id': course2.pk},
                       user=self.teacher)['assignments']
        assert len(resp) == 1, 'Not connected courses should not be returned'

        # Connected assignment
        course = assignment.courses.first()
        factory.Participation(user=self.teacher, course=course)
        # Not connected assignment
        factory.Assignment()

        resp = api.get(self, 'assignments', user=self.teacher)['assignments']
        assert len(
            resp
        ) == 3, 'Without a course supplied, it should return all assignments connected to user'
Beispiel #2
0
    def test_get(self):
        student = factory.Student()
        assignment = factory.Assignment(courses=[self.course])

        api.get(self,
                'assignments',
                params={'pk': assignment.pk},
                user=student,
                status=403)
        factory.Participation(user=student,
                              course=self.course,
                              role=Role.objects.get(course=self.course,
                                                    name='Student'))
        resp = api.get(self,
                       'assignments',
                       params={
                           'pk': assignment.pk,
                           'course_id': self.course.pk
                       },
                       user=student)['assignment']
        assert resp[
            'journal'] is not None, 'Response should include student serializer'

        resp = api.get(self,
                       'assignments',
                       params={
                           'pk': assignment.pk,
                           'course_id': self.course.pk
                       },
                       user=self.teacher)['assignment']
        assert resp[
            'journals'] is not None, 'Response should include teacher serializer'
Beispiel #3
0
    def test_get_active_course(self):
        future_course = factory.Course(startdate=timezone.now() +
                                       datetime.timedelta(weeks=2))
        later_future_course = factory.Course(startdate=timezone.now() +
                                             datetime.timedelta(weeks=5))
        assignment = factory.Assignment(
            courses=[future_course, later_future_course])
        assert assignment.get_active_course() == future_course, \
            'Select first upcomming course as there is no LTI course or course that has already started'

        past_course = factory.Course(startdate=timezone.now() -
                                     datetime.timedelta(weeks=5))
        assignment.courses.add(past_course)
        recent_course = factory.Course(startdate=timezone.now() -
                                       datetime.timedelta(weeks=3))
        assignment.courses.add(recent_course)
        assert assignment.get_active_course() == recent_course, \
            'Select most recent course as there is no LTI course'

        lti_course = factory.LtiCourseFactory(startdate=timezone.now() +
                                              datetime.timedelta(weeks=1))
        assignment.courses.add(lti_course)
        assignment.active_lti_id = 'lti_id'
        lti_course.assignment_lti_id_set.append('lti_id')
        lti_course.save()
        assignment.save()
        assert assignment.get_active_course(
        ) == lti_course, 'Select LTI course above all other courses'
Beispiel #4
0
    def test_delete(self):
        teach_course = factory.Course(author=self.teacher)
        other_course = factory.Course()
        assignment = factory.Assignment(
            courses=[self.course, teach_course, other_course])

        # Test no course specified
        api.delete(self,
                   'assignments',
                   params={'pk': assignment.pk},
                   user=self.teacher,
                   status=400)

        # Test normal removal
        resp = api.delete(self,
                          'assignments',
                          params={
                              'pk': assignment.pk,
                              'course_id': teach_course.id
                          },
                          user=self.teacher)
        assert 'removed' in resp['description'] and 'deleted' not in resp['description'], \
            'The assignment should be removed from the course, not deleted'

        # Test if only admins can delete assignments they are not part of
        resp = api.delete(self,
                          'assignments',
                          params={
                              'pk': assignment.pk,
                              'course_id': other_course.id
                          },
                          user=self.teacher,
                          status=403)
        resp = api.delete(self,
                          'assignments',
                          params={
                              'pk': assignment.pk,
                              'course_id': other_course.id
                          },
                          user=self.teacher,
                          status=403)
        resp = api.delete(self,
                          'assignments',
                          params={
                              'pk': assignment.pk,
                              'course_id': other_course.id
                          },
                          user=self.admin,
                          status=200)

        # Test delete
        resp = api.delete(self,
                          'assignments',
                          params={
                              'pk': assignment.pk,
                              'course_id': self.course.id
                          },
                          user=self.teacher)
        assert 'removed' not in resp['description'] and 'deleted' in resp['description'], \
            'The assignment should be deleted from the course, not removed'
Beispiel #5
0
 def setUp(self):
     self.teacher = factory.Teacher()
     self.course = factory.Course(author=self.teacher)
     self.assignment = factory.Assignment(courses=[self.course])
     participation = factory.Participation(course=self.course)
     self.student = participation.user
     self.roles = VLE.models.Role.objects.all()
Beispiel #6
0
 def setUp(self):
     self.student = factory.Student()
     self.journal = factory.Journal(user=self.student)
     self.teacher = self.journal.assignment.courses.first().author
     self.unrelated_assignment = factory.Assignment()
     self.video = SimpleUploadedFile('file.mp4',
                                     b'file_content',
                                     content_type='video/mp4')
     self.student_download_url = reverse('VLE:user-download',
                                         kwargs={'pk': self.student.pk})
     self.upload_url = reverse('VLE:user-upload')
Beispiel #7
0
 def setUp(self):
     self.teacher = factory.Teacher()
     self.course = factory.Course(author=self.teacher)
     factory.Assignment(courses=[self.course])
     participation = factory.Participation(course=self.course)
     self.student = participation.user
     # Username is 4 chartacters for the unenrolled check
     self.not_connected = factory.Student(username='******',
                                          full_name='Not Connected')
     self.create_params = {
         'course_id': self.course.pk,
         'user_id': self.not_connected.pk
     }
     self.group1 = factory.Group(course=self.course)
     self.group2 = factory.Group(course=self.course)
     self.update_params = {
         'pk': self.course.pk,
         'user_id': self.student.pk,
         'role': 'Teacher'
     }
Beispiel #8
0
 def setUp(self):
     self.teacher = factory.Teacher()
     self.admin = factory.Admin()
     self.course = factory.Course(author=self.teacher)
     self.assignment = factory.Assignment(courses=[self.course])
     self.format = factory.Format(assignment=self.assignment)
     self.template = factory.Template(format=self.format)
     self.update_dict = {
         'assignment_details': {
             'name': 'Colloq',
             'description': 'description1',
             'is_published': True
         },
         'templates':
         serialize.TemplateSerializer(
             self.format.template_set.filter(archived=False),
             many=True).data,
         'removed_presets': [],
         'removed_templates': [],
         'presets': []
     }