Commit f8faad69 by Don Mitchell

Add Aside

PLAT-216
parent df1a7f0c
from .acid import AcidBlock, AcidParentBlock from .acid import AcidBlock, AcidParentBlock, AcidAside
...@@ -7,8 +7,8 @@ import webob ...@@ -7,8 +7,8 @@ import webob
from lazy import lazy from lazy import lazy
from mako.lookup import TemplateLookup from mako.lookup import TemplateLookup
from xblock.core import XBlock from xblock.core import XBlock, XBlockAside
from xblock.fields import Scope, Dict, Boolean from xblock.fields import Scope, Dict
from xblock.fragment import Fragment from xblock.fragment import Fragment
...@@ -52,12 +52,10 @@ class FailureResponse(webob.Response): ...@@ -52,12 +52,10 @@ class FailureResponse(webob.Response):
@generate_fields @generate_fields
class AcidBlock(XBlock): class AcidSharedMixin(object):
""" """
A testing block that checks the behavior of the container. A testing block that checks the behavior of the container.
""" """
has_children = False
SUCCESS_CLASS = 'fa fa-check-square-o fa-lg pass' SUCCESS_CLASS = 'fa fa-check-square-o fa-lg pass'
FAILURE_CLASS = 'fa fa-times fa-lg fail' FAILURE_CLASS = 'fa fa-times fa-lg fail'
ERROR_CLASS = 'fa fa-exclamation-triangle fa-lg error' ERROR_CLASS = 'fa fa-exclamation-triangle fa-lg error'
...@@ -84,13 +82,6 @@ class AcidBlock(XBlock): ...@@ -84,13 +82,6 @@ class AcidBlock(XBlock):
""" """
return self.template_lookup.get_template(path).render_unicode(**kwargs) return self.template_lookup.get_template(path).render_unicode(**kwargs)
@lazy
def parent_value(self):
"""
This value is used to test that AcidBlock are visible to their parents.
"""
return random.randint(0, 9999)
def resource_string(self, path): def resource_string(self, path):
"""Handy helper for getting resources from our kit.""" """Handy helper for getting resources from our kit."""
data = pkg_resources.resource_string(__name__, path) data = pkg_resources.resource_string(__name__, path)
...@@ -132,43 +123,6 @@ class AcidBlock(XBlock): ...@@ -132,43 +123,6 @@ class AcidBlock(XBlock):
'handler_url': self.runtime.handler_url(self, 'check_storage', suffix, query) 'handler_url': self.runtime.handler_url(self, 'check_storage', suffix, query)
} }
def fallback_view(self, view_name, context=None): # pylint: disable=W0613
"""
This view is used by the Acid XBlock to test various features of
the runtime it is contained in
"""
scopes = (
scope
for scope in Scope.scopes()
if (view_name not in self.enabled_fields
or scope.name in self.enabled_fields[view_name])
)
scope_test_contexts = []
for scope in scopes:
try:
scope_test_contexts.append(self.setup_storage(scope.name))
except Exception:
logging.warning('Unable to use scope in acid test', exc_info=True)
frag = Fragment(self.render_template(
'html/acid.html.mako',
error_class=self.ERROR_CLASS,
success_class=self.SUCCESS_CLASS,
failure_class=self.FAILURE_CLASS,
unknown_class=self.UNKNOWN_CLASS,
storage_tests=scope_test_contexts,
local_resource_url=self.runtime.local_resource_url(self, 'public/test_data.json'),
))
frag.add_javascript(self.resource_string("static/js/jquery.ajaxq-0.0.1.js"))
frag.add_javascript(self.resource_string('static/js/acid_update_status.js'))
frag.add_javascript(self.resource_string('static/js/acid.js'))
frag.add_css(self.resource_string("static/css/acid.css"))
frag.add_css_url('//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css')
frag.initialize_js('AcidBlock')
return frag
@XBlock.handler @XBlock.handler
def check_storage(self, request, suffix=''): def check_storage(self, request, suffix=''):
""" """
...@@ -227,6 +181,57 @@ class AcidBlock(XBlock): ...@@ -227,6 +181,57 @@ class AcidBlock(XBlock):
return SuccessResponse(self.setup_storage(scope)) return SuccessResponse(self.setup_storage(scope))
class AcidBlock(XBlock, AcidSharedMixin):
"""
A testing block that checks the behavior of the container. The XBlock specific aspects
"""
has_children = False
@lazy
def parent_value(self):
"""
This value is used to test that AcidBlock are visible to their parents.
"""
return random.randint(0, 9999)
def fallback_view(self, view_name, context=None): # pylint: disable=W0613
"""
This view is used by the Acid XBlock to test various features of
the runtime it is contained in
"""
scopes = (
scope
for scope in Scope.scopes()
if (view_name not in self.enabled_fields
or scope.name in self.enabled_fields[view_name])
)
scope_test_contexts = []
for scope in scopes:
try:
scope_test_contexts.append(self.setup_storage(scope.name))
except Exception:
logging.warning('Unable to use scope in acid test', exc_info=True)
frag = Fragment(self.render_template(
'html/acid.html.mako',
error_class=self.ERROR_CLASS,
success_class=self.SUCCESS_CLASS,
failure_class=self.FAILURE_CLASS,
unknown_class=self.UNKNOWN_CLASS,
storage_tests=scope_test_contexts,
local_resource_url=self.runtime.local_resource_url(self, 'public/test_data.json'),
))
frag.add_javascript(self.resource_string("static/js/jquery.ajaxq-0.0.1.js"))
frag.add_javascript(self.resource_string('static/js/acid_update_status.js'))
frag.add_javascript(self.resource_string('static/js/acid.js'))
frag.add_css(self.resource_string("static/css/acid.css"))
frag.add_css_url('//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css')
frag.initialize_js('AcidBlock')
return frag
@staticmethod @staticmethod
def workbench_scenarios(): def workbench_scenarios():
"""A canned scenario for display in the workbench.""" """A canned scenario for display in the workbench."""
...@@ -241,6 +246,49 @@ class AcidBlock(XBlock): ...@@ -241,6 +246,49 @@ class AcidBlock(XBlock):
] ]
class AcidAside(XBlockAside, AcidSharedMixin):
"""
A testing aside
"""
@XBlockAside.aside_for('student_view')
def aside_view(self, block, context=None):
"""
This view is used by the Acid Aside to test various features of
the runtime it is contained in
"""
scopes = (
scope
for scope in Scope.scopes()
if scope.name in self.enabled_fields['student_view']
)
scope_test_contexts = []
for scope in scopes:
try:
scope_test_contexts.append(self.setup_storage(scope.name))
except Exception:
logging.warning('Unable to use scope in acid test', exc_info=True)
frag = Fragment(self.render_template(
'html/aside.html.mako',
usage_id=block.scope_ids.usage_id,
error_class=self.ERROR_CLASS,
success_class=self.SUCCESS_CLASS,
failure_class=self.FAILURE_CLASS,
unknown_class=self.UNKNOWN_CLASS,
storage_tests=scope_test_contexts,
local_resource_url=self.runtime.local_resource_url(self, 'public/test_data.json'),
))
frag.add_javascript(self.resource_string("static/js/jquery.ajaxq-0.0.1.js"))
frag.add_javascript(self.resource_string('static/js/acid_update_status.js'))
frag.add_javascript(self.resource_string('static/js/acid.js'))
frag.add_css(self.resource_string("static/css/acid.css"))
frag.add_css_url('//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css')
frag.initialize_js('AcidBlock')
return frag
@generate_fields @generate_fields
class AcidParentBlock(AcidBlock): class AcidParentBlock(AcidBlock):
""" """
......
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
padding-left: 30px; padding-left: 30px;
} }
.aside-block {
padding-left: 8px;
font-size: smaller;
}
.fail { .fail {
color: red; color: red;
} }
......
<%! import json %>
<div class="aside-block"
data-success-class="${success_class}"
data-failure-class="${failure_class}"
data-error-class="${error_class}"
data-unknown-class="${unknown_class}"
data-local-resource-url="${local_resource_url}"
>
<h6>Acid Aside for ${usage_id}</h6>
<p>JS init function run:
<span class="js-init-run">
<i class="${unknown_class}"></i>
</span>
</p>
<p>Resource Url Test:
<span class="local-resource-test">
<i class="${unknown_class}"></i>
</span>
</p>
<table class='storage-tests'>
<tr>
<th>Scope</th>
<th>Server-side<br>handler_url<br>returned</th>
<th>Server-side<br>handler_url<br>succeeded</th>
<th>Client-side<br>handler_url<br>returned</th>
<th>Client-side<br>handler_url<br>succeeded</th>
</tr>
% for test in storage_tests:
<tr class="scope-storage-test scope-${test['scope']} ${loop.cycle('', 'alt')}"
data-handler-url="${test['handler_url']}"
data-scope="${test['scope']}"
data-value="${test['value']}"
>
<td>${test['scope']}</td>
<td>
<span class="server-storage-test-returned">
<i class="${unknown_class}"></i>
</span>
</td>
<td>
<span class="server-storage-test-succeeded">
<i class="${unknown_class}"></i>
</span>
</td>
<td>
<span class="client-storage-test-returned">
<i class="${unknown_class}"></i>
</span>
</td>
<td>
<span class="client-storage-test-succeeded">
<i class="${unknown_class}"></i>
</span>
</td>
</tr>
% endfor
</table>
</div>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
function AcidBlock(runtime, element) { function AcidBlock(runtime, element) {
function acidData(key) { function acidData(key) {
return $('.acid-block', element).data(key); return $('.acid-block, .aside-block', element).data(key);
} }
function mark(result, selector, subelem, msg) { function mark(result, selector, subelem, msg) {
......
...@@ -31,6 +31,9 @@ setup( ...@@ -31,6 +31,9 @@ setup(
'acid = acid:AcidBlock', 'acid = acid:AcidBlock',
'acid_parent = acid:AcidParentBlock', 'acid_parent = acid:AcidParentBlock',
], ],
'xblock_asides.v1': [
'acid_aside = acid:AcidAside',
]
}, },
package_data=package_data("acid", ["static", "public"]), package_data=package_data("acid", ["static", "public"]),
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment