diff --git a/common/lib/xmodule/xmodule/modulestore/courseware_index.py b/common/lib/xmodule/xmodule/modulestore/courseware_index.py index 48b726d355..ff55b1a721 100644 --- a/common/lib/xmodule/xmodule/modulestore/courseware_index.py +++ b/common/lib/xmodule/xmodule/modulestore/courseware_index.py @@ -3,10 +3,10 @@ from __future__ import absolute_import import logging -from django.conf import settings from django.utils.translation import ugettext as _ from opaque_keys.edx.locator import CourseLocator from search.search_engine_base import SearchEngine +from eventtracking import tracker from . import ModuleStoreEnum from .exceptions import ItemNotFoundError @@ -139,7 +139,7 @@ class CoursewareSearchIndexer(object): Add to courseware search index published section and children """ indexed_count = cls.add_to_search_index(modulestore, location, delete, raise_on_error) - CoursewareSearchIndexer._track_index_request('edx.course.index.published', indexed_count, str(location)) + cls._track_index_request('edx.course.index.published', indexed_count, str(location)) return indexed_count @classmethod @@ -148,7 +148,7 @@ class CoursewareSearchIndexer(object): (Re)index all content within the given course """ indexed_count = cls.add_to_search_index(modulestore, course_key, delete=False, raise_on_error=True) - CoursewareSearchIndexer._track_index_request('edx.course.index.reindexed', indexed_count) + cls._track_index_request('edx.course.index.reindexed', indexed_count) return indexed_count @staticmethod @@ -162,10 +162,6 @@ class CoursewareSearchIndexer(object): None """ - - from eventtracking import tracker as track - tracker = track.get_tracker() - tracking_context = tracker.resolve_context() # pylint: disable=no-member data = { "indexed_count": indexed_count, 'category': 'courseware_index', diff --git a/common/lib/xmodule/xmodule/tests/__init__.py b/common/lib/xmodule/xmodule/tests/__init__.py index 522999cb5c..e8771915b4 100644 --- a/common/lib/xmodule/xmodule/tests/__init__.py +++ b/common/lib/xmodule/xmodule/tests/__init__.py @@ -12,6 +12,7 @@ import os import pprint import unittest import inspect +import mock from contextlib import contextmanager from lazy import lazy @@ -21,6 +22,7 @@ from path import path from eventtracking import tracker from eventtracking.django import DjangoTracker + from xblock.field_data import DictFieldData from xblock.fields import ScopeIds, Scope, Reference, ReferenceList, ReferenceValueDict @@ -56,7 +58,8 @@ class TestModuleSystem(ModuleSystem): # pylint: disable=abstract-method """ ModuleSystem for testing """ - def __init__(self, **kwargs): + @mock.patch('eventtracking.tracker.emit') + def __init__(self, mock_emit, **kwargs): # pylint: disable=unused-argument id_manager = CourseLocationManager(kwargs['course_id']) kwargs.setdefault('id_reader', id_manager) kwargs.setdefault('id_generator', id_manager) diff --git a/lms/static/js/search/views/search_item_view.js b/lms/static/js/search/views/search_item_view.js index 53f9f2e79c..30a5565385 100644 --- a/lms/static/js/search/views/search_item_view.js +++ b/lms/static/js/search/views/search_item_view.js @@ -42,6 +42,7 @@ define([ logSearchItem: function(event) { event.preventDefault(); + var self = this; var target = this.model.id; var link = $(event.target).attr('href'); var collection = this.model.collection; @@ -54,8 +55,9 @@ define([ "search_term": searchTerm, "result_position": (page * pageSize + index), "result_link": target + }).always(function() { + self.redirect(link); }); - this.redirect(link); } }); diff --git a/lms/static/js/spec/search/search_spec.js b/lms/static/js/spec/search/search_spec.js index 34ca36f22d..adc3260515 100644 --- a/lms/static/js/spec/search/search_spec.js +++ b/lms/static/js/spec/search/search_spec.js @@ -2,6 +2,7 @@ define([ 'jquery', 'sinon', 'backbone', + 'logger', 'js/common_helpers/template_helpers', 'js/search/views/search_form', 'js/search/views/search_item_view', @@ -14,6 +15,7 @@ define([ $, Sinon, Backbone, + Logger, TemplateHelpers, SearchForm, SearchItemView, @@ -123,6 +125,7 @@ define([ // Mock the redirect call spyOn(this.item, 'redirect').andCallFake( function() {} ); spyOn(this.item, 'logSearchItem').andCallThrough(); + spyOn(Logger, 'log').andReturn($.Deferred().resolve()); var link = this.item.$el.find('a'); expect(link.length).toBe(1); link.trigger('click');