예제 #1
0
파일: views.py 프로젝트: ccnmtl/mediathread
    def dispatch(self, request, *args, **kwargs):
        lti = LTI(self.request_type, self.role_type)

        # validate the user via oauth
        user = authenticate(request=request, lti=lti)
        if user is None:
            lti.clear_session(request)
            return render(request, 'lti_auth/fail_auth.html', {})

        # login
        login(request, user)

        # check if course is configured
        try:
            ctx = LTICourseContext.objects.get(
                lms_course_context=lti.course_context())
        except (KeyError, ValueError, LTICourseContext.DoesNotExist):
            return render(
                request,
                'lti_auth/fail_course_configuration.html',
                {
                    'is_instructor': lti.is_instructor(),
                    'is_administrator': lti.is_administrator(),
                    'user': user,
                    'lms_course': lti.course_context(),
                    'lms_course_title': lti.course_title(),
                    'sis_course_id': lti.sis_course_id(),
                    'domain': lti.canvas_domain()
                })

        # add user to the course
        self.join_groups(lti, ctx, user)
        self.lti = lti
        return super(LTIAuthMixin, self).dispatch(request, *args, **kwargs)
예제 #2
0
    def test_verify_session(self):
        lti = LTI('session', 'any')
        request = RequestFactory().post('/lti/')

        with self.assertRaises(LTINotInSessionException):
            request.session = {}
            lti.verify(request)

        request.session = {LTI_SESSION_KEY: True}
        self.assertTrue(lti.verify(request))
예제 #3
0
    def test_verify_session(self):
        lti = LTI('session', 'any')
        request = RequestFactory().post('/lti/')

        with self.assertRaises(LTINotInSessionException):
            request.session = {}
            lti.verify(request)

        request.session = {LTI_SESSION_KEY: True}
        self.assertTrue(lti.verify(request))
예제 #4
0
    def test_verify_any(self):
        lti = LTI('any', 'any')
        request = generate_lti_request()

        with self.settings(PYLTI_CONFIG={'consumers': CONSUMERS}):
            # test_verify_request
            lti.verify(request)
            self.assertTrue(request.session[LTI_SESSION_KEY])

            # test_verify_session
            self.assertTrue(lti.verify(request))
예제 #5
0
    def test_verify_any(self):
        lti = LTI('any', 'any')
        request = generate_lti_request()

        with self.settings(PYLTI_CONFIG={'consumers': CONSUMERS}):
            # test_verify_request
            lti.verify(request)
            self.assertTrue(request.session[LTI_SESSION_KEY])

            # test_verify_session
            self.assertTrue(lti.verify(request))
예제 #6
0
    def test_user_fullname(self):
        lti = LTI('initial', 'any')
        self.assertEquals(lti.user_fullname(), '')

        lti.lti_params = {'user_id': 'student_one'}
        self.assertEquals(lti.user_fullname(), 'student_one')

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_fullname(), 'Foo Bar Baz')
예제 #7
0
    def dispatch(self, request, *args, **kwargs):
        lti = LTI(self.request_type, self.role_type)

        # validate the user via oauth
        user = authenticate(request=request, lti=lti)
        if user is None:
            lti.clear_session(request)
            return render_to_response(
                'lti_auth/fail_auth.html', {},
                context_instance=RequestContext(request))

        # check if course is configured
        try:
            ctx = lti.custom_course_context()
        except (KeyError, ValueError, LTICourseContext.DoesNotExist):
            lti.clear_session(request)
            return render_to_response(
                'lti_auth/fail_course_configuration.html', {},
                context_instance=RequestContext(request))

        # add user to the course
        self.join_groups(lti, ctx, user)

        # login
        login(request, user)

        return super(LTIAuthMixin, self).dispatch(request, *args, **kwargs)
예제 #8
0
    def test_user_roles(self):
        lti = LTI('initial', 'any')
        self.assertEquals(lti.user_roles(), [])

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_roles(), [
            u'urn:lti:instrole:ims/lis/instructor',
            u'urn:lti:instrole:ims/lis/staff'
        ])

        self.assertTrue(lti.is_instructor())
        self.assertFalse(lti.is_administrator())
예제 #9
0
    def test_user_fullname(self):
        lti = LTI('initial', 'any')
        self.assertEquals(lti.user_fullname(), '')

        lti.lti_params = {'user_id': 'student_one'}
        self.assertEquals(lti.user_fullname(), 'student_one')

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_fullname(), 'Foo Bar Baz')
예제 #10
0
    def test_user_roles(self):
        lti = LTI('initial', 'any')
        self.assertEquals(lti.user_roles(), [])

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_roles(), [
            u'urn:lti:instrole:ims/lis/instructor',
            u'urn:lti:instrole:ims/lis/staff'])

        self.assertTrue(lti.is_instructor())
        self.assertFalse(lti.is_administrator())
