test_contents.py 20KB

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