Commit 1971b9c3 by Piotr Mitros

Tests

parent 857bf365
'''
Tests for the DoneXBlock.
This is nice as a simple example of the edX XBlock test framework.
'''
from openedx.tests.xblock_integration.xblock_testcase import XBlockTestCase
# pylint: disable=abstract-method
class TestDone(XBlockTestCase):
"""
Simple tests for the completion XBlock. We set up a page with two
of the block, make sure the page renders, toggle them a few times,
make sure they've toggled, and reconfirm the page renders.
"""
olx_scenarios = { # Currently not used
"two_done_block_test_case": """<vertical>
<done urlname="done0"/>
<done urlname="done1"/>
</vertical>"""
}
# This is a stop-gap until we can load OLX and/or OLX from
# normal workbench scenarios
test_configuration = [
{
"urlname": "two_done_block_test_case",
"olx": olx_scenarios[0],
"xblocks": [ # Stopgap until we handle OLX
{
'blocktype': 'done',
'urlname': 'done_0'
},
{
'blocktype': 'done',
'urlname': 'done_1'
}
]
}
]
def toggle_button(self, block, data, desired_state):
"""
Make an AJAX call to the XBlock, and assert the state is as
desired.
"""
resp = self.ajax('toggle_button', block, data)
self.assertEqual(resp.status_code, 200)
# pylint: disable=no-member
self.assertEqual(resp.data, {"state": desired_state})
# pylint: disable=unused-argument
def check_response(self, block_urlname, rendering):
"""
Confirm that we have a 200 response code (no server error)
In the future, visual diff test the response.
"""
response = self.render_block(block_urlname)
self.assertEqual(response.status_code, 200)
# To do: Below method needs to be implemented
#self.assertXBlockScreenshot(block_urlname, rendering)
def test_done(self):
"""
Walk through a few toggles. Make sure the blocks don't mix up
state between them, initial state is correct, and final state
is correct.
"""
# We confirm we don't have errors rendering the student view
self.check_response('done_0', 'done-unmarked')
self.check_response('done_1', 'done-unmarked')
# We confirm the block is initially false
self.toggle_button('done_0', {}, False)
self.reset_published_events()
self.toggle_button('done_1', {}, False)
self.assert_no_events_published("edx.done.toggled")
# We confirm we can toggle state both ways
self.reset_published_events()
self.toggle_button('done_0', {'done': True}, True)
self.assert_event_published('edx.done.toggled', event_fields={"done": True})
self.reset_published_events()
self.toggle_button('done_1', {'done': False}, False)
self.assert_event_published('edx.done.toggled', event_fields={"done": False})
self.toggle_button('done_0', {'done': False}, False)
self.assert_grade(0)
self.toggle_button('done_1', {'done': True}, True)
self.assert_grade(1)
# We confirm state sticks around
self.toggle_button('done_0', {}, False)
self.toggle_button('done_1', {}, True)
# And confirm we render correctly
self.check_response('done_0', 'done-unmarked')
self.check_response('done_1', 'done-marked')
...@@ -27,7 +27,10 @@ setup( ...@@ -27,7 +27,10 @@ setup(
entry_points={ entry_points={
'xblock.v1': [ 'xblock.v1': [
'done = done:DoneXBlock', 'done = done:DoneXBlock',
],
'xblock.test.v0': [
'done = done.tests:TestDone'
] ]
}, },
package_data=package_data("done", "static"), package_data=package_data("done", "static"),
) )
\ No newline at end of file
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