示例#1
0
 def test_create(self):
     api.create(self,
                'participations',
                params=self.create_params,
                user=self.student,
                status=403)
     api.create(self,
                'participations',
                params=self.create_params,
                user=self.teacher)
示例#2
0
    def test_lti_creation(self):
        user_params = factory.UserParams()

        # User creation via LTI requires an LTI_ID
        api.create(self,
                   'users',
                   params={
                       **user_params,
                       **gen_jwt_params(factory.JWTParams(user_id=None))
                   },
                   status=400)

        # Standard LTI user creation
        jwt_params = factory.JWTParams()
        api.create(self,
                   'users',
                   params={
                       **user_params,
                       **gen_jwt_params(jwt_params)
                   })
        user = User.objects.get(username=user_params['username'])
        assert not user.is_test_student, 'A default user created via LTI parameters should not be flagged ' \
            'as a test student.'

        # Can't create two users with the same lti ID
        resp = api.create(
            self,
            'users',
            params={
                **factory.UserParams(),
                **gen_jwt_params(
                    factory.JWTParams(user_id=jwt_params['user_id']))
            },
            status=400)
        assert 'lti id already exists' in resp['description']

        # Test student creation
        user_params = factory.UserParams()
        api.create(self,
                   'users',
                   params={
                       **user_params,
                       **gen_jwt_params(factory.JWTTestUserParams()),
                   })
        user = User.objects.get(username=user_params['username'])
        assert user.is_test_student, 'A user created via LTI parameters without email and with full_name {} should ' \
            'should be flagged as a test student.'.format(settings.LTI_TEST_STUDENT_FULL_NAME)

        # It should be possible to create multiple test students (all without email under the unique contraint)
        api.create(self,
                   'users',
                   params={
                       **factory.UserParams(),
                       **gen_jwt_params(factory.JWTTestUserParams()),
                   })
示例#3
0
    def test_update_journal_entries_vle_state(self):
        """Hopefully doesnt crash."""
        entry = factory.Entry(node__journal=self.journal)
        api.create(self,
                   'grades',
                   params={
                       'entry_id': entry.id,
                       'grade': 0,
                       'published': True
                   },
                   user=self.teacher)
        lti_grade.change_entry_vle_coupling(self.journal, Entry.GRADING)

        entry = Entry.objects.get(pk=entry.pk)
        assert entry.vle_coupling == Entry.GRADING, 'Check if change_entry_vle_coupling works'
示例#4
0
    def test_update(self):
        assignment = api.create(self,
                                'assignments',
                                params=self.create_params,
                                user=self.teacher)['assignment']

        # Try to publish the assignment
        # TODO: Test cannot unpublish when there are entries inside
        api.update(self,
                   'assignments',
                   params={
                       'pk': assignment['id'],
                       'published': True
                   },
                   user=factory.Student(),
                   status=403)
        api.update(self,
                   'assignments',
                   params={
                       'pk': assignment['id'],
                       'published': True
                   },
                   user=self.teacher)
        api.update(self,
                   'assignments',
                   params={
                       'pk': assignment['id'],
                       'published': True
                   },
                   user=factory.Admin())
示例#5
0
    def test_replace_result_no_url(self):
        """Hopefully doesnt crash."""
        entry = factory.Entry(node__journal=self.journal)
        api.create(self,
                   'grades',
                   params={
                       'entry_id': entry.id,
                       'grade': 0,
                       'published': True
                   },
                   user=self.teacher)
        self.journal.sourcedid = None
        self.journal.grade_url = None
        self.journal.save()

        assert lti_grade.replace_result(self.journal) is None
示例#6
0
 def test_journal_stats(self):
     """Test the journal stats functions in the serializer."""
     entries = utils.get_journal_entries(self.journal)
     for entry in entries[1:]:
         api.create(self,
                    'grades',
                    params={
                        'entry_id': entry.id,
                        'grade': 1,
                        'published': True
                    },
                    user=self.journal.assignment.courses.first().author)
     assert self.journal.get_grade() == 3
     self.journal.bonus_points = 5
     self.journal.save()
     assert self.journal.get_grade() == 8
     assert utils.get_submitted_count(entries) == 4
     assert utils.get_graded_count(entries) == 3
示例#7
0
 def test_create(self):
     lti_params = {**self.create_params, **{'lti_id': 'new_lti_id'}}
     resp = api.create(self,
                       'assignments',
                       params=lti_params,
                       user=self.teacher)['assignment']
     assignment = Assignment.objects.get(pk=resp['id'])
     assert assignment.active_lti_id in assignment.lti_id_set, 'lti id should be set in the lti_id_set as well'
     assert assignment.active_lti_id in assignment.courses.first().assignment_lti_id_set, \
         'lti id should be set in the course assignment_lti_id_set as well'
