test_comments.py 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # -*- coding: utf-8 -*-
  2. from tracim.tests import FunctionalTest
  3. from tracim.fixtures.content import Content as ContentFixtures
  4. from tracim.fixtures.users_and_groups import Base as BaseFixture
  5. class TestCommentsEndpoint(FunctionalTest):
  6. """
  7. Tests for /api/v2/workspaces/{workspace_id}/contents/{content_id}/comments
  8. endpoint
  9. """
  10. fixtures = [BaseFixture, ContentFixtures]
  11. def test_api__get_contents_comments__ok_200__nominal_case(self) -> None:
  12. """
  13. Get alls comments of a content
  14. """
  15. self.testapp.authorization = (
  16. 'Basic',
  17. (
  18. 'admin@admin.admin',
  19. 'admin@admin.admin'
  20. )
  21. )
  22. res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200) # nopep8
  23. assert len(res.json_body) == 3
  24. comment = res.json_body[0]
  25. assert comment['content_id'] == 18
  26. assert comment['parent_id'] == 7
  27. assert comment['raw_content'] == '<p> What is for you the best cake ever ? </br> I personnally vote for Chocolate cupcake !</p>' # nopep8
  28. assert comment['author']
  29. assert comment['author']['user_id'] == 1
  30. # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
  31. assert comment['author']['avatar_url'] == None
  32. assert comment['author']['public_name'] == 'Global manager'
  33. comment = res.json_body[1]
  34. assert comment['content_id'] == 19
  35. assert comment['parent_id'] == 7
  36. assert comment['raw_content'] == '<p>What about Apple Pie ? There are Awesome !</p>' # nopep8
  37. assert comment['author']
  38. assert comment['author']['user_id'] == 3
  39. # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
  40. assert comment['author']['avatar_url'] == None
  41. assert comment['author']['public_name'] == 'Bob i.'
  42. comment = res.json_body[2]
  43. assert comment['content_id'] == 20
  44. assert comment['parent_id'] == 7
  45. assert comment['raw_content'] == '<p>You are right, but Kouign-amann are clearly better.</p>' # nopep8
  46. assert comment['author']
  47. assert comment['author']['user_id'] == 1
  48. # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
  49. assert comment['author']['avatar_url'] == None
  50. assert comment['author']['public_name'] == 'Global manager'
  51. def test_api__post_content_comment__ok_200__nominal_case(self) -> None:
  52. """
  53. Get alls comments of a content
  54. """
  55. self.testapp.authorization = (
  56. 'Basic',
  57. (
  58. 'admin@admin.admin',
  59. 'admin@admin.admin'
  60. )
  61. )
  62. params = {
  63. 'raw_content': 'I strongly disagree, Tiramisu win !'
  64. }
  65. res = self.testapp.post_json(
  66. '/api/v2/workspaces/2/contents/7/comments',
  67. params=params,
  68. status=200
  69. )
  70. comment = res.json_body
  71. assert comment['content_id']
  72. assert comment['parent_id'] == 7
  73. assert comment['raw_content'] == 'I strongly disagree, Tiramisu win !'
  74. assert comment['author']
  75. assert comment['author']['user_id'] == 1
  76. # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
  77. assert comment['author']['avatar_url'] is None
  78. assert comment['author']['public_name'] == 'Global manager'
  79. res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200) # nopep8
  80. assert len(res.json_body) == 4
  81. assert comment == res.json_body[3]
  82. def test_api__delete_content_comment__ok_200__nominal_case(self) -> None:
  83. """
  84. Get alls comments of a content
  85. """
  86. self.testapp.authorization = (
  87. 'Basic',
  88. (
  89. 'admin@admin.admin',
  90. 'admin@admin.admin'
  91. )
  92. )
  93. res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
  94. assert len(res.json_body) == 3
  95. comment = res.json_body[2]
  96. assert comment['content_id'] == 20
  97. assert comment['parent_id'] == 7
  98. assert comment['raw_content'] == '<p>You are right, but Kouign-amann are clearly better.</p>' # nopep8
  99. assert comment['author']
  100. assert comment['author']['user_id'] == 1
  101. # TODO - G.M - 2018-06-172 - [avatar] setup avatar url
  102. assert comment['author']['avatar_url'] is None
  103. assert comment['author']['public_name'] == 'Global manager'
  104. res = self.testapp.delete(
  105. '/api/v2/workspaces/2/contents/7/comments/20',
  106. status=204
  107. )
  108. res = self.testapp.get('/api/v2/workspaces/2/contents/7/comments', status=200)
  109. assert len(res.json_body) == 2
  110. assert not [content for content in res.json_body if content['content_id'] == 20] # nopep8