test_contents.py 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 TestHtmlDocuments(FunctionalTest):
  6. """
  7. Tests for /api/v2/workspaces/{workspace_id}/html-documents/{content_id}
  8. endpoint
  9. """
  10. fixtures = [BaseFixture, ContentFixtures]
  11. def test_api__get_html_document__err_400__wrong_content_type(self) -> None:
  12. """
  13. Get one html document 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(
  23. '/api/v2/workspaces/2/html-documents/7',
  24. status=400
  25. ) # nopep8
  26. def test_api__get_html_document__ok_200__nominal_case(self) -> None:
  27. """
  28. Get one html document of a content
  29. """
  30. self.testapp.authorization = (
  31. 'Basic',
  32. (
  33. 'admin@admin.admin',
  34. 'admin@admin.admin'
  35. )
  36. )
  37. res = self.testapp.get(
  38. '/api/v2/workspaces/2/html-documents/6',
  39. status=200
  40. ) # nopep8
  41. content = res.json_body
  42. assert content['content_type'] == 'page'
  43. assert content['content_id'] == 6
  44. assert content['is_archived'] is False
  45. assert content['is_deleted'] is False
  46. assert content['label'] == 'Tiramisu Recipe'
  47. assert content['parent_id'] == 3
  48. assert content['show_in_ui'] is True
  49. assert content['slug'] == 'tiramisu-recipe'
  50. assert content['status'] == 'open'
  51. assert content['workspace_id'] == 2
  52. assert content['current_revision_id'] == 7
  53. # TODO - G.M - 2018-06-173 - check date format
  54. assert content['created']
  55. assert content['author']
  56. assert content['author']['user_id'] == 1
  57. assert content['author']['avatar_url'] is None
  58. assert content['author']['public_name'] == 'Global manager'
  59. # TODO - G.M - 2018-06-173 - check date format
  60. assert content['modified']
  61. assert content['last_modifier'] == content['author']
  62. assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>' # nopep8
  63. def test_api__update_html_document__ok_200__nominal_case(self) -> None:
  64. """
  65. Update(put) one html document of a content
  66. """
  67. self.testapp.authorization = (
  68. 'Basic',
  69. (
  70. 'admin@admin.admin',
  71. 'admin@admin.admin'
  72. )
  73. )
  74. params = {
  75. 'label' : 'My New label',
  76. 'raw_content': '<p> Le nouveau contenu </p>',
  77. }
  78. res = self.testapp.put_json(
  79. '/api/v2/workspaces/2/html-documents/6',
  80. params=params,
  81. status=200
  82. )
  83. content = res.json_body
  84. assert content['content_type'] == 'page'
  85. assert content['content_id'] == 6
  86. assert content['is_archived'] is False
  87. assert content['is_deleted'] is False
  88. assert content['label'] == 'My New label'
  89. assert content['parent_id'] == 3
  90. assert content['show_in_ui'] is True
  91. assert content['slug'] == 'my-new-label'
  92. assert content['status'] == 'open'
  93. assert content['workspace_id'] == 2
  94. assert content['current_revision_id'] == 26
  95. # TODO - G.M - 2018-06-173 - check date format
  96. assert content['created']
  97. assert content['author']
  98. assert content['author']['user_id'] == 1
  99. assert content['author']['avatar_url'] is None
  100. assert content['author']['public_name'] == 'Global manager'
  101. # TODO - G.M - 2018-06-173 - check date format
  102. assert content['modified']
  103. assert content['last_modifier'] == content['author']
  104. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  105. res = self.testapp.get(
  106. '/api/v2/workspaces/2/html-documents/6',
  107. status=200
  108. ) # nopep8
  109. content = res.json_body
  110. assert content['content_type'] == 'page'
  111. assert content['content_id'] == 6
  112. assert content['is_archived'] is False
  113. assert content['is_deleted'] is False
  114. assert content['label'] == 'My New label'
  115. assert content['parent_id'] == 3
  116. assert content['show_in_ui'] is True
  117. assert content['slug'] == 'my-new-label'
  118. assert content['status'] == 'open'
  119. assert content['workspace_id'] == 2
  120. assert content['current_revision_id'] == 26
  121. # TODO - G.M - 2018-06-173 - check date format
  122. assert content['created']
  123. assert content['author']
  124. assert content['author']['user_id'] == 1
  125. assert content['author']['avatar_url'] is None
  126. assert content['author']['public_name'] == 'Global manager'
  127. # TODO - G.M - 2018-06-173 - check date format
  128. assert content['modified']
  129. assert content['last_modifier'] == content['author']
  130. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  131. def test_api__get_html_document_revisions__ok_200__nominal_case(self) -> None:
  132. """
  133. Get one html document of a content
  134. """
  135. self.testapp.authorization = (
  136. 'Basic',
  137. (
  138. 'admin@admin.admin',
  139. 'admin@admin.admin'
  140. )
  141. )
  142. res = self.testapp.get(
  143. '/api/v2/workspaces/2/html-documents/6/revisions',
  144. status=200
  145. )
  146. revisions = res.json_body
  147. assert len(revisions) == 2
  148. revision = revisions[0]
  149. assert revision['content_type'] == 'page'
  150. assert revision['content_id'] == 6
  151. assert revision['is_archived'] is False
  152. assert revision['is_deleted'] is False
  153. assert revision['label'] == 'Tiramisu Recipe'
  154. assert revision['parent_id'] == 3
  155. assert revision['show_in_ui'] is True
  156. assert revision['slug'] == 'tiramisu-recipe'
  157. assert revision['status'] == 'open'
  158. assert revision['workspace_id'] == 2
  159. assert revision['revision_id'] == 6
  160. assert revision['sub_content_types']
  161. # TODO - G.M - 2018-06-173 - Test with real comments
  162. assert revision['comments_ids'] == []
  163. # TODO - G.M - 2018-06-173 - check date format
  164. assert revision['created']
  165. assert revision['author']
  166. assert revision['author']['user_id'] == 1
  167. assert revision['author']['avatar_url'] is None
  168. assert revision['author']['public_name'] == 'Global manager'
  169. def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
  170. """
  171. Get one html document of a content
  172. """
  173. self.testapp.authorization = (
  174. 'Basic',
  175. (
  176. 'admin@admin.admin',
  177. 'admin@admin.admin'
  178. )
  179. )
  180. params = {
  181. 'status': 'closed-deprecated',
  182. }
  183. # before
  184. res = self.testapp.get(
  185. '/api/v2/workspaces/2/html-documents/6',
  186. status=200
  187. ) # nopep8
  188. content = res.json_body
  189. assert content['content_type'] == 'page'
  190. assert content['content_id'] == 6
  191. assert content['status'] == 'open'
  192. # set status
  193. res = self.testapp.put_json(
  194. '/api/v2/workspaces/2/html-documents/6/status',
  195. params=params,
  196. status=204
  197. )
  198. # after
  199. res = self.testapp.get(
  200. '/api/v2/workspaces/2/html-documents/6',
  201. status=200
  202. ) # nopep8
  203. content = res.json_body
  204. assert content['content_type'] == 'page'
  205. assert content['content_id'] == 6
  206. assert content['status'] == 'closed-deprecated'