Commit dcf7b6a2 by Jonathan Piacenti

Refactor event tests.

parent 82a02bc3
# Imports ########################################################### # Imports ###########################################################
from ddt import ddt, data from ddt import ddt, data, unpack
from mock import Mock, patch from mock import Mock, patch
from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchElementException
...@@ -366,48 +366,35 @@ class BasicInteractionTest(DefaultDataTestMixin, InteractionTestBase): ...@@ -366,48 +366,35 @@ class BasicInteractionTest(DefaultDataTestMixin, InteractionTestBase):
self.interact_with_keyboard_help() self.interact_with_keyboard_help()
@ddt
class EventsFiredTest(DefaultDataTestMixin, InteractionTestBase, BaseIntegrationTest): class EventsFiredTest(DefaultDataTestMixin, InteractionTestBase, BaseIntegrationTest):
"""
def setUp(self): Tests that the analytics events are fired and in the proper order.
mock = Mock() """
context = patch.object(WorkbenchRuntime, 'publish', mock) # These events must be fired in this order.
context.start() scenarios = (
self.addCleanup(context.stop) {
self.publish = mock 'name': 'edx.drag_and_drop_v2.loaded',
super(EventsFiredTest, self).setUp() 'data': {
def _get_scenario_xml(self): # pylint: disable=no-self-use
return "<vertical_demo><drag-and-drop-v2/></vertical_demo>"
def test_loaded(self):
dummy, name, event_data = self.publish.call_args[0]
self.assertEqual(name, 'edx.drag_and_drop_v2.loaded')
self.assertEqual(
event_data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0', 'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'user_id': 'student_1' 'user_id': 'student_1'
} },
) },
{
def test_picked_up(self): 'name': 'edx.drag_and_drop_v2.item.picked_up',
self.parameterized_item_positive_feedback_on_good_move(self.items_map) 'data': {
dummy, name, event_data = self.publish.call_args_list[1][0]
self.assertEqual(name, 'edx.drag_and_drop_v2.item.picked_up')
self.assertEqual(
event_data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0', 'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'user_id': 'student_1', 'user_id': 'student_1',
'item_id': 0, 'item_id': 0,
} },
) },
{
def test_dropped(self): 'name': 'grade',
self.parameterized_item_positive_feedback_on_good_move(self.items_map) 'data': {'max_value': 1, 'value': (1.0 / 3)},
# Skipping to 3, since 2 is grade event. },
dummy, name, event_data = self.publish.call_args_list[3][0] {
self.assertEqual(name, 'edx.drag_and_drop_v2.item.dropped') 'name': 'edx.drag_and_drop_v2.item.dropped',
self.assertEqual( 'data': {
event_data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0', 'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'input': None, 'input': None,
'is_correct': True, 'is_correct': True,
...@@ -415,34 +402,48 @@ class EventsFiredTest(DefaultDataTestMixin, InteractionTestBase, BaseIntegration ...@@ -415,34 +402,48 @@ class EventsFiredTest(DefaultDataTestMixin, InteractionTestBase, BaseIntegration
'item_id': 0, 'item_id': 0,
'location': u'The Top Zone', 'location': u'The Top Zone',
'user_id': 'student_1', 'user_id': 'student_1',
} },
) },
{
def test_feedback_opened(self): 'name': 'edx.drag_and_drop_v2.feedback.opened',
self.parameterized_item_positive_feedback_on_good_move(self.items_map) 'data': {
dummy, name, event_data = self.publish.call_args_list[4][0]
self.assertEqual(name, 'edx.drag_and_drop_v2.feedback.opened')
self.assertEqual(
event_data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0', 'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'content': u'Correct! This one belongs to The Top Zone.', 'content': u'Correct! This one belongs to The Top Zone.',
'user_id': 'student_1', 'user_id': 'student_1',
'truncated': False, 'truncated': False,
} },
) },
{
def test_feedback_closed(self): 'name': 'edx.drag_and_drop_v2.feedback.closed',
self.parameterized_item_positive_feedback_on_good_move(self.items_map) 'data': {
dummy, name, event_data = self.publish.call_args_list[5][0]
self.assertEqual(name, 'edx.drag_and_drop_v2.feedback.closed')
self.assertEqual(
event_data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0', 'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'user_id': 'student_1', 'user_id': 'student_1',
'manually': False, 'manually': False,
'content': u'Correct! This one belongs to The Top Zone.', 'content': u'Correct! This one belongs to The Top Zone.',
'truncated': False, 'truncated': False,
} },
},
)
def setUp(self):
mock = Mock()
context = patch.object(WorkbenchRuntime, 'publish', mock)
context.start()
self.addCleanup(context.stop)
self.publish = mock
super(EventsFiredTest, self).setUp()
def _get_scenario_xml(self): # pylint: disable=no-self-use
return "<vertical_demo><drag-and-drop-v2/></vertical_demo>"
@data(*enumerate(scenarios)) # pylint: disable=star-args
@unpack
def test_event(self, index, event):
self.parameterized_item_positive_feedback_on_good_move(self.items_map)
dummy, name, published_data = self.publish.call_args_list[index][0]
self.assertEqual(name, event['name'])
self.assertEqual(
published_data, event['data']
) )
......
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