123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- # -*- coding: utf-8 -*-
- from tracim_backend.tests import FunctionalTest
- from tracim_backend.fixtures.content import Content as ContentFixtures
- from tracim_backend.fixtures.users_and_groups import Base as BaseFixture
-
-
- class TestCommentsEndpoint(FunctionalTest):
- """
- Tests for /api/v2/workspaces/{workspace_id}/contents/{content_id}/comments
- endpoint
- """
-
- fixtures = [BaseFixture, ContentFixtures]
-
- def test_api__get_contents_comments__ok_200__nominal_case(self) -> None:
- """
- Get alls comments of a content
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'admin@admin.admin',
- 'admin@admin.admin'
- )
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200) # nopep8
- assert len(res.json_body) == 3
- comment = res.json_body[0]
- assert comment['content_id'] == 18
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>What is for you the best cake ever? </br> I personnally vote for Chocolate cupcake!</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 1
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] == None
- assert comment['author']['public_name'] == 'Global manager'
-
- comment = res.json_body[1]
- assert comment['content_id'] == 19
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>What about Apple Pie? There are Awesome!</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 3
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] == None
- assert comment['author']['public_name'] == 'Bob i.'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- comment = res.json_body[2]
- assert comment['content_id'] == 20
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>You are right, but Kouign-amann are clearly better.</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 4
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] == None
- assert comment['author']['public_name'] == 'John Reader'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- def test_api__post_content_comment__ok_200__nominal_case(self) -> None:
- """
- Get alls comments of a content
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'admin@admin.admin',
- 'admin@admin.admin'
- )
- )
- params = {
- 'raw_content': 'I strongly disagree, Tiramisu win!'
- }
- res = self.testapp.post_json(
- '/api/v2/workspaces/2/contents/7/comments',
- params=params,
- status=200
- )
- comment = res.json_body
- assert comment['content_id']
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == 'I strongly disagree, Tiramisu win!'
- assert comment['author']
- assert comment['author']['user_id'] == 1
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] is None
- assert comment['author']['public_name'] == 'Global manager'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200) # nopep8
- assert len(res.json_body) == 4
- assert comment == res.json_body[3]
-
- def test_api__post_content_comment__err_400__empty_raw_content(self) -> None:
- """
- Get alls comments of a content
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'admin@admin.admin',
- 'admin@admin.admin'
- )
- )
- params = {
- 'raw_content': ''
- }
- res = self.testapp.post_json(
- '/api/v2/workspaces/2/contents/7/comments',
- params=params,
- status=400
- )
-
- def test_api__delete_content_comment__ok_200__user_is_owner_and_workspace_manager(self) -> None: # nopep8
- """
- delete comment (user is workspace_manager and owner)
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'admin@admin.admin',
- 'admin@admin.admin'
- )
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
- assert len(res.json_body) == 3
- comment = res.json_body[0]
- assert comment['content_id'] == 18
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>What is for you the best cake ever? </br> I personnally vote for Chocolate cupcake!</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 1
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] is None
- assert comment['author']['public_name'] == 'Global manager'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- res = self.testapp.delete(
- '/api/v2/workspaces/2/contents/7/comments/18',
- status=204
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
- assert len(res.json_body) == 2
- assert not [content for content in res.json_body if content['content_id'] == 18] # nopep8
-
- def test_api__delete_content_comment__ok_200__user_is_workspace_manager(self) -> None: # nopep8
- """
- delete comment (user is workspace_manager)
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'admin@admin.admin',
- 'admin@admin.admin'
- )
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
- assert len(res.json_body) == 3
- comment = res.json_body[1]
- assert comment['content_id'] == 19
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>What about Apple Pie? There are Awesome!</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 3
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] is None
- assert comment['author']['public_name'] == 'Bob i.'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- res = self.testapp.delete(
- '/api/v2/workspaces/2/contents/7/comments/19',
- status=204
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
- assert len(res.json_body) == 2
- assert not [content for content in res.json_body if content['content_id'] == 19] # nopep8
-
- def test_api__delete_content_comment__ok_200__user_is_owner_and_content_manager(self) -> None: # nopep8
- """
- delete comment (user is content-manager and owner)
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'admin@admin.admin',
- 'admin@admin.admin'
- )
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
- assert len(res.json_body) == 3
- comment = res.json_body[1]
- assert comment['content_id'] == 19
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>What about Apple Pie? There are Awesome!</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 3
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] is None
- assert comment['author']['public_name'] == 'Bob i.'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- res = self.testapp.delete(
- '/api/v2/workspaces/2/contents/7/comments/19',
- status=204
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
- assert len(res.json_body) == 2
- assert not [content for content in res.json_body if content['content_id'] == 19] # nopep8
-
- def test_api__delete_content_comment__err_403__user_is_content_manager(self) -> None: # nopep8
- """
- delete comment (user is content-manager)
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'bob@fsf.local',
- 'foobarbaz'
- )
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200) # nopep8
- assert len(res.json_body) == 3
- comment = res.json_body[2]
- assert comment['content_id'] == 20
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>You are right, but Kouign-amann are clearly better.</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 4
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] is None
- assert comment['author']['public_name'] == 'John Reader'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- res = self.testapp.delete(
- '/api/v2/workspaces/2/contents/7/comments/20',
- status=403
- )
-
- def test_api__delete_content_comment__err_403__user_is_owner_and_reader(self) -> None:
- """
- delete comment (user is reader and owner)
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'bob@fsf.local',
- 'foobarbaz'
- )
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
- assert len(res.json_body) == 3
- comment = res.json_body[2]
- assert comment['content_id'] == 20
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>You are right, but Kouign-amann are clearly better.</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 4
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] is None
- assert comment['author']['public_name'] == 'John Reader'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- res = self.testapp.delete(
- '/api/v2/workspaces/2/contents/7/comments/20',
- status=403
- )
-
- def test_api__delete_content_comment__err_403__user_is_reader(self) -> None:
- """
- delete comment (user is reader)
- """
- self.testapp.authorization = (
- 'Basic',
- (
- 'bob@fsf.local',
- 'foobarbaz'
- )
- )
- res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
- assert len(res.json_body) == 3
- comment = res.json_body[2]
- assert comment['content_id'] == 20
- assert comment['parent_id'] == 7
- assert comment['raw_content'] == '<p>You are right, but Kouign-amann are clearly better.</p>' # nopep8
- assert comment['author']
- assert comment['author']['user_id'] == 4
- # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
- assert comment['author']['avatar_url'] is None
- assert comment['author']['public_name'] == 'John Reader'
- # TODO - G.M - 2018-06-179 - better check for datetime
- assert comment['created']
-
- res = self.testapp.delete(
- '/api/v2/workspaces/2/contents/7/comments/20',
- status=403
- )
|