示例#1
0
    def test_lti_id_model_logic(self):
        # Test if a single lTI id can only be coupled to a singular assignment
        ltiAssignment1 = factory.LtiAssignment()
        ltiAssignment2 = factory.LtiAssignment()
        assert ltiAssignment1.active_lti_id != ltiAssignment2.active_lti_id, \
            'LTI ids of generated assignments should be unique.'

        ltiAssignment2.active_lti_id = ltiAssignment1.active_lti_id
        self.assertRaises(
            ValidationError,
            ltiAssignment2.save,
            msg=
            'lti_id_set and assignment should be unique together for each arrayfield value'
        )

        assert ltiAssignment2.active_lti_id in ltiAssignment2.lti_id_set, \
            'LTI ids added to the assignment should als be added to the lti_id_set'

        journal = factory.Journal(assignment=ltiAssignment1)
        journal.grade_url = 'Not None'
        journal.sourcedid = 'Not None'
        journal.save()
        ltiAssignment1.active_lti_id = 'new lti id'
        ltiAssignment1.save()
        # Refresh the journal instance after the assignment update
        journal = Journal.objects.get(pk=journal.pk)

        assert journal.grade_url is None and journal.sourcedid is None, \
            'Updating the active LTI id of an assignment should reset the grade_url and sourcedid of all nested ' \
            'journals'
示例#2
0
    def setUp(self):
        self.admin = factory.Admin()
        self.student = factory.Student()
        self.journal = factory.Journal(user=self.student)
        self.TA = factory.Student()
        nfac.make_participation(
            user=self.TA,
            course=self.journal.assignment.courses.first(),
            role=self.journal.assignment.courses.first().role_set.get(
                name='TA'))
        self.teacher = self.journal.assignment.courses.first().author
        self.comment = factory.StudentComment(
            entry__node__journal=self.journal)
        self.TA_comment = nfac.make_comment(self.comment.entry, self.TA,
                                            'TA comment', False)
        self.teacher_comment = nfac.make_comment(self.comment.entry,
                                                 self.teacher,
                                                 'Teacher comment', False)
        set_entry_comment_counts(self)

        assert self.teacher.has_permission('can_grade', self.journal.assignment), \
            'Teacher requires can_grade permission in the relevant assignment'
        assert self.TA.has_permission('can_grade', self.journal.assignment), \
            'TA requires can_grade permission in the relevant assignment'
        assert not self.teacher_comment.published, 'Teacher comment should be unpublished.'
        assert not self.TA_comment.published, 'TA comment should be unpublished.'
        assert self.entry_comments == 3, 'Journal should have 3 comments total'
        assert self.entry_published_comments == 1, 'Journal should have 3 comments of which only one is published'
        assert self.entry_unpublished_comments == 2, 'Expected 2 unpublished comments'
示例#3
0
    def setUp(self):
        """Setup."""
        self.factory = RequestFactory()
        self.request = REQUEST.copy()

        self.teacher = factory.LtiTeacher()
        self.student = factory.LtiStudent()

        self.journal = factory.Journal(user=self.student)
        self.assignment = self.journal.assignment
示例#4
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')
示例#5
0
 def setUp(self):
     """Setup."""
     self.student = factory.Student()
     self.teacher = factory.Teacher()
     self.course = factory.LtiCourse(author=self.teacher)
     self.assignment = factory.LtiAssignment(author=self.teacher,
                                             courses=[self.course])
     self.journal = factory.Journal(
         assignment=self.assignment,
         user=self.student,
         sourcedid='f6d552',
         grade_url=
         'https://uvadlo-tes.instructure.com/api/lti/v1/tools/267/grade_passback'
     )
