Add teams eventing for search.
TNL-3187
This commit is contained in:
@@ -11,7 +11,7 @@ from flaky import flaky
|
||||
from nose.plugins.attrib import attr
|
||||
from uuid import uuid4
|
||||
|
||||
from ..helpers import UniqueCourseTest, EventsTestMixin
|
||||
from ..helpers import EventsTestMixin, UniqueCourseTest
|
||||
from ...fixtures import LMS_BASE_URL
|
||||
from ...fixtures.course import CourseFixture
|
||||
from ...fixtures.discussion import (
|
||||
@@ -717,10 +717,21 @@ class BrowseTeamsWithinTopicTest(TeamsTabBase):
|
||||
"""
|
||||
# Note: all searches will return 0 results with the mock search server
|
||||
# used by Bok Choy.
|
||||
search_text = 'banana'
|
||||
self.create_teams(self.topic, 5)
|
||||
self.browse_teams_page.visit()
|
||||
search_results_page = self.browse_teams_page.search('banana')
|
||||
self.verify_search_header(search_results_page, 'banana')
|
||||
events = [{
|
||||
'event_type': 'edx.team.searched',
|
||||
'event': {
|
||||
'course_id': self.course_id,
|
||||
'search_text': search_text,
|
||||
'topic_id': self.topic['id'],
|
||||
'number_of_results': 0
|
||||
}
|
||||
}]
|
||||
with self.assert_events_match_during(self.only_team_events, expected_events=events):
|
||||
search_results_page = self.browse_teams_page.search(search_text)
|
||||
self.verify_search_header(search_results_page, search_text)
|
||||
self.assertTrue(search_results_page.get_pagination_header_text().startswith('Showing 0 out of 0 total'))
|
||||
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ from rest_framework.test import APITestCase, APIClient
|
||||
|
||||
from courseware.tests.factories import StaffFactory
|
||||
from common.test.utils import skip_signal
|
||||
from util.testing import EventTestMixin
|
||||
from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory
|
||||
from student.models import CourseEnrollment
|
||||
from util.testing import EventTestMixin
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from .factories import CourseTeamFactory, LAST_ACTIVITY_AT
|
||||
@@ -400,9 +400,12 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase):
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestListTeamsAPI(TeamAPITestCase):
|
||||
class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
|
||||
"""Test cases for the team listing API endpoint."""
|
||||
|
||||
def setUp(self): # pylint: disable=arguments-differ
|
||||
super(TestListTeamsAPI, self).setUp('teams.views.tracker')
|
||||
|
||||
@ddt.data(
|
||||
(None, 401),
|
||||
('student_inactive', 401),
|
||||
@@ -472,6 +475,7 @@ class TestListTeamsAPI(TeamAPITestCase):
|
||||
def test_order_by_with_text_search(self):
|
||||
data = {'order_by': 'name', 'text_search': 'search'}
|
||||
self.verify_names(data, 400, [])
|
||||
self.assert_no_events_were_emitted()
|
||||
|
||||
@ddt.data((404, {'course_id': 'no/such/course'}), (400, {'topic_id': 'no_such_topic'}))
|
||||
@ddt.unpack
|
||||
@@ -510,7 +514,7 @@ class TestListTeamsAPI(TeamAPITestCase):
|
||||
('queryable', ['Search']),
|
||||
('Tonga', ['Search']),
|
||||
('Island', ['Search']),
|
||||
('search queryable', []),
|
||||
('not-a-query', []),
|
||||
('team', ['Another Team', 'Public Profile Team']),
|
||||
)
|
||||
@ddt.unpack
|
||||
@@ -528,6 +532,14 @@ class TestListTeamsAPI(TeamAPITestCase):
|
||||
user='student_enrolled_public_profile'
|
||||
)
|
||||
|
||||
self.assert_event_emitted(
|
||||
'edx.team.searched',
|
||||
course_id=unicode(self.test_course_2.id),
|
||||
search_text=text_search,
|
||||
topic_id=None,
|
||||
number_of_results=len(expected_team_names)
|
||||
)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestCreateTeamAPI(EventTestMixin, TeamAPITestCase):
|
||||
|
||||
@@ -34,8 +34,8 @@ from xmodule.modulestore.django import modulestore
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from eventtracking import tracker
|
||||
from courseware.courses import get_course_with_access, has_access
|
||||
from eventtracking import tracker
|
||||
from student.models import CourseEnrollment, CourseAccessRole
|
||||
from student.roles import CourseStaffRole
|
||||
from django_comment_client.utils import has_discussion_privileges
|
||||
@@ -319,16 +319,15 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView):
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
if 'topic_id' in request.QUERY_PARAMS:
|
||||
topic_id = request.QUERY_PARAMS['topic_id']
|
||||
topic_id = request.QUERY_PARAMS.get('topic_id', None)
|
||||
if topic_id is not None:
|
||||
if topic_id not in [topic['id'] for topic in course_module.teams_configuration['topics']]:
|
||||
error = build_api_error(
|
||||
ugettext_noop('The supplied topic id {topic_id} is not valid'),
|
||||
topic_id=topic_id
|
||||
)
|
||||
return Response(error, status=status.HTTP_400_BAD_REQUEST)
|
||||
result_filter.update({'topic_id': request.QUERY_PARAMS['topic_id']})
|
||||
|
||||
result_filter.update({'topic_id': topic_id})
|
||||
if text_search and CourseTeamIndexer.search_is_enabled():
|
||||
search_engine = CourseTeamIndexer.engine()
|
||||
result_filter.update({'course_id': course_id_string})
|
||||
@@ -346,6 +345,12 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView):
|
||||
self.get_page()
|
||||
)
|
||||
serializer = self.get_pagination_serializer(paginated_results)
|
||||
tracker.emit('edx.team.searched', {
|
||||
"number_of_results": search_results['total'],
|
||||
"search_text": text_search,
|
||||
"topic_id": topic_id,
|
||||
"course_id": course_id_string,
|
||||
})
|
||||
else:
|
||||
queryset = CourseTeam.objects.filter(**result_filter)
|
||||
order_by_input = request.QUERY_PARAMS.get('order_by', 'name')
|
||||
|
||||
Reference in New Issue
Block a user