Merge pull request #254 from jGleitz/preview

Preview endpoint
This commit is contained in:
Martin Zimmermann 2016-07-13 21:04:35 +02:00 committed by GitHub
commit bbff002bd6
2 changed files with 18 additions and 1 deletions

View File

@ -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):

View File

@ -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')