1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-10-20 10:20:42 +00:00

[api] Add file comment endpoints

This commit is contained in:
zhengxie
2016-05-01 17:41:18 +08:00
committed by llj
parent ee99d7aad8
commit e8579d0742
11 changed files with 432 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
import json
from django.core.urlresolvers import reverse
from seahub.base.models import FileComment
from seahub.test_utils import BaseTestCase
class FileCommentTest(BaseTestCase):
def setUp(self):
self.login_as(self.user)
o = FileComment.objects.add_by_file_path(repo_id=self.repo.id,
file_path=self.file,
author=self.user.username,
comment='test comment')
self.endpoint = reverse('api2-file-comment', args=[self.repo.id, o.pk]) + '?p=' + self.file
def tearDown(self):
self.remove_repo()
def test_can_get(self):
resp = self.client.get(self.endpoint)
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['parent_path'] == '/'
assert json_resp['item_name'] == 'test.txt'
def test_can_delete(self):
assert len(FileComment.objects.all()) == 1
resp = self.client.delete(self.endpoint)
self.assertEqual(204, resp.status_code)
assert len(FileComment.objects.all()) == 0
def test_invalid_user_can_not_delete(self):
self.logout()
self.login_as(self.admin)
assert len(FileComment.objects.all()) == 1
resp = self.client.delete(self.endpoint)
self.assertEqual(403, resp.status_code)
assert len(FileComment.objects.all()) == 1

View File

@@ -0,0 +1,47 @@
import json
from django.core.urlresolvers import reverse
from seahub.base.models import FileComment
from seahub.test_utils import BaseTestCase
class FileCommentsTest(BaseTestCase):
def setUp(self):
self.login_as(self.user)
self.endpoint = reverse('api2-file-comments', args=[self.repo.id]) + '?p=' + self.file
def tearDown(self):
self.remove_repo()
def test_can_list(self):
o = FileComment.objects.add_by_file_path(repo_id=self.repo.id,
file_path=self.file,
author=self.user.username,
comment='test comment')
resp = self.client.get(self.endpoint)
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
assert len(json_resp['comments']) == 1
assert json_resp['comments'][0]['comment'] == o.comment
def test_can_post(self):
resp = self.client.post(self.endpoint, {
'comment': 'new comment'
})
self.assertEqual(201, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['comment'] == 'new comment'
def test_invalid_user(self):
self.logout()
self.login_as(self.admin)
resp = self.client.get(self.endpoint)
self.assertEqual(403, resp.status_code)
resp = self.client.post(self.endpoint, {
'comment': 'new comment'
})
self.assertEqual(403, resp.status_code)

View File

@@ -0,0 +1,46 @@
import json
from django.core.urlresolvers import reverse
from seahub.base.models import FileComment
from seahub.test_utils import BaseTestCase
class FileCommentsCountsTest(BaseTestCase):
def setUp(self):
self.login_as(self.user)
self.endpoint = reverse('api2-file-comments-counts', args=[self.repo.id]) + '?p=/'
self.file2 = self.create_file(repo_id=self.repo.id, parent_dir='/',
filename='test2.txt',
username=self.user.username)
def tearDown(self):
self.remove_repo()
def test_can_get(self):
FileComment.objects.add_by_file_path(repo_id=self.repo.id,
file_path=self.file,
author=self.user.username,
comment='test comment')
FileComment.objects.add_by_file_path(repo_id=self.repo.id,
file_path=self.file,
author=self.user.username,
comment='reply test comment')
FileComment.objects.add_by_file_path(repo_id=self.repo.id,
file_path=self.file2,
author=self.user.username,
comment='test comment on other file')
resp = self.client.get(self.endpoint)
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
assert len(json_resp) == 2
for d in json_resp:
if d.keys()[0] == 'test.txt':
assert d['test.txt'] == 2
if d.keys()[0] == 'test2.txt':
assert d['test2.txt'] == 1