示例#6
0
    def test_copyable(self):
        teacher = factory.Teacher()
        course = factory.Course(author=teacher)
        assignment = factory.TemplateAssignment(courses=[course])
        factory.TemplateFormat(assignment=assignment)
        assignment2 = factory.TemplateAssignment(courses=[course])
        factory.TemplateFormat(assignment=assignment2)
        journal = factory.Journal(assignment=assignment2)
        [factory.Entry(node__journal=journal) for _ in range(4)]

        resp = api.get(self,
                       'assignments/copyable',
                       params={'pk': assignment.pk},
                       user=teacher)['data']
        assert len(resp[0]['assignments']) == 1
        assert resp[0]['course'][
            'id'] == course.id, 'copyable assignments should be displayed'

        before_id = api.get(self,
                            'formats',
                            params={'pk': assignment2.pk},
                            user=teacher)['format']['templates'][0]['id']
        before_from_id = api.get(self,
                                 'formats',
                                 params={'pk': assignment.pk},
                                 user=teacher)['format']['templates'][0]['id']
        resp = api.update(self,
                          'formats/copy',
                          params={
                              'pk': assignment2.pk,
                              'from_assignment_id': assignment.pk
                          },
                          user=teacher)
        after_id = api.get(self,
                           'formats',
                           params={'pk': assignment2.pk},
                           user=teacher)['format']['templates'][0]['id']

        after_from_id = api.get(self,
                                'formats',
                                params={'pk': assignment.pk},
                                user=teacher)['format']['templates'][0]['id']
        assert before_id != after_id, 'Assignment should be changed'
        assert before_from_id == after_from_id, 'From assignment templates should be unchanged'

        assert len(utils.get_journal_entries(
            journal)) == 4, 'Old entries should not be removed'
示例#7
0
    def test_legit_student_from_old_uplink_update_passback(self):
        course = factory.LtiCourse(author=self.teacher,
                                   name=REQUEST['custom_course_name'])
        assignment = factory.LtiAssignment(
            author=self.teacher,
            courses=[course],
            name=REQUEST['custom_assignment_title'])
        student = factory.LtiStudent()
        journal = factory.Journal(user=student)
        assignment = journal.assignment

        journal_exists = Journal.objects.filter(user=student,
                                                assignment=assignment)
        journal_exists = journal_exists.count(
        ) == 1 and journal.pk == journal_exists.first().pk
        assert journal_exists, "The student is assumed to have a single nested journal beforehand"

        journal.grade_url = 'before'
        journal.sourcedid = 'before'
        course.active_lti_id = 'new'
        assignment.active_lti_id = 'new'
        course.save()
        assignment.save()
        journal.save()

        get_jwt(
            self,
            user=student,
            status=200,
            request_body={
                'user_id': student.lti_id,
                'custom_course_id': 'new',
                'custom_assignment_id': 'new',
                'lis_outcome_service_url': REQUEST['lis_outcome_service_url'],
                'lis_result_sourcedid': REQUEST['lis_result_sourcedid'],
            },
            response_value=lti_view.LTI_STATES.FINISH_S.value,
            assert_msg=
            'With a setup assignment, a legitimate student jwt connection should return FINISH_S state',
        )

        journal = Journal.objects.get(user=student, assignment=assignment)
        assert journal.sourcedid == REQUEST['lis_result_sourcedid'], \
            'A legitimate student jwt route should set a journal sourcedid.'
        assert journal.grade_url == REQUEST['lis_outcome_service_url'], \
            'A legitimate student jwt route should set a journal grade_url.'
示例#8
0
    def test_get(self):
        student = factory.Student()
        admin = factory.Admin()
        journal = factory.Journal(user=student)
        teacher = journal.assignment.courses.first().author

        # Test get all users
        api.get(self, 'users', user=student, status=403)
        resp = api.get(self, 'users', user=admin)['users']
        assert len(resp) == User.objects.count(
        ), 'Test if the admin got all the users'

        # Test get own user
        resp = api.get(self, 'users', params={'pk': 0}, user=student)['user']
        assert 'id' in resp, 'Test if the student got userdata'
        assert 'verified_email' in resp, 'Test if the student got all their userdata'

        resp = api.get(self, 'users', params={'pk': 0}, user=admin)['user']
        assert resp[
            'is_superuser'], 'Admin user should be flagged as superuser.'

        # Check if a user cant see other users data
        api.get(self,
                'users',
                params={'pk': admin.pk},
                user=student,
                status=403)

        # Test get user as supervisor
        assert permissions.is_user_supervisor_of(
            teacher, student), 'Teacher should be supervisor of student'
        resp = api.get(self, 'users', params={'pk': student.pk},
                       user=teacher)['user']
        assert 'username' in resp, 'Supervisor can retrieve basic supervisee data'
        assert 'full_name' in resp, 'Supervisor can retrieve basic supervisee data'
        assert 'verified_email' not in resp, 'Supervisor can\'t retrieve all supervisee data'
        assert 'email' not in resp, 'Supervisor can\'t retrieve all supervisee data'

        # Test get user as admin
        resp = api.get(self, 'users', params={'pk': student.pk},
                       user=admin)['user']
        assert 'id' in resp, 'Admin can retrieve basic user data'
        assert 'verified_email' in resp, 'Admin can retrieve all user data'
        assert 'email' in resp, 'Admin can retrieve all user data'
