test_contents.py 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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'] == 27
  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['last_modifier']['user_id'] == 3
  63. assert content['last_modifier']['public_name'] == 'Bob i.'
  64. assert content['last_modifier']['avatar_url'] is None
  65. assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>' # nopep8
  66. def test_api__update_html_document__ok_200__nominal_case(self) -> None:
  67. """
  68. Update(put) one html document of a content
  69. """
  70. self.testapp.authorization = (
  71. 'Basic',
  72. (
  73. 'admin@admin.admin',
  74. 'admin@admin.admin'
  75. )
  76. )
  77. params = {
  78. 'label': 'My New label',
  79. 'raw_content': '<p> Le nouveau contenu </p>',
  80. }
  81. res = self.testapp.put_json(
  82. '/api/v2/workspaces/2/html-documents/6',
  83. params=params,
  84. status=200
  85. )
  86. content = res.json_body
  87. assert content['content_type'] == 'page'
  88. assert content['content_id'] == 6
  89. assert content['is_archived'] is False
  90. assert content['is_deleted'] is False
  91. assert content['label'] == 'My New label'
  92. assert content['parent_id'] == 3
  93. assert content['show_in_ui'] is True
  94. assert content['slug'] == 'my-new-label'
  95. assert content['status'] == 'open'
  96. assert content['workspace_id'] == 2
  97. assert content['current_revision_id'] == 28
  98. # TODO - G.M - 2018-06-173 - check date format
  99. assert content['created']
  100. assert content['author']
  101. assert content['author']['user_id'] == 1
  102. assert content['author']['avatar_url'] is None
  103. assert content['author']['public_name'] == 'Global manager'
  104. # TODO - G.M - 2018-06-173 - check date format
  105. assert content['modified']
  106. assert content['last_modifier'] == content['author']
  107. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  108. res = self.testapp.get(
  109. '/api/v2/workspaces/2/html-documents/6',
  110. status=200
  111. ) # nopep8
  112. content = res.json_body
  113. assert content['content_type'] == 'page'
  114. assert content['content_id'] == 6
  115. assert content['is_archived'] is False
  116. assert content['is_deleted'] is False
  117. assert content['label'] == 'My New label'
  118. assert content['parent_id'] == 3
  119. assert content['show_in_ui'] is True
  120. assert content['slug'] == 'my-new-label'
  121. assert content['status'] == 'open'
  122. assert content['workspace_id'] == 2
  123. assert content['current_revision_id'] == 28
  124. # TODO - G.M - 2018-06-173 - check date format
  125. assert content['created']
  126. assert content['author']
  127. assert content['author']['user_id'] == 1
  128. assert content['author']['avatar_url'] is None
  129. assert content['author']['public_name'] == 'Global manager'
  130. # TODO - G.M - 2018-06-173 - check date format
  131. assert content['modified']
  132. assert content['last_modifier'] == content['author']
  133. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  134. def test_api__get_html_document_revisions__ok_200__nominal_case(
  135. self
  136. ) -> None:
  137. """
  138. Get one html document of a content
  139. """
  140. self.testapp.authorization = (
  141. 'Basic',
  142. (
  143. 'admin@admin.admin',
  144. 'admin@admin.admin'
  145. )
  146. )
  147. res = self.testapp.get(
  148. '/api/v2/workspaces/2/html-documents/6/revisions',
  149. status=200
  150. )
  151. revisions = res.json_body
  152. assert len(revisions) == 3
  153. revision = revisions[0]
  154. assert revision['content_type'] == 'page'
  155. assert revision['content_id'] == 6
  156. assert revision['is_archived'] is False
  157. assert revision['is_deleted'] is False
  158. assert revision['label'] == 'Tiramisu Recipes !!!'
  159. assert revision['parent_id'] == 3
  160. assert revision['show_in_ui'] is True
  161. assert revision['slug'] == 'tiramisu-recipes'
  162. assert revision['status'] == 'open'
  163. assert revision['workspace_id'] == 2
  164. assert revision['revision_id'] == 6
  165. assert revision['sub_content_types']
  166. # TODO - G.M - 2018-06-173 - Test with real comments
  167. assert revision['comments_ids'] == []
  168. # TODO - G.M - 2018-06-173 - check date format
  169. assert revision['created']
  170. assert revision['author']
  171. assert revision['author']['user_id'] == 1
  172. assert revision['author']['avatar_url'] is None
  173. assert revision['author']['public_name'] == 'Global manager'
  174. revision = revisions[1]
  175. assert revision['content_type'] == 'page'
  176. assert revision['content_id'] == 6
  177. assert revision['is_archived'] is False
  178. assert revision['is_deleted'] is False
  179. assert revision['label'] == 'Tiramisu Recipes !!!'
  180. assert revision['parent_id'] == 3
  181. assert revision['show_in_ui'] is True
  182. assert revision['slug'] == 'tiramisu-recipes'
  183. assert revision['status'] == 'open'
  184. assert revision['workspace_id'] == 2
  185. assert revision['revision_id'] == 7
  186. assert revision['sub_content_types']
  187. # TODO - G.M - 2018-06-173 - Test with real comments
  188. assert revision['comments_ids'] == []
  189. # TODO - G.M - 2018-06-173 - check date format
  190. assert revision['created']
  191. assert revision['author']
  192. assert revision['author']['user_id'] == 1
  193. assert revision['author']['avatar_url'] is None
  194. assert revision['author']['public_name'] == 'Global manager'
  195. revision = revisions[2]
  196. assert revision['content_type'] == 'page'
  197. assert revision['content_id'] == 6
  198. assert revision['is_archived'] is False
  199. assert revision['is_deleted'] is False
  200. assert revision['label'] == 'Tiramisu Recipe'
  201. assert revision['parent_id'] == 3
  202. assert revision['show_in_ui'] is True
  203. assert revision['slug'] == 'tiramisu-recipe'
  204. assert revision['status'] == 'open'
  205. assert revision['workspace_id'] == 2
  206. assert revision['revision_id'] == 27
  207. assert revision['sub_content_types']
  208. # TODO - G.M - 2018-06-173 - Test with real comments
  209. assert revision['comments_ids'] == []
  210. # TODO - G.M - 2018-06-173 - check date format
  211. assert revision['created']
  212. assert revision['author']
  213. assert revision['author']['user_id'] == 3
  214. assert revision['author']['avatar_url'] is None
  215. assert revision['author']['public_name'] == 'Bob i.'
  216. def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
  217. """
  218. Get one html document of a content
  219. """
  220. self.testapp.authorization = (
  221. 'Basic',
  222. (
  223. 'admin@admin.admin',
  224. 'admin@admin.admin'
  225. )
  226. )
  227. params = {
  228. 'status': 'closed-deprecated',
  229. }
  230. # before
  231. res = self.testapp.get(
  232. '/api/v2/workspaces/2/html-documents/6',
  233. status=200
  234. ) # nopep8
  235. content = res.json_body
  236. assert content['content_type'] == 'page'
  237. assert content['content_id'] == 6
  238. assert content['status'] == 'open'
  239. # set status
  240. res = self.testapp.put_json(
  241. '/api/v2/workspaces/2/html-documents/6/status',
  242. params=params,
  243. status=204
  244. )
  245. # after
  246. res = self.testapp.get(
  247. '/api/v2/workspaces/2/html-documents/6',
  248. status=200
  249. ) # nopep8
  250. content = res.json_body
  251. assert content['content_type'] == 'page'
  252. assert content['content_id'] == 6
  253. assert content['status'] == 'closed-deprecated'
  254. class TestThreads(FunctionalTest):
  255. """
  256. Tests for /api/v2/workspaces/{workspace_id}/threads/{content_id}
  257. endpoint
  258. """
  259. fixtures = [BaseFixture, ContentFixtures]
  260. def test_api__get_thread__err_400__wrong_content_type(self) -> None:
  261. """
  262. Get one html document of a content
  263. """
  264. self.testapp.authorization = (
  265. 'Basic',
  266. (
  267. 'admin@admin.admin',
  268. 'admin@admin.admin'
  269. )
  270. )
  271. res = self.testapp.get(
  272. '/api/v2/workspaces/2/threads/6',
  273. status=400
  274. ) # nopep8
  275. def test_api__get_thread__ok_200__nominal_case(self) -> None:
  276. """
  277. Get one html document of a content
  278. """
  279. self.testapp.authorization = (
  280. 'Basic',
  281. (
  282. 'admin@admin.admin',
  283. 'admin@admin.admin'
  284. )
  285. )
  286. res = self.testapp.get(
  287. '/api/v2/workspaces/2/threads/7',
  288. status=200
  289. ) # nopep8
  290. content = res.json_body
  291. assert content['content_type'] == 'thread'
  292. assert content['content_id'] == 7
  293. assert content['is_archived'] is False
  294. assert content['is_deleted'] is False
  295. assert content['label'] == 'Best Cakes ?'
  296. assert content['parent_id'] == 3
  297. assert content['show_in_ui'] is True
  298. assert content['slug'] == 'best-cakes'
  299. assert content['status'] == 'open'
  300. assert content['workspace_id'] == 2
  301. assert content['current_revision_id'] == 26
  302. # TODO - G.M - 2018-06-173 - check date format
  303. assert content['created']
  304. assert content['author']
  305. assert content['author']['user_id'] == 1
  306. assert content['author']['avatar_url'] is None
  307. assert content['author']['public_name'] == 'Global manager'
  308. # TODO - G.M - 2018-06-173 - check date format
  309. assert content['modified']
  310. assert content['last_modifier'] != content['author']
  311. assert content['last_modifier']['user_id'] == 3
  312. assert content['last_modifier']['public_name'] == 'Bob i.'
  313. assert content['last_modifier']['avatar_url'] is None
  314. assert content['raw_content'] == 'What is the best cake ?' # nopep8
  315. def test_api__update_thread__ok_200__nominal_case(self) -> None:
  316. """
  317. Update(put) one html document of a content
  318. """
  319. self.testapp.authorization = (
  320. 'Basic',
  321. (
  322. 'admin@admin.admin',
  323. 'admin@admin.admin'
  324. )
  325. )
  326. params = {
  327. 'label': 'My New label',
  328. 'raw_content': '<p> Le nouveau contenu </p>',
  329. }
  330. res = self.testapp.put_json(
  331. '/api/v2/workspaces/2/threads/7',
  332. params=params,
  333. status=200
  334. )
  335. content = res.json_body
  336. assert content['content_type'] == 'thread'
  337. assert content['content_id'] == 7
  338. assert content['is_archived'] is False
  339. assert content['is_deleted'] is False
  340. assert content['label'] == 'My New label'
  341. assert content['parent_id'] == 3
  342. assert content['show_in_ui'] is True
  343. assert content['slug'] == 'my-new-label'
  344. assert content['status'] == 'open'
  345. assert content['workspace_id'] == 2
  346. assert content['current_revision_id'] == 28
  347. # TODO - G.M - 2018-06-173 - check date format
  348. assert content['created']
  349. assert content['author']
  350. assert content['author']['user_id'] == 1
  351. assert content['author']['avatar_url'] is None
  352. assert content['author']['public_name'] == 'Global manager'
  353. # TODO - G.M - 2018-06-173 - check date format
  354. assert content['modified']
  355. assert content['last_modifier'] == content['author']
  356. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  357. res = self.testapp.get(
  358. '/api/v2/workspaces/2/threads/7',
  359. status=200
  360. ) # nopep8
  361. content = res.json_body
  362. assert content['content_type'] == 'thread'
  363. assert content['content_id'] == 7
  364. assert content['is_archived'] is False
  365. assert content['is_deleted'] is False
  366. assert content['label'] == 'My New label'
  367. assert content['parent_id'] == 3
  368. assert content['show_in_ui'] is True
  369. assert content['slug'] == 'my-new-label'
  370. assert content['status'] == 'open'
  371. assert content['workspace_id'] == 2
  372. assert content['current_revision_id'] == 28
  373. # TODO - G.M - 2018-06-173 - check date format
  374. assert content['created']
  375. assert content['author']
  376. assert content['author']['user_id'] == 1
  377. assert content['author']['avatar_url'] is None
  378. assert content['author']['public_name'] == 'Global manager'
  379. # TODO - G.M - 2018-06-173 - check date format
  380. assert content['modified']
  381. assert content['last_modifier'] == content['author']
  382. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  383. def test_api__get_thread_revisions__ok_200__nominal_case(
  384. self
  385. ) -> None:
  386. """
  387. Get one html document of a content
  388. """
  389. self.testapp.authorization = (
  390. 'Basic',
  391. (
  392. 'admin@admin.admin',
  393. 'admin@admin.admin'
  394. )
  395. )
  396. res = self.testapp.get(
  397. '/api/v2/workspaces/2/threads/7/revisions',
  398. status=200
  399. )
  400. revisions = res.json_body
  401. assert len(revisions) == 2
  402. revision = revisions[0]
  403. assert revision['content_type'] == 'thread'
  404. assert revision['content_id'] == 7
  405. assert revision['is_archived'] is False
  406. assert revision['is_deleted'] is False
  407. assert revision['label'] == 'Best Cake'
  408. assert revision['parent_id'] == 3
  409. assert revision['show_in_ui'] is True
  410. assert revision['slug'] == 'best-cake'
  411. assert revision['status'] == 'open'
  412. assert revision['workspace_id'] == 2
  413. assert revision['revision_id'] == 8
  414. assert revision['sub_content_types']
  415. # TODO - G.M - 2018-06-173 - Test with real comments
  416. assert revision['comments_ids'] == []
  417. # TODO - G.M - 2018-06-173 - check date format
  418. assert revision['created']
  419. assert revision['author']
  420. assert revision['author']['user_id'] == 1
  421. assert revision['author']['avatar_url'] is None
  422. assert revision['author']['public_name'] == 'Global manager'
  423. revision = revisions[1]
  424. assert revision['content_type'] == 'thread'
  425. assert revision['content_id'] == 7
  426. assert revision['is_archived'] is False
  427. assert revision['is_deleted'] is False
  428. assert revision['label'] == 'Best Cakes ?'
  429. assert revision['parent_id'] == 3
  430. assert revision['show_in_ui'] is True
  431. assert revision['slug'] == 'best-cakes'
  432. assert revision['status'] == 'open'
  433. assert revision['workspace_id'] == 2
  434. assert revision['revision_id'] == 26
  435. assert revision['sub_content_types']
  436. # TODO - G.M - 2018-06-173 - Test with real comments
  437. assert revision['comments_ids'] == []
  438. # TODO - G.M - 2018-06-173 - check date format
  439. assert revision['created']
  440. assert revision['author']
  441. assert revision['author']['user_id'] == 3
  442. assert revision['author']['avatar_url'] is None
  443. assert revision['author']['public_name'] == 'Bob i.'
  444. def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
  445. """
  446. Get one html document of a content
  447. """
  448. self.testapp.authorization = (
  449. 'Basic',
  450. (
  451. 'admin@admin.admin',
  452. 'admin@admin.admin'
  453. )
  454. )
  455. params = {
  456. 'status': 'closed-deprecated',
  457. }
  458. # before
  459. res = self.testapp.get(
  460. '/api/v2/workspaces/2/threads/7',
  461. status=200
  462. ) # nopep8
  463. content = res.json_body
  464. assert content['content_type'] == 'thread'
  465. assert content['content_id'] == 7
  466. assert content['status'] == 'open'
  467. # set status
  468. res = self.testapp.put_json(
  469. '/api/v2/workspaces/2/threads/7/status',
  470. params=params,
  471. status=204
  472. )
  473. # after
  474. res = self.testapp.get(
  475. '/api/v2/workspaces/2/threads/7',
  476. status=200
  477. ) # nopep8
  478. content = res.json_body
  479. assert content['content_type'] == 'thread'
  480. assert content['content_id'] == 7
  481. assert content['status'] == 'closed-deprecated'