示例#8
0
    def test_create(self):
        api.create(self,
                   'comments',
                   params={
                       'entry_id': self.comment.entry.pk,
                       'text': 'test-create-comment'
                   },
                   user=self.student)

        comment = api.create(self,
                             'comments',
                             params={
                                 'entry_id': self.comment.entry.pk,
                                 'text': 'test-create-comment',
                                 'published': False
                             },
                             user=self.student)['comment']
        assert comment[
            'published'], 'Student should not be able to post unpublished comments'

        comment = api.create(self,
                             'comments',
                             params={
                                 'entry_id': self.comment.entry.pk,
                                 'text': 'test-create-comment',
                                 'published': False
                             },
                             user=self.teacher)['comment']
        assert not comment['published'], 'Comment should not be published'

        comment = api.create(self,
                             'comments',
                             params={
                                 'entry_id': self.comment.entry.pk,
                                 'text': 'test-create-comment',
                                 'published': True
                             },
                             user=self.teacher)['comment']
        assert comment['published'], 'Comment should be published'

        api.create(self,
                   'comments',
                   params={
                       'entry_id': self.comment.entry.pk,
                       'text': 'test-create-comment',
                       'published': True
                   },
                   user=factory.Student(),
                   status=403)

        set_entry_comment_counts(self)
示例#9
0
    def test_create(self):
        # Test courses with same name and abbreviation
        api.create(self,
                   'courses',
                   params=self.create_params,
                   user=self.teacher1)
        api.create(self,
                   'courses',
                   params=self.create_params,
                   user=self.teacher1)

        # Test admin without is_teacher can make a course
        self.admin.is_teacher = False
        self.admin.save()
        api.create(self, 'courses', params=self.create_params, user=self.admin)

        # Check that students cannot make new courses
        api.create(self,
                   'courses',
                   params=self.create_params,
                   user=self.student,
                   status=403)
示例#10
0
    def test_create(self):
        params = dict(self.create_params)

        # Test a valid creation
        resp = api.create(self, 'users', params=params)['user']
        assert 'id' in resp, 'Check if id is in resp'
        assert resp['username'] == params[
            'username'], 'Check if the username is the same'
        user = User.objects.get(username=params['username'])
        assert user.has_usable_password(
        ), 'Normal users should have a usable password.'

        # Test a creation with the same username and email
        resp = api.create(self, 'users', params=params, status=400)

        # Test a non lti creation without email
        params_without_email = {
            'username': '******',
            'password': '******',
            'full_name': 'test user2'
        }
        resp = api.create(self,
                          'users',
                          params=params_without_email,
                          status=400)

        # Test a creation with the different username and same email
        params['username'] = '******'
        params['email'] = self.create_params['email']
        resp = api.create(self, 'users', params=params, status=400)

        # Test a creation with the same username and different email
        params['username'] = self.create_params['username']
        params['email'] = '*****@*****.**'
        resp = api.create(self, 'users', params=params, status=400)

        # Test a creation with the different username and email
        params['username'] = '******'
        params['email'] = '*****@*****.**'
        resp = api.create(self, 'users', params=params)['user']
示例#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'
示例#12
0
    def test_create(self):
        api.create(self, 'roles', user=self.teacher, status=400)

        # Test not author of course
        api.create(self,
                   'roles',
                   params={
                       'course_id': factory.Course().pk,
                       'name': 'name'
                   },
                   user=self.teacher,
                   status=403)
        api.create(self,
                   'roles',
                   params={
                       'course_id': self.course.pk,
                       'name': 'name'
                   },
                   user=self.student,
                   status=403)

        api.create(self,
                   'roles',
                   params={
                       'course_id': self.course.pk,
                       'name': 'name'
                   },
                   user=self.teacher)
        # TODO: Test same name
        # api.create(self, 'roles', params={'course_id': self.course.pk, 'name': 'name'}, user=self.teacher,
        #            status=400)

        # Test invalid permissions
        api.create(self,
                   'roles',
                   params={
                       'course_id': self.course.pk,
                       'name': 'name',
                       'permissions': 'invalid_string'
                   },
                   user=self.teacher,
                   status=400)
        api.create(self,
                   'roles',
                   params={
                       'course_id': self.course.pk,
                       'name': 'name',
                       'permissions': ['invalid', 'list']
                   },
                   user=self.teacher,
                   status=400)
        api.create(self,
                   'roles',
                   params={
                       'course_id': self.course.pk,
                       'name': 'name',
                       'permissions': {
                           'invalid': 'object'
                       }
                   },
                   user=self.teacher,
                   status=400)
        resp = api.create(self,
                          'roles',
                          params={
                              'course_id': self.course.pk,
                              'name': 'name2',
                              'permissions': {
                                  'can_edit_course_roles': True
                              }
                          },
                          user=self.teacher)

        assert resp['role'][
            'can_edit_course_roles'], 'Check if extra permission is also set'