test_contents.py 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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(
  132. self
  133. ) -> None:
  134. """
  135. Get one html document of a content
  136. """
  137. self.testapp.authorization = (
  138. 'Basic',
  139. (
  140. 'admin@admin.admin',
  141. 'admin@admin.admin'
  142. )
  143. )
  144. res = self.testapp.get(
  145. '/api/v2/workspaces/2/html-documents/6/revisions',
  146. status=200
  147. )
  148. revisions = res.json_body
  149. assert len(revisions) == 2
  150. revision = revisions[0]
  151. assert revision['content_type'] == 'page'
  152. assert revision['content_id'] == 6
  153. assert revision['is_archived'] is False
  154. assert revision['is_deleted'] is False
  155. assert revision['label'] == 'Tiramisu Recipe'
  156. assert revision['parent_id'] == 3
  157. assert revision['show_in_ui'] is True
  158. assert revision['slug'] == 'tiramisu-recipe'
  159. assert revision['status'] == 'open'
  160. assert revision['workspace_id'] == 2
  161. assert revision['revision_id'] == 6
  162. assert revision['sub_content_types']
  163. # TODO - G.M - 2018-06-173 - Test with real comments
  164. assert revision['comments_ids'] == []
  165. # TODO - G.M - 2018-06-173 - check date format
  166. assert revision['created']
  167. assert revision['author']
  168. assert revision['author']['user_id'] == 1
  169. assert revision['author']['avatar_url'] is None
  170. assert revision['author']['public_name'] == 'Global manager'
  171. def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
  172. """
  173. Get one html document of a content
  174. """
  175. self.testapp.authorization = (
  176. 'Basic',
  177. (
  178. 'admin@admin.admin',
  179. 'admin@admin.admin'
  180. )
  181. )
  182. params = {
  183. 'status': 'closed-deprecated',
  184. }
  185. # before
  186. res = self.testapp.get(
  187. '/api/v2/workspaces/2/html-documents/6',
  188. status=200
  189. ) # nopep8
  190. content = res.json_body
  191. assert content['content_type'] == 'page'
  192. assert content['content_id'] == 6
  193. assert content['status'] == 'open'
  194. # set status
  195. res = self.testapp.put_json(
  196. '/api/v2/workspaces/2/html-documents/6/status',
  197. params=params,
  198. status=204
  199. )
  200. # after
  201. res = self.testapp.get(
  202. '/api/v2/workspaces/2/html-documents/6',
  203. status=200
  204. ) # nopep8
  205. content = res.json_body
  206. assert content['content_type'] == 'page'
  207. assert content['content_id'] == 6
  208. assert content['status'] == 'closed-deprecated'
  209. class TestThreads(FunctionalTest):
  210. """
  211. Tests for /api/v2/workspaces/{workspace_id}/threads/{content_id}
  212. endpoint
  213. """
  214. fixtures = [BaseFixture, ContentFixtures]
  215. def test_api__get_thread__err_400__wrong_content_type(self) -> None:
  216. """
  217. Get one html document of a content
  218. """
  219. self.testapp.authorization = (
  220. 'Basic',
  221. (
  222. 'admin@admin.admin',
  223. 'admin@admin.admin'
  224. )
  225. )
  226. res = self.testapp.get(
  227. '/api/v2/workspaces/2/threads/6',
  228. status=400
  229. ) # nopep8
  230. def test_api__get_thread__ok_200__nominal_case(self) -> None:
  231. """
  232. Get one html document of a content
  233. """
  234. self.testapp.authorization = (
  235. 'Basic',
  236. (
  237. 'admin@admin.admin',
  238. 'admin@admin.admin'
  239. )
  240. )
  241. res = self.testapp.get(
  242. '/api/v2/workspaces/2/threads/7',
  243. status=200
  244. ) # nopep8
  245. content = res.json_body
  246. assert content['content_type'] == 'thread'
  247. assert content['content_id'] == 7
  248. assert content['is_archived'] is False
  249. assert content['is_deleted'] is False
  250. assert content['label'] == 'Best Cakes ?'
  251. assert content['parent_id'] == 3
  252. assert content['show_in_ui'] is True
  253. assert content['slug'] == 'best-cakes'
  254. assert content['status'] == 'open'
  255. assert content['workspace_id'] == 2
  256. assert content['current_revision_id'] == 8
  257. # TODO - G.M - 2018-06-173 - check date format
  258. assert content['created']
  259. assert content['author']
  260. assert content['author']['user_id'] == 1
  261. assert content['author']['avatar_url'] is None
  262. assert content['author']['public_name'] == 'Global manager'
  263. # TODO - G.M - 2018-06-173 - check date format
  264. assert content['modified']
  265. assert content['last_modifier'] == content['author']
  266. assert content['raw_content'] == 'What is the best cake ?' # nopep8
  267. def test_api__update_thread__ok_200__nominal_case(self) -> None:
  268. """
  269. Update(put) one html document of a content
  270. """
  271. self.testapp.authorization = (
  272. 'Basic',
  273. (
  274. 'admin@admin.admin',
  275. 'admin@admin.admin'
  276. )
  277. )
  278. params = {
  279. 'label': 'My New label',
  280. 'raw_content': '<p> Le nouveau contenu </p>',
  281. }
  282. res = self.testapp.put_json(
  283. '/api/v2/workspaces/2/threads/7',
  284. params=params,
  285. status=200
  286. )
  287. content = res.json_body
  288. assert content['content_type'] == 'thread'
  289. assert content['content_id'] == 7
  290. assert content['is_archived'] is False
  291. assert content['is_deleted'] is False
  292. assert content['label'] == 'My New label'
  293. assert content['parent_id'] == 3
  294. assert content['show_in_ui'] is True
  295. assert content['slug'] == 'my-new-label'
  296. assert content['status'] == 'open'
  297. assert content['workspace_id'] == 2
  298. assert content['current_revision_id'] == 26
  299. # TODO - G.M - 2018-06-173 - check date format
  300. assert content['created']
  301. assert content['author']
  302. assert content['author']['user_id'] == 1
  303. assert content['author']['avatar_url'] is None
  304. assert content['author']['public_name'] == 'Global manager'
  305. # TODO - G.M - 2018-06-173 - check date format
  306. assert content['modified']
  307. assert content['last_modifier'] == content['author']
  308. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  309. res = self.testapp.get(
  310. '/api/v2/workspaces/2/threads/7',
  311. status=200
  312. ) # nopep8
  313. content = res.json_body
  314. assert content['content_type'] == 'thread'
  315. assert content['content_id'] == 7
  316. assert content['is_archived'] is False
  317. assert content['is_deleted'] is False
  318. assert content['label'] == 'My New label'
  319. assert content['parent_id'] == 3
  320. assert content['show_in_ui'] is True
  321. assert content['slug'] == 'my-new-label'
  322. assert content['status'] == 'open'
  323. assert content['workspace_id'] == 2
  324. assert content['current_revision_id'] == 26
  325. # TODO - G.M - 2018-06-173 - check date format
  326. assert content['created']
  327. assert content['author']
  328. assert content['author']['user_id'] == 1
  329. assert content['author']['avatar_url'] is None
  330. assert content['author']['public_name'] == 'Global manager'
  331. # TODO - G.M - 2018-06-173 - check date format
  332. assert content['modified']
  333. assert content['last_modifier'] == content['author']
  334. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  335. def test_api__get_thread_revisions__ok_200__nominal_case(
  336. self
  337. ) -> None:
  338. """
  339. Get one html document of a content
  340. """
  341. self.testapp.authorization = (
  342. 'Basic',
  343. (
  344. 'admin@admin.admin',
  345. 'admin@admin.admin'
  346. )
  347. )
  348. res = self.testapp.get(
  349. '/api/v2/workspaces/2/threads/7/revisions',
  350. status=200
  351. )
  352. revisions = res.json_body
  353. assert len(revisions) == 1
  354. revision = revisions[0]
  355. assert revision['content_type'] == 'thread'
  356. assert revision['content_id'] == 7
  357. assert revision['is_archived'] is False
  358. assert revision['is_deleted'] is False
  359. assert revision['label'] == 'Best Cakes ?'
  360. assert revision['parent_id'] == 3
  361. assert revision['show_in_ui'] is True
  362. assert revision['slug'] == 'best-cakes'
  363. assert revision['status'] == 'open'
  364. assert revision['workspace_id'] == 2
  365. assert revision['revision_id'] == 8
  366. assert revision['sub_content_types']
  367. # TODO - G.M - 2018-06-173 - Test with real comments
  368. assert revision['comments_ids'] == []
  369. # TODO - G.M - 2018-06-173 - check date format
  370. assert revision['created']
  371. assert revision['author']
  372. assert revision['author']['user_id'] == 1
  373. assert revision['author']['avatar_url'] is None
  374. assert revision['author']['public_name'] == 'Global manager'
  375. def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
  376. """
  377. Get one html document of a content
  378. """
  379. self.testapp.authorization = (
  380. 'Basic',
  381. (
  382. 'admin@admin.admin',
  383. 'admin@admin.admin'
  384. )
  385. )
  386. params = {
  387. 'status': 'closed-deprecated',
  388. }
  389. # before
  390. res = self.testapp.get(
  391. '/api/v2/workspaces/2/threads/7',
  392. status=200
  393. ) # nopep8
  394. content = res.json_body
  395. assert content['content_type'] == 'thread'
  396. assert content['content_id'] == 7
  397. assert content['status'] == 'open'
  398. # set status
  399. res = self.testapp.put_json(
  400. '/api/v2/workspaces/2/threads/7/status',
  401. params=params,
  402. status=204
  403. )
  404. # after
  405. res = self.testapp.get(
  406. '/api/v2/workspaces/2/threads/7',
  407. status=200
  408. ) # nopep8
  409. content = res.json_body
  410. assert content['content_type'] == 'thread'
  411. assert content['content_id'] == 7
  412. assert content['status'] == 'closed-deprecated'