|
|
|
@ -50,7 +50,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def testGet(self):
|
|
|
|
|
|
|
|
|
|
self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Lorem ipsum ...'}))
|
|
|
|
|
self.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({'text': 'Lorem ipsum ...'}))
|
|
|
|
|
r = self.get('/id/1')
|
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
|
|
|
|
|
@ -61,7 +62,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def testCreate(self):
|
|
|
|
|
|
|
|
|
|
rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Lorem ipsum ...'}))
|
|
|
|
|
rv = self.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({'text': 'Lorem ipsum ...'}))
|
|
|
|
|
|
|
|
|
|
self.assertEqual(rv.status_code, 201)
|
|
|
|
|
self.assertIn("Set-Cookie", rv.headers)
|
|
|
|
@ -73,7 +75,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def textCreateWithNonAsciiText(self):
|
|
|
|
|
|
|
|
|
|
rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Здравствуй, мир!'}))
|
|
|
|
|
rv = self.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({'text': 'Здравствуй, мир!'}))
|
|
|
|
|
|
|
|
|
|
self.assertEqual(rv.status_code, 201)
|
|
|
|
|
rv = loads(rv.data)
|
|
|
|
@ -105,14 +108,16 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
def testCreateInvalidParent(self):
|
|
|
|
|
|
|
|
|
|
self.post('/new?uri=test', data=json.dumps({'text': '...'}))
|
|
|
|
|
self.post('/new?uri=test', data=json.dumps({'text': '...', 'parent': 1}))
|
|
|
|
|
invalid = self.post('/new?uri=test', data=json.dumps({'text': '...', 'parent': 2}))
|
|
|
|
|
self.post('/new?uri=test',
|
|
|
|
|
data=json.dumps({'text': '...', 'parent': 1}))
|
|
|
|
|
invalid = self.post(
|
|
|
|
|
'/new?uri=test', data=json.dumps({'text': '...', 'parent': 2}))
|
|
|
|
|
|
|
|
|
|
self.assertEqual(loads(invalid.data)["parent"], 1)
|
|
|
|
|
|
|
|
|
|
def testVerifyFields(self):
|
|
|
|
|
|
|
|
|
|
verify = lambda comment: comments.API.verify(comment)[0]
|
|
|
|
|
def verify(comment): return comments.API.verify(comment)[0]
|
|
|
|
|
|
|
|
|
|
# text is missing
|
|
|
|
|
self.assertFalse(verify({}))
|
|
|
|
@ -128,10 +133,12 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
# email/website length
|
|
|
|
|
self.assertTrue(verify({"text": "...", "email": "*"*254}))
|
|
|
|
|
self.assertTrue(verify({"text": "...", "website": "google.de/" + "a"*128}))
|
|
|
|
|
self.assertTrue(
|
|
|
|
|
verify({"text": "...", "website": "google.de/" + "a"*128}))
|
|
|
|
|
|
|
|
|
|
self.assertFalse(verify({"text": "...", "email": "*"*1024}))
|
|
|
|
|
self.assertFalse(verify({"text": "...", "website": "google.de/" + "*"*1024}))
|
|
|
|
|
self.assertFalse(
|
|
|
|
|
verify({"text": "...", "website": "google.de/" + "*"*1024}))
|
|
|
|
|
|
|
|
|
|
# valid website url
|
|
|
|
|
self.assertTrue(comments.isurl("example.tld"))
|
|
|
|
@ -139,7 +146,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
self.assertTrue(comments.isurl("https://example.tld"))
|
|
|
|
|
self.assertTrue(comments.isurl("https://example.tld:1337/"))
|
|
|
|
|
self.assertTrue(comments.isurl("https://example.tld:1337/foobar"))
|
|
|
|
|
self.assertTrue(comments.isurl("https://example.tld:1337/foobar?p=1#isso-thread"))
|
|
|
|
|
self.assertTrue(comments.isurl(
|
|
|
|
|
"https://example.tld:1337/foobar?p=1#isso-thread"))
|
|
|
|
|
|
|
|
|
|
self.assertFalse(comments.isurl("ftp://example.tld/"))
|
|
|
|
|
self.assertFalse(comments.isurl("tel:+1234567890"))
|
|
|
|
@ -149,7 +157,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
def testGetInvalid(self):
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get('/?uri=%2Fpath%2F&id=123').status_code, 404)
|
|
|
|
|
self.assertEqual(self.get('/?uri=%2Fpath%2Fspam%2F&id=123').status_code, 404)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.get('/?uri=%2Fpath%2Fspam%2F&id=123').status_code, 404)
|
|
|
|
|
self.assertEqual(self.get('/?uri=?uri=%foo%2F').status_code, 404)
|
|
|
|
|
|
|
|
|
|
def testGetLimited(self):
|
|
|
|
@ -166,7 +175,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
def testGetNested(self):
|
|
|
|
|
|
|
|
|
|
self.post('/new?uri=test', data=json.dumps({'text': '...'}))
|
|
|
|
|
self.post('/new?uri=test', data=json.dumps({'text': '...', 'parent': 1}))
|
|
|
|
|
self.post('/new?uri=test',
|
|
|
|
|
data=json.dumps({'text': '...', 'parent': 1}))
|
|
|
|
|
|
|
|
|
|
r = self.get('/?uri=test&parent=1')
|
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
@ -178,7 +188,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
self.post('/new?uri=test', data=json.dumps({'text': '...'}))
|
|
|
|
|
for i in range(20):
|
|
|
|
|
self.post('/new?uri=test', data=json.dumps({'text': '...', 'parent': 1}))
|
|
|
|
|
self.post('/new?uri=test',
|
|
|
|
|
data=json.dumps({'text': '...', 'parent': 1}))
|
|
|
|
|
|
|
|
|
|
r = self.get('/?uri=test&parent=1&limit=10')
|
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
@ -188,7 +199,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def testUpdate(self):
|
|
|
|
|
|
|
|
|
|
self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Lorem ipsum ...'}))
|
|
|
|
|
self.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({'text': 'Lorem ipsum ...'}))
|
|
|
|
|
self.put('/id/1', data=json.dumps({
|
|
|
|
|
'text': 'Hello World', 'author': 'me', 'website': 'http://example.com/'}))
|
|
|
|
|
|
|
|
|
@ -203,7 +215,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def testDelete(self):
|
|
|
|
|
|
|
|
|
|
self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Lorem ipsum ...'}))
|
|
|
|
|
self.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({'text': 'Lorem ipsum ...'}))
|
|
|
|
|
r = self.delete('/id/1')
|
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
|
self.assertEqual(loads(r.data), None)
|
|
|
|
@ -213,7 +226,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
client = JSONClient(self.app, Response)
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'First'}))
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'First', 'parent': 1}))
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({'text': 'First', 'parent': 1}))
|
|
|
|
|
|
|
|
|
|
r = client.delete('/id/1')
|
|
|
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
@ -242,8 +256,10 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
client = JSONClient(self.app, Response)
|
|
|
|
|
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'First'}))
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Second', 'parent': 1}))
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Third', 'parent': 1}))
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({'text': 'Second', 'parent': 1}))
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({'text': 'Third', 'parent': 1}))
|
|
|
|
|
client.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Last'}))
|
|
|
|
|
|
|
|
|
|
client.delete('/id/1')
|
|
|
|
@ -261,10 +277,11 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
for path in paths:
|
|
|
|
|
self.assertEqual(self.post('/new?' + urlencode({'uri': path}),
|
|
|
|
|
data=json.dumps({'text': '...'})).status_code, 201)
|
|
|
|
|
data=json.dumps({'text': '...'})).status_code, 201)
|
|
|
|
|
|
|
|
|
|
for i, path in enumerate(paths):
|
|
|
|
|
self.assertEqual(self.get('/?' + urlencode({'uri': path})).status_code, 200)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.get('/?' + urlencode({'uri': path})).status_code, 200)
|
|
|
|
|
self.assertEqual(self.get('/id/%i' % (i + 1)).status_code, 200)
|
|
|
|
|
|
|
|
|
|
def testDeleteAndCreateByDifferentUsersButSamePostId(self):
|
|
|
|
@ -283,7 +300,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
a = self.post('/new?uri=%2Fpath%2F', data=json.dumps({"text": "Aaa"}))
|
|
|
|
|
b = self.post('/new?uri=%2Fpath%2F', data=json.dumps({"text": "Bbb"}))
|
|
|
|
|
c = self.post('/new?uri=%2Fpath%2F', data=json.dumps({"text": "Ccc", "email": "..."}))
|
|
|
|
|
c = self.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({"text": "Ccc", "email": "..."}))
|
|
|
|
|
|
|
|
|
|
a = loads(a.data)
|
|
|
|
|
b = loads(b.data)
|
|
|
|
@ -295,7 +313,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def testVisibleFields(self):
|
|
|
|
|
|
|
|
|
|
rv = self.post('/new?uri=%2Fpath%2F', data=json.dumps({"text": "...", "invalid": "field"}))
|
|
|
|
|
rv = self.post('/new?uri=%2Fpath%2F',
|
|
|
|
|
data=json.dumps({"text": "...", "invalid": "field"}))
|
|
|
|
|
self.assertEqual(rv.status_code, 201)
|
|
|
|
|
|
|
|
|
|
rv = loads(rv.data)
|
|
|
|
@ -333,7 +352,8 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
for uri, count in iteritems(expected):
|
|
|
|
|
for _ in range(count):
|
|
|
|
|
self.post('/new?uri=%s' % uri, data=json.dumps({"text": "..."}))
|
|
|
|
|
self.post('/new?uri=%s' %
|
|
|
|
|
uri, data=json.dumps({"text": "..."}))
|
|
|
|
|
|
|
|
|
|
rv = self.post('/count', data=json.dumps(list(expected.keys())))
|
|
|
|
|
self.assertEqual(loads(rv.data), list(expected.values()))
|
|
|
|
@ -362,22 +382,26 @@ class TestComments(unittest.TestCase):
|
|
|
|
|
self.post('/new?uri=%2F', data=json.dumps({"text": "..."}))
|
|
|
|
|
|
|
|
|
|
# no header is fine (default for XHR)
|
|
|
|
|
self.assertEqual(self.post('/id/1/dislike', content_type="").status_code, 200)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.post('/id/1/dislike', content_type="").status_code, 200)
|
|
|
|
|
|
|
|
|
|
# x-www-form-urlencoded is definitely not RESTful
|
|
|
|
|
self.assertEqual(self.post('/id/1/dislike', content_type=form).status_code, 403)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
self.post('/id/1/dislike', content_type=form).status_code, 403)
|
|
|
|
|
self.assertEqual(self.post('/new?uri=%2F', data=json.dumps({"text": "..."}),
|
|
|
|
|
content_type=form).status_code, 403)
|
|
|
|
|
content_type=form).status_code, 403)
|
|
|
|
|
# just for the record
|
|
|
|
|
self.assertEqual(self.post('/id/1/dislike', content_type=js).status_code, 200)
|
|
|
|
|
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*'}))
|
|
|
|
|
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>')
|
|
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
rv["text"], '<p>This is <strong>mark</strong><em>down</em></p>')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestModeratedComments(unittest.TestCase):
|
|
|
|
@ -402,7 +426,8 @@ class TestModeratedComments(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def testAddComment(self):
|
|
|
|
|
|
|
|
|
|
rv = self.client.post('/new?uri=test', data=json.dumps({"text": "..."}))
|
|
|
|
|
rv = self.client.post(
|
|
|
|
|
'/new?uri=test', data=json.dumps({"text": "..."}))
|
|
|
|
|
self.assertEqual(rv.status_code, 202)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.client.get('/id/1').status_code, 200)
|
|
|
|
|