Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7c480f93
Commit
7c480f93
authored
Nov 05, 2015
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10245 from edx/jia/MA-1044
MA-1044 DiscussionTopic - Added bulk operations
parents
1aac73d6
509b2a44
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
lms/djangoapps/discussion_api/tests/test_views.py
+46
-1
lms/djangoapps/discussion_api/views.py
+4
-1
No files found.
lms/djangoapps/discussion_api/tests/test_views.py
View file @
7c480f93
...
...
@@ -13,6 +13,8 @@ from pytz import UTC
from
django.core.urlresolvers
import
reverse
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
discussion_api
import
api
...
...
@@ -24,7 +26,7 @@ from discussion_api.tests.utils import (
from
student.tests.factories
import
CourseEnrollmentFactory
,
UserFactory
from
util.testing
import
UrlResetMixin
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
):
...
...
@@ -104,6 +106,7 @@ class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
)
@ddt.ddt
@mock.patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_DISCUSSION_SERVICE"
:
True
})
class
CourseTopicsViewTest
(
DiscussionAPIViewTestMixin
,
ModuleStoreTestCase
):
"""Tests for CourseTopicsView"""
...
...
@@ -111,6 +114,32 @@ class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
super
(
CourseTopicsViewTest
,
self
)
.
setUp
()
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
):
response
=
self
.
client
.
get
(
reverse
(
"course_topics"
,
kwargs
=
{
"course_id"
:
"non/existent/course"
})
...
...
@@ -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
@httpretty.activate
...
...
lms/djangoapps/discussion_api/views.py
View file @
7c480f93
...
...
@@ -11,6 +11,7 @@ from rest_framework.views import APIView
from
rest_framework.viewsets
import
ViewSet
from
opaque_keys.edx.keys
import
CourseKey
from
xmodule.modulestore.django
import
modulestore
from
discussion_api.api
import
(
create_comment
,
...
...
@@ -100,7 +101,9 @@ class CourseTopicsView(_ViewMixin, DeveloperErrorViewMixin, APIView):
def
get
(
self
,
request
,
course_id
):
"""Implements the GET method as described in the class docstring."""
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment