This allows XModules (specifically CombinedOpenEnded) to use ajax_url
during their init functions (which would, before, have thrown an
exception).
[LMS-1493]
Under normal operation, XModules are reloaded on each request from a
student. CombinedOpenEnded modules have code that runs at initialization
that validates the students state. These changes makes that code run
during several long-form unit tests (testing CombinedOpenEnded across
multiple 'requests').
These tests are marked as expectedFailure because they now exhibit the
same failures as observed in [LMS-1493] (namely, the students state gets
reset, because CombinedOpenEnded interprets system.ajax_url raising an
error as meaning that the problem definition and the student answers are
in conflict)
AJAX requests on forums pages occasionally fail (usually when a request
to the comments service times out), but the user is not made aware of
the failure. This manifests as either the system not appearing to store
state (e.g. if an attempt to flag a post fails) or something taking
forever to load. Now, a modal will pop up to alert the user that a
request has failed and instruct them to reload the page.
In the longer term, we should fix each user gesture that results in an
AJAX call to gracefully handle a failure by resetting the state of the
world appropriately and aleritng the user.
JIRA: FOR-37
XBlock Fragments expect unicode strings, and fail on an assertion when
it isn't:
```
2013-11-14 07:55:50,774 ERROR 3788 [django.request] base.py:215 - Internal Server Error: /courses/TestU/TST101/now/courseware/41d55c576a574fde99319420228f7f88/5fef5794e34842f4a2d45ebcdeaa9a3a/
Traceback (most recent call last):
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 20, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 75, in _cache_controlled
response = viewfunc(request, *args, **kw)
File "/edx/app/edxapp/edx-platform/lms/djangoapps/courseware/views.py", line 407, in index
context['fragment'] = section_module.render('student_view')
File "/edx/app/edxapp/venvs/edxapp/src/xblock/xblock/core.py", line 156, in render
return self.runtime.render(self, view, context)
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 903, in render
return block.xmodule_runtime.render(to_render, view_name, context)
File "/edx/app/edxapp/venvs/edxapp/src/xblock/xblock/runtime.py", line 356, in render
frag = view_fn(context)
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/seq_module.py", line 77, in student_view
rendered_child = child.render('student_view', context)
File "/edx/app/edxapp/venvs/edxapp/src/xblock/xblock/core.py", line 156, in render
return self.runtime.render(self, view, context)
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 903, in render
return block.xmodule_runtime.render(to_render, view_name, context)
File "/edx/app/edxapp/venvs/edxapp/src/xblock/xblock/runtime.py", line 356, in render
frag = view_fn(context)
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/vertical_module.py", line 27, in student_view
rendered_child = child.render('student_view', context)
File "/edx/app/edxapp/venvs/edxapp/src/xblock/xblock/core.py", line 156, in render
return self.runtime.render(self, view, context)
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 903, in render
return block.xmodule_runtime.render(to_render, view_name, context)
File "/edx/app/edxapp/venvs/edxapp/src/xblock/xblock/runtime.py", line 356, in render
frag = view_fn(context)
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 464, in student_view
return Fragment(self.get_html())
File "/edx/app/edxapp/venvs/edxapp/src/xblock/xblock/fragment.py", line 34, in __init__
self.add_content(content)
File "/edx/app/edxapp/venvs/edxapp/src/xblock/xblock/fragment.py", line 71, in add_content
assert isinstance(content, unicode)
AssertionError
```
BY writing to stderr, BaseHTTPRequestHandler writes log messages to the
console during testing. This makes the output harder to interpret.
Write the log messages to stdout instead, so that test runners will
suppress them during passing tests, and show them during failing tests.
It would be nice to have a place to write this method just once for the
Youtube and LTI mock servers, but we don't seem to have a place for code
as common as that.