preview endpoint
This commit is contained in:
parent
4d3f6fa390
commit
3c9bbda252
@ -375,6 +375,14 @@ class TestComments(unittest.TestCase):
|
||||
# just for the record
|
||||
self.assertEqual(self.post('/id/1/dislike', content_type=js).status_code, 200)
|
||||
|
||||
def testPreview(self):
|
||||
response = self.post('/preview', data=json.dumps({'text': 'This is **mark***down*'}))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
rv = loads(response.data)
|
||||
self.assertEqual(rv["text"], '<p>This is <strong>mark</strong><em>down</em></p>')
|
||||
|
||||
|
||||
|
||||
class TestModeratedComments(unittest.TestCase):
|
||||
|
||||
|
@ -89,7 +89,8 @@ class API(object):
|
||||
('moderate',('POST', '/id/<int:id>/<any(activate,delete):action>/<string:key>')),
|
||||
('like', ('POST', '/id/<int:id>/like')),
|
||||
('dislike', ('POST', '/id/<int:id>/dislike')),
|
||||
('demo', ('GET', '/demo'))
|
||||
('demo', ('GET', '/demo')),
|
||||
('preview', ('POST', '/preview'))
|
||||
]
|
||||
|
||||
def __init__(self, isso, hasher):
|
||||
@ -476,5 +477,13 @@ class API(object):
|
||||
|
||||
return JSON(self.comments.count(*data), 200)
|
||||
|
||||
def preview(self, environment, request):
|
||||
data = request.get_json()
|
||||
|
||||
if "text" not in data or data["text"] is None:
|
||||
raise BadRequest("no text given")
|
||||
|
||||
return JSON({'text': self.isso.render(data["text"])}, 200)
|
||||
|
||||
def demo(self, env, req):
|
||||
return redirect(get_current_url(env) + '/index.html')
|
||||
|
Loading…
Reference in New Issue
Block a user