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
f3911c44
Commit
f3911c44
authored
May 27, 2015
by
Greg Price
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8198 from edx/gprice/discussion-api-create-thread-following
Add "following" parameter to thread creation
parents
c54952b5
df3e6535
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
4 deletions
+52
-4
lms/djangoapps/discussion_api/api.py
+11
-3
lms/djangoapps/discussion_api/forms.py
+9
-1
lms/djangoapps/discussion_api/tests/test_api.py
+18
-0
lms/djangoapps/discussion_api/tests/utils.py
+11
-0
lms/djangoapps/discussion_api/views.py
+3
-0
No files found.
lms/djangoapps/discussion_api/api.py
View file @
f3911c44
...
@@ -10,6 +10,7 @@ from opaque_keys import InvalidKeyError
...
@@ -10,6 +10,7 @@ from opaque_keys import InvalidKeyError
from
opaque_keys.edx.locator
import
CourseLocator
from
opaque_keys.edx.locator
import
CourseLocator
from
courseware.courses
import
get_course_with_access
from
courseware.courses
import
get_course_with_access
from
discussion_api.forms
import
ThreadCreateExtrasForm
from
discussion_api.pagination
import
get_paginated_data
from
discussion_api.pagination
import
get_paginated_data
from
discussion_api.serializers
import
CommentSerializer
,
ThreadSerializer
,
get_context
from
discussion_api.serializers
import
CommentSerializer
,
ThreadSerializer
,
get_context
from
django_comment_client.base.views
import
(
from
django_comment_client.base.views
import
(
...
@@ -243,17 +244,24 @@ def create_thread(request, thread_data):
...
@@ -243,17 +244,24 @@ def create_thread(request, thread_data):
context
=
get_context
(
course
,
request
)
context
=
get_context
(
course
,
request
)
serializer
=
ThreadSerializer
(
data
=
thread_data
,
context
=
context
)
serializer
=
ThreadSerializer
(
data
=
thread_data
,
context
=
context
)
if
not
serializer
.
is_valid
():
extras_form
=
ThreadCreateExtrasForm
(
thread_data
)
raise
ValidationError
(
serializer
.
errors
)
if
not
(
serializer
.
is_valid
()
and
extras_form
.
is_valid
()):
raise
ValidationError
(
dict
(
serializer
.
errors
.
items
()
+
extras_form
.
errors
.
items
()))
serializer
.
save
()
serializer
.
save
()
thread
=
serializer
.
object
thread
=
serializer
.
object
ret
=
serializer
.
data
following
=
extras_form
.
cleaned_data
[
"following"
]
if
following
:
context
[
"cc_requester"
]
.
follow
(
thread
)
ret
[
"following"
]
=
True
track_forum_event
(
track_forum_event
(
request
,
request
,
THREAD_CREATED_EVENT_NAME
,
THREAD_CREATED_EVENT_NAME
,
course
,
course
,
thread
,
thread
,
get_thread_created_event_data
(
thread
,
followed
=
False
)
get_thread_created_event_data
(
thread
,
followed
=
following
)
)
)
return
serializer
.
data
return
serializer
.
data
lms/djangoapps/discussion_api/forms.py
View file @
f3911c44
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
Discussion API forms
Discussion API forms
"""
"""
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.forms
import
CharField
,
Form
,
IntegerField
,
NullBooleanField
from
django.forms
import
BooleanField
,
CharField
,
Form
,
IntegerField
,
NullBooleanField
from
opaque_keys
import
InvalidKeyError
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.locator
import
CourseLocator
from
opaque_keys.edx.locator
import
CourseLocator
...
@@ -37,6 +37,14 @@ class ThreadListGetForm(_PaginationForm):
...
@@ -37,6 +37,14 @@ class ThreadListGetForm(_PaginationForm):
raise
ValidationError
(
"'{}' is not a valid course id"
.
format
(
value
))
raise
ValidationError
(
"'{}' is not a valid course id"
.
format
(
value
))
class
ThreadCreateExtrasForm
(
Form
):
"""
A form to handle fields in thread creation that require separate
interactions with the comments service.
"""
following
=
BooleanField
(
required
=
False
)
class
CommentListGetForm
(
_PaginationForm
):
class
CommentListGetForm
(
_PaginationForm
):
"""
"""
A form to validate query parameters in the comment list retrieval endpoint
A form to validate query parameters in the comment list retrieval endpoint
...
...
lms/djangoapps/discussion_api/tests/test_api.py
View file @
f3911c44
...
@@ -3,6 +3,7 @@ Tests for Discussion API internal interface
...
@@ -3,6 +3,7 @@ Tests for Discussion API internal interface
"""
"""
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
import
itertools
import
itertools
from
urlparse
import
urlparse
import
ddt
import
ddt
import
httpretty
import
httpretty
...
@@ -1066,6 +1067,23 @@ class CreateThreadTest(CommentsServiceMockMixin, UrlResetMixin, ModuleStoreTestC
...
@@ -1066,6 +1067,23 @@ class CreateThreadTest(CommentsServiceMockMixin, UrlResetMixin, ModuleStoreTestC
}
}
)
)
def
test_following
(
self
):
self
.
register_post_thread_response
({
"id"
:
"test_id"
})
self
.
register_subscription_response
(
self
.
user
)
data
=
self
.
minimal_data
.
copy
()
data
[
"following"
]
=
"True"
result
=
create_thread
(
self
.
request
,
data
)
self
.
assertEqual
(
result
[
"following"
],
True
)
cs_request
=
httpretty
.
last_request
()
self
.
assertEqual
(
urlparse
(
cs_request
.
path
)
.
path
,
"/api/v1/users/{}/subscriptions"
.
format
(
self
.
user
.
id
)
)
self
.
assertEqual
(
cs_request
.
parsed_body
,
{
"source_type"
:
[
"thread"
],
"source_id"
:
[
"test_id"
]}
)
def
test_course_id_missing
(
self
):
def
test_course_id_missing
(
self
):
with
self
.
assertRaises
(
ValidationError
)
as
assertion
:
with
self
.
assertRaises
(
ValidationError
)
as
assertion
:
create_thread
(
self
.
request
,
{})
create_thread
(
self
.
request
,
{})
...
...
lms/djangoapps/discussion_api/tests/utils.py
View file @
f3911c44
...
@@ -74,6 +74,17 @@ class CommentsServiceMockMixin(object):
...
@@ -74,6 +74,17 @@ class CommentsServiceMockMixin(object):
status
=
200
status
=
200
)
)
def
register_subscription_response
(
self
,
user
):
"""
Register a mock response for POST on the CS user subscription endpoint
"""
httpretty
.
register_uri
(
httpretty
.
POST
,
"http://localhost:4567/api/v1/users/{id}/subscriptions"
.
format
(
id
=
user
.
id
),
body
=
json
.
dumps
({}),
# body is unused
status
=
200
)
def
assert_query_params_equal
(
self
,
httpretty_request
,
expected_params
):
def
assert_query_params_equal
(
self
,
httpretty_request
,
expected_params
):
"""
"""
Assert that the given mock request had the expected query parameters
Assert that the given mock request had the expected query parameters
...
...
lms/djangoapps/discussion_api/views.py
View file @
f3911c44
...
@@ -96,6 +96,9 @@ class ThreadViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet):
...
@@ -96,6 +96,9 @@ class ThreadViewSet(_ViewMixin, DeveloperErrorViewMixin, ViewSet):
* raw_body (required): The thread's raw body text
* raw_body (required): The thread's raw body text
* following (optional): A boolean indicating whether the user should
follow the thread upon its creation; defaults to false
**GET Response Values**:
**GET Response Values**:
* results: The list of threads; each item in the list has the same
* results: The list of threads; each item in the list has the same
...
...
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