9
9
import itertools
10
10
import logging
11
11
from collections import defaultdict
12
+ from datetime import datetime , timedelta
12
13
14
+ from mock import Mock
13
15
from six import iteritems
14
16
15
17
import django .utils .translation
16
18
from django .conf import settings
19
+ from django .contrib .auth .models import User
17
20
from django .core .urlresolvers import reverse
18
21
from django .template import loader as django_template_loader
19
22
from django .templatetags .static import static
@@ -239,8 +242,9 @@ class WorkbenchRuntime(Runtime):
239
242
240
243
A pre-configured instance of this class will be available to XBlocks as
241
244
`self.runtime`.
242
-
243
245
"""
246
+ anonymous_student_id = 'dummydummy000-fake-fake-dummydummy00' # Needed for the LTI XBlock
247
+ hostname = '127.0.0.1:8000' # Arbitrary value, needed for the LTI XBlock
244
248
245
249
def __init__ (self , user_id = None ):
246
250
# TODO: Add params for user, runtime, etc. to service initialization
@@ -264,8 +268,50 @@ def __init__(self, user_id=None):
264
268
self .id_generator = ID_MANAGER
265
269
self .user_id = user_id
266
270
271
+ def get_user_role (self ):
272
+ """Provide a dummy user role."""
273
+ return 'Student'
274
+
275
+ @property
276
+ def descriptor_runtime (self ):
277
+ """Provide a dummy course."""
278
+ course = Mock (
279
+ lti_passports = ['test:test:secret' ],
280
+ display_name_with_default = 'Test Course' ,
281
+ display_org_with_default = 'edX' ,
282
+ )
283
+
284
+ return Mock (modulestore = Mock (
285
+ get_course = Mock (return_value = course )
286
+ ))
287
+
288
+ def get_real_user (self , _ ):
289
+ """
290
+ Return a dummy user with a Mock profile.
291
+
292
+ Expected by the LTI Consumer XBlock.
293
+ """
294
+ u = User ()
295
+ u .profile = Mock ()
296
+ u .profile .name = 'John Doe'
297
+ return u
298
+
299
+ def _patch_xblock (self , block ):
300
+ """Add required attributes by some legacy XBlocks such as the LTI Consumer XBlock."""
301
+ block .location = Mock (html_id = Mock (return_value = 'course-v1:edX+Demo+2020' ))
302
+ block .course_id = block .location .html_id ()
303
+ block .due = datetime .utcnow ()
304
+ block .graceperiod = timedelta (seconds = 0 )
305
+ block .category = 'chapter'
306
+
307
+ def handle (self , block , handler_name , request , suffix = '' ):
308
+ """Patch the XBlock with required fields."""
309
+ self ._patch_xblock (block )
310
+ return super (WorkbenchRuntime , self ).handle (block , handler_name , request , suffix )
311
+
267
312
def render (self , block , view_name , context = None ):
268
313
"""Renders using parent class render() method"""
314
+ self ._patch_xblock (block )
269
315
try :
270
316
return super (WorkbenchRuntime , self ).render (block , view_name , context )
271
317
except NoSuchViewError :
0 commit comments