Commit 7c480f93 by Nimisha Asthagiri

Merge pull request #10245 from edx/jia/MA-1044

MA-1044 DiscussionTopic - Added bulk operations
parents 1aac73d6 509b2a44
...@@ -13,6 +13,8 @@ from pytz import UTC ...@@ -13,6 +13,8 @@ from pytz import UTC
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from rest_framework.test import APIClient from rest_framework.test import APIClient
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from common.test.utils import disable_signal from common.test.utils import disable_signal
from discussion_api import api from discussion_api import api
...@@ -24,7 +26,7 @@ from discussion_api.tests.utils import ( ...@@ -24,7 +26,7 @@ from discussion_api.tests.utils import (
from student.tests.factories import CourseEnrollmentFactory, UserFactory from student.tests.factories import CourseEnrollmentFactory, UserFactory
from util.testing import UrlResetMixin from util.testing import UrlResetMixin
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, ItemFactory
class DiscussionAPIViewTestMixin(CommentsServiceMockMixin, UrlResetMixin): class DiscussionAPIViewTestMixin(CommentsServiceMockMixin, UrlResetMixin):
...@@ -104,6 +106,7 @@ class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -104,6 +106,7 @@ class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
) )
@ddt.ddt
@mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @mock.patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"""Tests for CourseTopicsView""" """Tests for CourseTopicsView"""
...@@ -111,6 +114,32 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -111,6 +114,32 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
super(CourseTopicsViewTest, self).setUp() super(CourseTopicsViewTest, self).setUp()
self.url = reverse("course_topics", kwargs={"course_id": unicode(self.course.id)}) self.url = reverse("course_topics", kwargs={"course_id": unicode(self.course.id)})
def create_course(self, modules_count, module_store, topics):
"""
Create a course in a specified module store with discussion module and topics
"""
course = CourseFactory.create(
org="a",
course="b",
run="c",
start=datetime.now(UTC),
default_store=module_store,
discussion_topics=topics
)
CourseEnrollmentFactory.create(user=self.user, course_id=course.id)
course_url = reverse("course_topics", kwargs={"course_id": unicode(course.id)})
# add some discussion modules
for i in range(modules_count):
ItemFactory.create(
parent_location=course.location,
category='discussion',
discussion_id='id_module_{}'.format(i),
discussion_category='Category {}'.format(i),
discussion_target='Discussion {}'.format(i),
publish_item=False,
)
return course_url
def test_404(self): def test_404(self):
response = self.client.get( response = self.client.get(
reverse("course_topics", kwargs={"course_id": "non/existent/course"}) reverse("course_topics", kwargs={"course_id": "non/existent/course"})
...@@ -138,6 +167,22 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -138,6 +167,22 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
} }
) )
@ddt.data(
(2, ModuleStoreEnum.Type.mongo, 2, {"Test Topic 1": {"id": "test_topic_1"}}),
(2, ModuleStoreEnum.Type.mongo, 2,
{"Test Topic 1": {"id": "test_topic_1"}, "Test Topic 2": {"id": "test_topic_2"}}),
(2, ModuleStoreEnum.Type.split, 3, {"Test Topic 1": {"id": "test_topic_1"}}),
(2, ModuleStoreEnum.Type.split, 3,
{"Test Topic 1": {"id": "test_topic_1"}, "Test Topic 2": {"id": "test_topic_2"}}),
(10, ModuleStoreEnum.Type.split, 3, {"Test Topic 1": {"id": "test_topic_1"}}),
)
@ddt.unpack
def test_bulk_response(self, modules_count, module_store, mongo_calls, topics):
course_url = self.create_course(modules_count, module_store, topics)
with check_mongo_calls(mongo_calls):
with modulestore().default_store(module_store):
self.client.get(course_url)
@ddt.ddt @ddt.ddt
@httpretty.activate @httpretty.activate
......
...@@ -11,6 +11,7 @@ from rest_framework.views import APIView ...@@ -11,6 +11,7 @@ from rest_framework.views import APIView
from rest_framework.viewsets import ViewSet from rest_framework.viewsets import ViewSet
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from xmodule.modulestore.django import modulestore
from discussion_api.api import ( from discussion_api.api import (
create_comment, create_comment,
...@@ -100,7 +101,9 @@ class CourseTopicsView(_ViewMixin, DeveloperErrorViewMixin, APIView): ...@@ -100,7 +101,9 @@ class CourseTopicsView(_ViewMixin, DeveloperErrorViewMixin, APIView):
def get(self, request, course_id): def get(self, request, course_id):
"""Implements the GET method as described in the class docstring.""" """Implements the GET method as described in the class docstring."""
course_key = CourseKey.from_string(course_id) course_key = CourseKey.from_string(course_id)
return Response(get_course_topics(request, course_key)) with modulestore().bulk_operations(course_key):
response = get_course_topics(request, course_key)
return Response(response)
class ThreadViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet): class ThreadViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet):
......
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