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
fa269d3c
Commit
fa269d3c
authored
May 14, 2013
by
Kevin Chugh
Committed by
Jay Zoldak
May 16, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add flag thread django test
parent
82d2b78b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
0 deletions
+66
-0
lms/djangoapps/django_comment_client/base/tests.py
+31
-0
lms/djangoapps/django_comment_client/tests/mock_cs_server/mock_cs_server.py
+35
-0
No files found.
lms/djangoapps/django_comment_client/base/tests.py
View file @
fa269d3c
...
...
@@ -87,3 +87,34 @@ class ViewsTestCase(ModuleStoreTestCase):
'anonymous'
:
False
,
'course_id'
:
u'MITx/999/Robot_Super_Course'
,
'api_key'
:
'PUT_YOUR_API_KEY_HERE'
},
timeout
=
5
)
assert_equal
(
response
.
status_code
,
200
)
def
test_flag_thread
(
self
,
mock_request
):
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
text
=
u'{"title":"Hello",
\
"body":"this is a post",
\
"course_id":"MITx/999/Robot_Super_Course",
\
"anonymous":false,
\
"anonymous_to_peers":false,
\
"commentable_id":"i4x-MITx-999-course-Robot_Super_Course",
\
"created_at":"2013-05-10T18:53:43Z",
\
"updated_at":"2013-05-10T18:53:43Z",
\
"at_position_list":[],
\
"closed":false,
\
"id":"518d4237b023791dca00000d",
\
"user_id":"1","username":"robot",
\
"votes":{"count":0,"up_count":0,
\
"down_count":0,"point":0},
\
"abuse_flaggers":[1],"tags":[],
\
"type":"thread","group_id":null,
\
"pinned":false,
\
"endorsed":false,
\
"unread_comments_count":0,
\
"read":false,"comments_count":0}'
url
=
reverse
(
'flag_thread'
,
kwargs
=
{
'thread_id'
:
'518d4237b023791dca00000d'
})
response
=
self
.
client
.
put
(
url
)
assert_true
(
mock_request
.
called
)
mock_request
.
assert_called_with
(
'put'
,
'http://localhost:4567/api/v1/i4x-MITx-999-course-Robot_Super_Course/threads/518d4237b023791dca00000d/abuse_flag'
,
data
=
{
'user_id'
:
1
,
'api_key'
:
'PUT_YOUR_API_KEY_HERE'
},
timeout
=
5
)
assert_equal
(
response
.
status_code
,
200
)
lms/djangoapps/django_comment_client/tests/mock_cs_server/mock_cs_server.py
View file @
fa269d3c
...
...
@@ -45,6 +45,41 @@ class MockCommentServiceRequestHandler(BaseHTTPRequestHandler):
self
.
end_headers
()
return
False
def
do_PUT
self
):
'''
Handle a PUT request from the client
Used by the APIs for comment threads, commentables, comments,
subscriptions, commentables, users
'''
# Retrieve the PUT data into a dict.
# It should have been sent in json format
length
=
int
(
self
.
headers
.
getheader
(
'content-length'
))
data_string
=
self
.
rfile
.
read
(
length
)
post_dict
=
json
.
loads
(
data_string
)
# Log the request
logger
.
debug
(
"Comment Service received PUT request
%
s to path
%
s"
%
(
json
.
dumps
(
post_dict
),
self
.
path
))
# Every good post has at least an API key
if
'api_key'
in
post_dict
:
response
=
self
.
server
.
_response_str
# Log the response
logger
.
debug
(
"Comment Service: sending response
%
s"
%
json
.
dumps
(
response
))
# Send a response back to the client
self
.
send_response
(
200
)
self
.
send_header
(
'Content-type'
,
'application/json'
)
self
.
end_headers
()
self
.
wfile
.
write
(
response
)
else
:
# Respond with failure
self
.
send_response
(
500
,
'Bad Request: does not contain API key'
)
self
.
send_header
(
'Content-type'
,
'text/plain'
)
self
.
end_headers
()
return
False
class
MockCommentServiceServer
(
HTTPServer
):
'''
...
...
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