Skip to content
Snippets Groups Projects
Commit 01340440 authored by Benjamin Zagorsky's avatar Benjamin Zagorsky
Browse files

slight code reduction

parent 819b8064
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,11 @@ from unittest import TestCase
from mock import MagicMock
from django_auth_lti.verification import is_allowed
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.http import HttpRequest
class TestVerification(TestCase):
def test_is_allowed_config_failure(self):
request = MagicMock(session={"LTI_LAUNCH": None})
request = MagicMock(session={})
allowed_roles = ["admin", "student"]
self.assertRaises(ImproperlyConfigured, is_allowed,
request, allowed_roles, False)
......
......@@ -8,12 +8,12 @@ def is_allowed(request, allowed_roles, raise_exception):
else:
allowed = allowed_roles
lti_params = request.session.get('LTI_LAUNCH', None)
if lti_params is None:
if ("LTI_LAUNCH" not in request.session
or request.session["LTI_LAUNCH"] is None):
# If this is raised, then likely the project doesn't have
# the correct settings or is being run outside of an lti context
raise ImproperlyConfigured("No LTI_LAUNCH vale found in session")
user_roles = lti_params.get('roles', [])
user_roles = request.session['LTI_LAUNCH'].get('roles', [])
is_user_allowed = set(allowed) & set(user_roles)
if not is_user_allowed and raise_exception:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment