|
|
|
@ -33,6 +33,7 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
conf.set("general", "dbpath", self.path)
|
|
|
|
|
conf.set("guard", "enabled", "off")
|
|
|
|
|
conf.set("hash", "algorithm", "none")
|
|
|
|
|
conf.set("general", "latest-enabled", "true")
|
|
|
|
|
self.conf = conf
|
|
|
|
|
|
|
|
|
|
class App(Isso, core.Mixin):
|
|
|
|
@ -451,6 +452,48 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
rv["text"], '<p>This is <strong>mark</strong><em>down</em></p>')
|
|
|
|
|
|
|
|
|
|
def testLatestOk(self):
|
|
|
|
|
# load some comments in a mix of posts
|
|
|
|
|
saved = []
|
|
|
|
|
for idx, post_id in enumerate([1, 2, 2, 1, 2, 1, 3, 1, 4, 2, 3, 4, 1, 2]):
|
|
|
|
|
text = 'text-{}'.format(idx)
|
|
|
|
|
post_uri = 'test-{}'.format(post_id)
|
|
|
|
|
self.post('/new?uri=' + post_uri, data=json.dumps({'text': text}))
|
|
|
|
|
saved.append((post_uri, text))
|
|
|
|
|
|
|
|
|
|
response = self.get('/latest?limit=5')
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
|
|
body = loads(response.data)
|
|
|
|
|
expected_items = saved[-5:] # latest 5
|
|
|
|
|
for reply, expected in zip(body, expected_items):
|
|
|
|
|
expected_uri, expected_text = expected
|
|
|
|
|
self.assertIn(expected_text, reply['text'])
|
|
|
|
|
self.assertEqual(expected_uri, reply['uri'])
|
|
|
|
|
|
|
|
|
|
def testLatestWithoutLimit(self):
|
|
|
|
|
response = self.get('/latest')
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
|
|
def testLatestBadLimitNaN(self):
|
|
|
|
|
response = self.get('/latest?limit=WAT')
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
|
|
def testLatestBadLimitNegative(self):
|
|
|
|
|
response = self.get('/latest?limit=-12')
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
|
|
def testLatestBadLimitZero(self):
|
|
|
|
|
response = self.get('/latest?limit=0')
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
|
|
def testLatestNotEnabled(self):
|
|
|
|
|
# disable the endpoint
|
|
|
|
|
self.conf.set("general", "latest-enabled", "false")
|
|
|
|
|
|
|
|
|
|
response = self.get('/latest?limit=5')
|
|
|
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestModeratedComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|