From a89debbc9cb136339585db59829907eed99db68f Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 22 Apr 2018 12:38:51 +0200 Subject: [PATCH] api: add a simple test for /feed endpoint --- isso/tests/test_comments.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/isso/tests/test_comments.py b/isso/tests/test_comments.py index cc27ae8..a58ae62 100644 --- a/isso/tests/test_comments.py +++ b/isso/tests/test_comments.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import os import json +import re import tempfile import unittest @@ -30,6 +31,7 @@ class TestComments(unittest.TestCase): fd, self.path = tempfile.mkstemp() conf = config.load(os.path.join(dist.location, "share", "isso.conf")) conf.set("general", "dbpath", self.path) + conf.set("general", "host", "https://example.org") conf.set("guard", "enabled", "off") conf.set("hash", "algorithm", "none") @@ -324,6 +326,28 @@ class TestComments(unittest.TestCase): self.assertListEqual(list(rv.keys()), []) + def testFeedEmpty(self): + rv = self.get('/feed?uri=%2Fpath%2Fnothing') + self.assertEqual(rv.status_code, 200) + self.assertEqual(rv.headers['ETag'], '"empty"') + data = rv.data.decode('utf-8') + self.assertEqual(data, """ +1970-01-01T01:00:00Ztag:example.org,2018:/isso/thread/path/nothingComments for example.org/path/nothing""") + + def testFeed(self): + self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'First'})) + self.post('/new?uri=%2Fpath%2F', + data=json.dumps({'text': 'First', 'parent': 1})) + + rv = self.get('/feed?uri=%2Fpath%2F') + self.assertEqual(rv.status_code, 200) + self.assertEqual(rv.headers['ETag'], '"1-2"') + data = rv.data.decode('utf-8') + data = re.sub('[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+Z', + '2018-04-01T10:00:00Z', data) + self.assertEqual(data, """ +2018-04-01T10:00:00Ztag:example.org,2018:/isso/thread/path/Comments for example.org/path/tag:example.org,2018:/isso/1/2Comment #22018-04-01T10:00:00ZFirsttag:example.org,2018:/isso/1/1Comment #12018-04-01T10:00:00ZFirst""") + def testCounts(self): self.assertEqual(self.get('/count?uri=%2Fpath%2F').status_code, 404)