예제 #11
0
 def test_verify_request(self):
     with self.settings(PYLTI_CONFIG={'consumers': CONSUMERS}):
         request = generate_lti_request()
         lti = LTI('initial', 'any')
         lti.verify(request)
         self.assertTrue(request.session[LTI_SESSION_KEY])
예제 #12
0
    def test_consumers(self):
        lti = LTI('any', 'any')

        with self.settings(PYLTI_CONFIG={'consumers': CONSUMERS}):
            self.assertEquals(lti._consumers(), CONSUMERS)
예제 #13
0
    def test_user_email(self):
        lti = LTI('initial', 'any')
        self.assertIsNone(lti.user_email())

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_email(), '*****@*****.**')
예제 #14
0
    def test_custom_course_context(self):
        lti = LTI('initial', 'any')

        with self.assertRaises(KeyError):
            lti.custom_course_context()

        lti.lti_params = BASE_LTI_PARAMS
        lti.lti_params['custom_course_context'] = 434
        with self.assertRaises(LTICourseContext.DoesNotExist):
            lti.custom_course_context()

        ctx = LTICourseContextFactory()
        lti.lti_params['custom_course_context'] = 'abc'
        with self.assertRaises(ValueError):
            lti.custom_course_context()

        lti.lti_params['custom_course_context'] = ctx.uuid
        with self.assertRaises(LTICourseContext.DoesNotExist):
            lti.custom_course_context()

        ctx.enable = True
        ctx.save()
        self.assertEquals(lti.custom_course_context(), ctx)
예제 #15
0
    def test_consumer_user_id(self):
        lti = LTI('initial', 'any')
        lti.lti_params = BASE_LTI_PARAMS.copy()
        lti.lti_params['oauth_consumer_key'] = '1234567890'

        self.assertEquals(lti.consumer_user_id(), '1234567890-student')
예제 #16
0
    def test_user_email(self):
        lti = LTI('initial', 'any')
        self.assertIsNone(lti.user_email())

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_email(), '*****@*****.**')
예제 #17
0
    def test_consumers(self):
        lti = LTI('any', 'any')

        with self.settings(PYLTI_CONFIG={'consumers': CONSUMERS}):
            self.assertEquals(lti._consumers(), CONSUMERS)
예제 #18
0
 def test_verify_request(self):
     with self.settings(PYLTI_CONFIG={'consumers': CONSUMERS}):
         request = generate_lti_request()
         lti = LTI('initial', 'any')
         lti.verify(request)
         self.assertTrue(request.session[LTI_SESSION_KEY])
예제 #19
0
 def test_init(self):
     lti = LTI('initial', 'any')
     self.assertEquals(lti.request_type, 'initial')
     self.assertEquals(lti.role_type, 'any')
예제 #20
0
 def setUp(self):
     self.lti = LTI('initial', 'any')
     self.lti.lti_params = BASE_LTI_PARAMS.copy()
예제 #21
0
    def test_consumer_user_id(self):
        lti = LTI('initial', 'any')
        lti.lti_params = BASE_LTI_PARAMS.copy()
        lti.lti_params['oauth_consumer_key'] = '1234567890'

        self.assertEquals(lti.consumer_user_id(), '1234567890-student')
예제 #22
0
    def dispatch(self, request, *args, **kwargs):
        lti = LTI(self.request_type, self.role_type)

        # validate the user via oauth
        user = authenticate(request=request, lti=lti)
        if user is None:
            lti.clear_session(request)
            return render(request, 'lti_auth/fail_auth.html', {})

        # login
        login(request, user)

        # check if course is configured
        try:
            ctx = LTICourseContext.objects.get(
                lms_course_context=lti.course_context())
        except (KeyError, ValueError, LTICourseContext.DoesNotExist):
            return render(
                request, 'lti_auth/fail_course_configuration.html', {
                    'is_instructor': lti.is_instructor(),
                    'is_administrator': lti.is_administrator(),
                    'user': user,
                    'lms_course': lti.course_context(),
                    'lms_course_title': lti.course_title(),
                    'sis_course_id': lti.sis_course_id(),
                    'domain': lti.canvas_domain()
                })

        # add user to the course
        self.join_groups(lti, ctx, user)
        self.lti = lti
        return super(LTIAuthMixin, self).dispatch(request, *args, **kwargs)
예제 #23
0
    def test_user_roles(self):
        lti = LTI('initial', 'any')
        self.assertEquals(lti.user_roles(), [])

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_roles(), ['Instructor', 'Staff'])