test_comments.py 4.8KB

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