def test_task_track(self): request_info = { 'accept_language': '', 'referer': '', 'username': '******', 'ip': '127.0.0.1', 'agent': 'agent', 'host': 'testserver', } task_info = {str(sentinel.task_key): sentinel.task_value} expected_event_data = dict(task_info) expected_event_data.update(self.event) views.task_track(request_info, task_info, str(sentinel.event_type), self.event) expected_event = { 'timestamp': FROZEN_TIME, 'data': expected_event_data, 'name': str(sentinel.event_type), 'context': { 'username': '******', 'ip': '127.0.0.1', 'agent': 'agent', 'host': 'testserver', 'page': None, 'event_source': 'task' } } actual_event = self.get_event() assert_event_matches(expected_event, actual_event)
def make_track_function(): ''' Make a tracking function that logs what happened. For insertion into ModuleSystem, and used by CapaModule, which will provide the event_type (as string) and event (as dict) as arguments. The request_info and task_info (and page) are provided here. ''' return lambda event_type, event: task_track( request_info, task_info, event_type, event, page='x_module_task')
def _get_track_function_for_task(student, xmodule_instance_args=None, source_page='x_module_task'): """ Make a tracking function that logs what happened. For insertion into ModuleSystem, and used by CapaModule, which will provide the event_type (as string) and event (as dict) as arguments. The request_info and task_info (and page) are provided here. """ # get request-related tracking information from args passthrough, and supplement with task-specific # information: request_info = xmodule_instance_args.get( 'request_info', {}) if xmodule_instance_args is not None else {} task_info = { 'student': student.username, 'task_id': _get_task_id_from_xmodule_args(xmodule_instance_args) } return lambda event_type, event: task_track( request_info, task_info, event_type, event, page=source_page)