Commit fa269d3c by Kevin Chugh Committed by Jay Zoldak

add flag thread django test

parent 82d2b78b
......@@ -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)
......@@ -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):
'''
......
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