1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-12 21:30:39 +00:00

file participant batch add (#3914)

* file participants batch add view

* file participants batch add test

* file participants batch add in exist API

* fix database query
This commit is contained in:
sniper-py
2019-07-26 11:14:08 +08:00
committed by Daniel Pan
parent 4a4e280098
commit 75318ef1f9
2 changed files with 86 additions and 44 deletions

View File

@@ -49,52 +49,68 @@ class FileParticipantsTest(BaseTestCase):
self.assertEqual(403, resp.status_code)
def test_can_post(self):
resp = self.client.post(self.url, {
'email': self.tmp_user.username,
data = {
'emails': [self.tmp_user.username, self.admin.username],
'path': self.file,
})
self.assertEqual(201, resp.status_code)
}
resp = self.client.post(self.url, json.dumps(data), 'application/json')
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['email'] == self.tmp_user.username
assert json_resp['avatar_url']
assert json_resp['contact_email']
assert json_resp['name']
assert FileParticipant.objects.filter(
uuid=self.file_uuid, username=self.tmp_user.username).count() == 1
assert len(json_resp['success']) == 1
assert json_resp['success'][0]['email'] == self.tmp_user.username
assert len(json_resp['failed']) == 1
assert json_resp['failed'][0]['email'] == self.admin.username
assert FileParticipant.objects.filter(uuid=self.file_uuid).count() == 2
def test_can_not_post_by_not_exists_path(self):
invalid_path = self.file + randstring(5)
resp = self.client.post(self.url, {
'email': self.tmp_user.username,
data = {
'emails': [self.tmp_user.username],
'path': invalid_path,
})
}
resp = self.client.post(self.url, json.dumps(data), 'application/json')
self.assertEqual(404, resp.status_code)
def test_can_not_post_by_invalid_user_permission(self):
self.logout()
self.login_as(self.admin)
resp = self.client.post(self.url, {
'email': self.tmp_user.username,
data = {
'emails': [self.tmp_user.username],
'path': self.file,
})
}
resp = self.client.post(self.url, json.dumps(data), 'application/json')
self.assertEqual(403, resp.status_code)
def test_can_not_post_by_not_exists_user(self):
invalid_email = randstring(5) + '@seafile.com'
resp = self.client.post(self.url, {
'email': invalid_email,
data = {
'emails': [invalid_email],
'path': self.file,
})
self.assertEqual(404, resp.status_code)
}
resp = self.client.post(self.url, json.dumps(data), 'application/json')
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
assert len(json_resp['success']) == 0
assert len(json_resp['failed']) == 1
assert json_resp['failed'][0]['email'] == invalid_email
def test_can_not_post_by_invalid_email_permission(self):
resp = self.client.post(self.url, {
'email': self.admin.username,
data = {
'emails': [self.admin.username],
'path': self.file,
})
self.assertEqual(403, resp.status_code)
}
resp = self.client.post(self.url, json.dumps(data), 'application/json')
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
assert len(json_resp['success']) == 0
assert len(json_resp['failed']) == 1
assert json_resp['failed'][0]['email'] == self.admin.username
class FileParticipantTest(BaseTestCase):