示例#9
0
 def setUp(self):
     self.student = factory.Student()
     self.journal = factory.Journal(user=self.student)
     self.teacher = self.journal.assignment.courses.first().author
示例#10
0
 def setUp(self):
     """Set up the test file."""
     self.journal = factory.Journal()
     self.entries = [
         factory.Entry(node__journal=self.journal) for _ in range(4)
     ]
示例#11
0
    def test_deadline(self):
        journal = factory.Journal(
            assignment__format=factory.TemplateFormatFactory())
        assignment = journal.assignment
        teacher = assignment.courses.first().author
        assignment.points_possible = 10

        resp = api.get(self, 'assignments/upcoming',
                       user=journal.user)['upcoming']
        assert resp[0]['deadline']['name'] == 'End of assignment', \
            'Default end of assignment should be shown'

        resp = api.get(self, 'assignments/upcoming', user=teacher)['upcoming']
        assert resp[0]['deadline']['date'] is None, \
            'Default no deadline for a teacher be shown'

        progress = VLE.factory.make_progress_node(
            assignment.format,
            timezone.now() + datetime.timedelta(days=3), 7)
        utils.update_journals(assignment.journal_set.all(), progress)

        resp = api.get(self, 'assignments/upcoming',
                       user=journal.user)['upcoming']
        assert resp[0]['deadline']['name'] == '0/7 points', \
            'When not having completed an progress node, that should be shown'

        entrydeadline = VLE.factory.make_entrydeadline_node(
            assignment.format,
            timezone.now() + datetime.timedelta(days=1),
            assignment.format.template_set.first())
        utils.update_journals(assignment.journal_set.all(), entrydeadline)

        resp = api.get(self, 'assignments/upcoming',
                       user=journal.user)['upcoming']
        assert resp[0]['deadline']['name'] == assignment.format.template_set.first().name, \
            'When not having completed an entry deadline, that should be shown'

        entry = factory.Entry(node=Node.objects.get(preset=entrydeadline))

        resp = api.get(self, 'assignments/upcoming', user=teacher)['upcoming']
        assert resp[0]['deadline']['date'] is not None, \
            'With ungraded entry a deadline for a teacher be shown'

        api.create(self,
                   'grades',
                   params={
                       'entry_id': entry.pk,
                       'grade': 5,
                       'published': False
                   },
                   user=teacher)
        resp = api.get(self, 'assignments/upcoming', user=teacher)['upcoming']
        assert resp[0]['deadline']['date'] is not None, \
            'With only graded & NOT published entries a deadline for a teacher be shown'

        api.create(self,
                   'grades',
                   params={
                       'entry_id': entry.pk,
                       'grade': 5,
                       'published': True
                   },
                   user=teacher)
        resp = api.get(self, 'assignments/upcoming', user=teacher)['upcoming']
        assert resp[0]['deadline']['date'] is None, \
            'With only graded & published entries no deadline for a teacher be shown'

        resp = api.get(self, 'assignments/upcoming',
                       user=journal.user)['upcoming']
        assert resp[0]['deadline']['name'] == '5/7 points', \
            'With only graded & published entries progres node should be the deadline'

        api.create(self,
                   'grades',
                   params={
                       'entry_id': entry.pk,
                       'grade': 7,
                       'published': True
                   },
                   user=teacher)
        resp = api.get(self, 'assignments/upcoming',
                       user=journal.user)['upcoming']
        assert resp[0]['deadline']['name'] == 'End of assignment', \
            'With full points of progress node, end of assignment should be shown'

        api.create(self,
                   'grades',
                   params={
                       'entry_id': entry.pk,
                       'grade': 10,
                       'published': True
                   },
                   user=teacher)
        resp = api.get(self, 'assignments/upcoming',
                       user=journal.user)['upcoming']
        assert resp[0]['deadline']['name'] is None, \
            'With full points of assignment, no deadline should be shown'