Пример #1
0
    def test_forgot_password(self):
        # Test if no/invalid params crashes
        api.post(self, 'forgot_password', status=404)
        api.post(self,
                 'forgot_password',
                 params={'username': '******'},
                 status=404)
        api.post(self,
                 'forgot_password',
                 params={'email': 'invalid_email'},
                 status=404)

        # Test valid parameters
        resp = api.post(self,
                        'forgot_password',
                        params={'username': self.student.username})
        assert 'An email was sent' in resp['description'], \
            'You should be able to get forgot password mail with only a username'
        resp = api.post(self,
                        'forgot_password',
                        params={'email': self.student.email})
        assert 'An email was sent' in resp['description'], \
            'You should be able to get forgot password mail with only an email'
        resp = api.post(self,
                        'forgot_password',
                        params={'email': self.student.email},
                        user=self.student)
        assert 'An email was sent' in resp['description'], \
            'You should be able to get forgot password mail while logged in'
        resp = api.post(self,
                        'forgot_password',
                        params={'username': self.is_test_student.username},
                        status=400)
        assert 'no known email address' in resp['description'], \
            'Test student without email address cannot retrieve their password via email.'
Пример #2
0
 def test_student_cant_upload_temp_file_to_unrelated_assignment(self):
     api.post(
         self,
         self.upload_url,
         params={
             'file': self.video,
             'assignment_id': self.unrelated_assignment.pk,
             'content_id': 'null'
         },
         user=self.student,
         status=403,
         content_type=MULTIPART_CONTENT,
     )
Пример #3
0
    def test_temp_file_upload_teacher(self):
        api.post(
            self,
            self.upload_url,
            params={
                'file': self.video,
                'assignment_id': self.journal.assignment.pk,
                'content_id': 'null'
            },
            user=self.teacher,
            status=200,
            content_type=MULTIPART_CONTENT,
        )
        user_file = UserFile.objects.get(author=self.teacher.pk,
                                         file_name=self.video.name)
        assert user_file, "The teacher should have succesfully created a temp user file."

        # Cleanup
        user_file.delete()
Пример #4
0
    def test_recover_password(self):
        api.post(self, 'recover_password', status=400)
        # Test invalid token
        api.post(self,
                 'recover_password',
                 params={
                     'username': self.student.username,
                     'recovery_token': 'invalid_token',
                     'new_password': self.valid_pass
                 },
                 status=400)
        # Test invalid password
        token = PasswordResetTokenGenerator().make_token(self.student)
        api.post(self,
                 'recover_password',
                 params={
                     'username': self.student.username,
                     'recovery_token': token,
                     'new_password': '******'
                 },
                 status=400)
        # Test invalid username
        api.post(self,
                 'recover_password',
                 params={
                     'username': factory.Student().username,
                     'recovery_token': token,
                     'new_password': self.valid_pass
                 },
                 status=400)

        # Test everything valid
        api.post(self,
                 'recover_password',
                 params={
                     'username': self.student.username,
                     'recovery_token': token,
                     'new_password': self.valid_pass
                 })
Пример #5
0
 def test_file_upload_needs_actual_file(self):
     response = api.post(
         self,
         self.upload_url,
         params={
             'file': 'not an actual file',
             'assignment_id': self.journal.assignment.pk,
             'content_id': 'null'
         },
         user=self.student,
         status=400,
         content_type=MULTIPART_CONTENT,
     )
     assert "No accompanying file found in the request." in response[
         'description']
Пример #6
0
 def test_send_feedback(self):
     # needs to be logged in
     api.post(self, 'send_feedback', status=401)
     # cannot send without valid email
     api.post(self, 'send_feedback', user=self.not_verified, status=403)
     # Require params
     api.post(self, 'send_feedback', user=self.student, status=400)
     api.post(self,
              'send_feedback',
              params={
                  'topic': 'topic',
                  'feedback': 'feedback',
                  'ftype': 'ftype',
                  'user_agent': 'user_agent',
                  'url': 'url'
              },
              user=self.student)
Пример #7
0
    def test_verify_email(self):
        api.post(self, 'verify_email', status=400)
        # Test invalid token
        api.post(self,
                 'verify_email',
                 params={
                     'username': self.not_verified.username,
                     'token': 'invalid_token'
                 },
                 status=400)
        # Test invalid username
        token = PasswordResetTokenGenerator().make_token(self.not_verified)
        api.post(self,
                 'verify_email',
                 params={
                     'username': factory.Student().username,
                     'token': token
                 },
                 status=400)

        # Test everything valid
        resp = api.post(self,
                        'verify_email',
                        params={
                            'username': self.not_verified.username,
                            'token': token
                        })
        assert VLE.models.User.objects.get(
            pk=self.not_verified.pk).verified_email
        assert 'Success' in resp['description']
        # Test already verified
        token = PasswordResetTokenGenerator().make_token(self.student)
        resp = api.post(self,
                        'verify_email',
                        params={
                            'username': self.student.username,
                            'token': token
                        })
        assert 'already verified' in resp['description']
Пример #8
0
    def test_request_email_verification(self):
        api.post(self, 'request_email_verification', status=401)

        resp = api.post(self, 'request_email_verification', user=self.student)
        assert 'already verified' in resp['description']

        resp = api.post(self,
                        'request_email_verification',
                        user=self.not_verified)
        assert 'email was sent' in resp['description']

        # A test student without email address set can't request email verification
        api.post(self,
                 'request_email_verification',
                 user=self.is_test_student,
                 status=400)
        self.is_test_student.email = '*****@*****.**'
        self.is_test_student.save()
        resp = api.post(self,
                        'request_email_verification',
                        user=self.is_test_student,
                        status=200)
        assert 'email was sent' in resp['description']