コード例 #1
0
    def test_delete_test_user_participation(self):
        test_user = factory.TestUser()
        factory.Participation(user=test_user, course=self.course)
        api.delete(self,
                   'participations',
                   params={
                       'pk': self.course.pk,
                       'user_id': test_user.pk
                   },
                   user=self.teacher)
        assert not User.objects.filter(pk=test_user.pk).exists(), 'A test user should be deleted upon removal from a ' \
            'course, if the test user has no remaining participations.'

        test_user = factory.TestUser()
        factory.Participation(user=test_user, course=self.course)
        factory.Participation(user=test_user, course=factory.Course())
        api.delete(self,
                   'participations',
                   params={
                       'pk': self.course.pk,
                       'user_id': test_user.pk
                   },
                   user=self.teacher)
        assert User.objects.filter(pk=test_user.pk).exists(), 'A test user should not be deleted upon removal from a ' \
            'course, if the test user has remaining participations.'
コード例 #2
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'
コード例 #3
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'
コード例 #4
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()
コード例 #5
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'
     }
コード例 #6
0
    def test_get(self):
        factory.Participation(user=self.teacher2, course=self.course2)

        # Get all courses
        get_resp = api.get(self, 'courses', user=self.teacher1)['courses']
        assert len(
            get_resp
        ) == 2, 'The teacher did not get all the courses it is the author of'
        assert {self.course1.pk, self.course2.pk} == set([c['id'] for c in get_resp]), \
            'The teacher did not get all the courses it is the author of'

        get_resp = api.get(self, 'courses', user=self.teacher2)['courses']
        assert len(
            get_resp
        ) == 2, 'The teacher did not get all the courses it is the author of or is participating in'
        assert is_response(get_resp, self.course2, self.course3), \
            'The teacher did not get all the courses it is the author of'

        # Get author course
        get_resp = api.get(self,
                           'courses',
                           params={'pk': self.course1.pk},
                           user=self.teacher1)

        # Check not participating
        get_resp = api.get(self,
                           'courses',
                           params={'pk': self.course1.pk},
                           user=self.teacher2,
                           status=403)

        # Check participating
        get_resp = api.get(self,
                           'courses',
                           params={'pk': self.course2.pk},
                           user=self.teacher2)