Commit 86cce5f0 by Peter Fogg

Add teams eventing for search.

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