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
c9c1a4bc
Commit
c9c1a4bc
authored
Dec 02, 2015
by
wajeeha-khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jia/MA-1748 patch read states for users
parent
f2c4a3de
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
3 deletions
+90
-3
lms/djangoapps/discussion_api/serializers.py
+1
-1
lms/djangoapps/discussion_api/tests/test_api.py
+1
-0
lms/djangoapps/discussion_api/tests/test_serializers.py
+2
-0
lms/djangoapps/discussion_api/tests/test_views.py
+78
-0
lms/lib/comment_client/models.py
+8
-2
No files found.
lms/djangoapps/discussion_api/serializers.py
View file @
c9c1a4bc
...
...
@@ -272,7 +272,7 @@ class ThreadSerializer(_ContentSerializer):
def
update
(
self
,
instance
,
validated_data
):
for
key
,
val
in
validated_data
.
items
():
instance
[
key
]
=
val
instance
.
save
()
instance
.
save
(
params
=
{
"requested_user_id"
:
self
.
context
[
"cc_requester"
][
"id"
]}
)
return
instance
...
...
lms/djangoapps/discussion_api/tests/test_api.py
View file @
c9c1a4bc
...
...
@@ -1968,6 +1968,7 @@ class UpdateThreadTest(
"closed"
:
[
"False"
],
"pinned"
:
[
"False"
],
"read"
:
[
"False"
],
"requested_user_id"
:
[
str
(
self
.
user
.
id
)],
}
)
...
...
lms/djangoapps/discussion_api/tests/test_serializers.py
View file @
c9c1a4bc
...
...
@@ -562,6 +562,7 @@ class ThreadSerializerDeserializationTest(CommentsServiceMockMixin, UrlResetMixi
"pinned"
:
[
"False"
],
"user_id"
:
[
str
(
self
.
user
.
id
)],
"read"
:
[
"False"
],
"requested_user_id"
:
[
str
(
self
.
user
.
id
)],
}
)
...
...
@@ -590,6 +591,7 @@ class ThreadSerializerDeserializationTest(CommentsServiceMockMixin, UrlResetMixi
"pinned"
:
[
"False"
],
"user_id"
:
[
str
(
self
.
user
.
id
)],
"read"
:
[
str
(
read
)],
"requested_user_id"
:
[
str
(
self
.
user
.
id
)],
}
)
for
key
in
data
:
...
...
lms/djangoapps/discussion_api/tests/test_views.py
View file @
c9c1a4bc
...
...
@@ -683,6 +683,7 @@ class ThreadViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTest
"closed"
:
[
"False"
],
"pinned"
:
[
"False"
],
"read"
:
[
"False"
],
"requested_user_id"
:
[
str
(
self
.
user
.
id
)],
}
)
...
...
@@ -736,6 +737,83 @@ class ThreadViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTest
response
=
self
.
request_patch
(
request_data
)
self
.
assertEqual
(
response
.
status_code
,
400
)
def
test_patch_read_owner_user
(
self
):
self
.
register_get_user_response
(
self
.
user
)
self
.
register_thread
()
request_data
=
{
"read"
:
True
}
response
=
self
.
request_patch
(
request_data
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_data
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response_data
,
self
.
expected_response_data
({
"comment_count"
:
1
,
"read"
:
True
,
"editable_fields"
:
[
"abuse_flagged"
,
"following"
,
"raw_body"
,
"read"
,
"title"
,
"topic_id"
,
"type"
,
"voted"
],
})
)
self
.
assertEqual
(
httpretty
.
last_request
()
.
parsed_body
,
{
"course_id"
:
[
unicode
(
self
.
course
.
id
)],
"commentable_id"
:
[
"original_topic"
],
"thread_type"
:
[
"discussion"
],
"title"
:
[
"Original Title"
],
"body"
:
[
"Original body"
],
"user_id"
:
[
str
(
self
.
user
.
id
)],
"anonymous"
:
[
"False"
],
"anonymous_to_peers"
:
[
"False"
],
"closed"
:
[
"False"
],
"pinned"
:
[
"False"
],
"read"
:
[
"True"
],
"requested_user_id"
:
[
str
(
self
.
user
.
id
)],
}
)
def
test_patch_read_non_owner_user
(
self
):
self
.
register_get_user_response
(
self
.
user
)
thread_owner_user
=
UserFactory
.
create
(
password
=
self
.
password
)
CourseEnrollmentFactory
.
create
(
user
=
thread_owner_user
,
course_id
=
self
.
course
.
id
)
self
.
register_get_user_response
(
thread_owner_user
)
self
.
register_thread
({
"username"
:
thread_owner_user
.
username
,
"user_id"
:
str
(
thread_owner_user
.
id
)})
request_data
=
{
"read"
:
True
}
response
=
self
.
request_patch
(
request_data
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_data
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response_data
,
self
.
expected_response_data
({
"author"
:
str
(
thread_owner_user
.
username
),
"comment_count"
:
1
,
"read"
:
True
,
"editable_fields"
:
[
"abuse_flagged"
,
"following"
,
"read"
,
"voted"
],
})
)
self
.
assertEqual
(
httpretty
.
last_request
()
.
parsed_body
,
{
"course_id"
:
[
unicode
(
self
.
course
.
id
)],
"commentable_id"
:
[
"original_topic"
],
"thread_type"
:
[
"discussion"
],
"title"
:
[
"Original Title"
],
"body"
:
[
"Original body"
],
"user_id"
:
[
str
(
thread_owner_user
.
id
)],
"anonymous"
:
[
"False"
],
"anonymous_to_peers"
:
[
"False"
],
"closed"
:
[
"False"
],
"pinned"
:
[
"False"
],
"read"
:
[
"True"
],
"requested_user_id"
:
[
str
(
self
.
user
.
id
)],
}
)
@httpretty.activate
@disable_signal
(
api
,
'thread_deleted'
)
...
...
lms/lib/comment_client/models.py
View file @
c9c1a4bc
...
...
@@ -124,14 +124,20 @@ class Model(object):
def
after_save
(
cls
,
instance
):
pass
def
save
(
self
):
def
save
(
self
,
params
=
None
):
"""
Invokes Forum's POST/PUT service to create/update thread
"""
self
.
before_save
(
self
)
if
self
.
id
:
# if we have id already, treat this as an update
request_params
=
self
.
updatable_attributes
()
if
params
:
request_params
.
update
(
params
)
url
=
self
.
url
(
action
=
'put'
,
params
=
self
.
attributes
)
response
=
perform_request
(
'put'
,
url
,
self
.
updatable_attributes
()
,
request_params
,
metric_tags
=
self
.
_metric_tags
,
metric_action
=
'model.update'
)
...
...
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