test_contents.py 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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__ok_200__legacy_slug(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. set_html_document_slug_to_legacy(self.session_factory)
  24. res = self.testapp.get(
  25. '/api/v2/workspaces/2/html-documents/6',
  26. status=200
  27. )
  28. content = res.json_body
  29. assert content['content_type'] == 'html-documents'
  30. assert content['content_id'] == 6
  31. assert content['is_archived'] is False
  32. assert content['is_deleted'] is False
  33. assert content['label'] == 'Tiramisu Recipe'
  34. assert content['parent_id'] == 3
  35. assert content['show_in_ui'] is True
  36. assert content['slug'] == 'tiramisu-recipe'
  37. assert content['status'] == 'open'
  38. assert content['workspace_id'] == 2
  39. assert content['current_revision_id'] == 27
  40. # TODO - G.M - 2018-06-173 - check date format
  41. assert content['created']
  42. assert content['author']
  43. assert content['author']['user_id'] == 1
  44. assert content['author']['avatar_url'] is None
  45. assert content['author']['public_name'] == 'Global manager'
  46. # TODO - G.M - 2018-06-173 - check date format
  47. assert content['modified']
  48. assert content['last_modifier'] != content['author']
  49. assert content['last_modifier']['user_id'] == 3
  50. assert content['last_modifier']['public_name'] == 'Bob i.'
  51. assert content['last_modifier']['avatar_url'] is None
  52. assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>' # nopep8
  53. def test_api__get_html_document__ok_200__nominal_case(self) -> None:
  54. """
  55. Get one html document of a content
  56. """
  57. self.testapp.authorization = (
  58. 'Basic',
  59. (
  60. 'admin@admin.admin',
  61. 'admin@admin.admin'
  62. )
  63. )
  64. res = self.testapp.get(
  65. '/api/v2/workspaces/2/html-documents/6',
  66. status=200
  67. )
  68. content = res.json_body
  69. assert content['content_type'] == 'html-documents'
  70. assert content['content_id'] == 6
  71. assert content['is_archived'] is False
  72. assert content['is_deleted'] is False
  73. assert content['label'] == 'Tiramisu Recipe'
  74. assert content['parent_id'] == 3
  75. assert content['show_in_ui'] is True
  76. assert content['slug'] == 'tiramisu-recipe'
  77. assert content['status'] == 'open'
  78. assert content['workspace_id'] == 2
  79. assert content['current_revision_id'] == 27
  80. # TODO - G.M - 2018-06-173 - check date format
  81. assert content['created']
  82. assert content['author']
  83. assert content['author']['user_id'] == 1
  84. assert content['author']['avatar_url'] is None
  85. assert content['author']['public_name'] == 'Global manager'
  86. # TODO - G.M - 2018-06-173 - check date format
  87. assert content['modified']
  88. assert content['last_modifier'] != content['author']
  89. assert content['last_modifier']['user_id'] == 3
  90. assert content['last_modifier']['public_name'] == 'Bob i.'
  91. assert content['last_modifier']['avatar_url'] is None
  92. assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>' # nopep8
  93. def test_api__get_html_document__err_400__wrong_content_type(self) -> None:
  94. """
  95. Get one html document of a content content 7 is not html_document
  96. """
  97. self.testapp.authorization = (
  98. 'Basic',
  99. (
  100. 'admin@admin.admin',
  101. 'admin@admin.admin'
  102. )
  103. )
  104. res = self.testapp.get(
  105. '/api/v2/workspaces/2/html-documents/7',
  106. status=400
  107. )
  108. def test_api__get_html_document__err_400__content_does_not_exist(self) -> None: # nopep8
  109. """
  110. Get one html document of a content (content 170 does not exist in db
  111. """
  112. self.testapp.authorization = (
  113. 'Basic',
  114. (
  115. 'admin@admin.admin',
  116. 'admin@admin.admin'
  117. )
  118. )
  119. res = self.testapp.get(
  120. '/api/v2/workspaces/2/html-documents/170',
  121. status=400
  122. )
  123. def test_api__get_html_document__err_400__content_not_in_workspace(self) -> None: # nopep8
  124. """
  125. Get one html document of a content (content 6 is in workspace 2)
  126. """
  127. self.testapp.authorization = (
  128. 'Basic',
  129. (
  130. 'admin@admin.admin',
  131. 'admin@admin.admin'
  132. )
  133. )
  134. res = self.testapp.get(
  135. '/api/v2/workspaces/1/html-documents/6',
  136. status=400
  137. )
  138. def test_api__get_html_document__err_400__workspace_does_not_exist(self) -> None: # nopep8
  139. """
  140. Get one html document of a content (Workspace 40 does not exist)
  141. """
  142. self.testapp.authorization = (
  143. 'Basic',
  144. (
  145. 'admin@admin.admin',
  146. 'admin@admin.admin'
  147. )
  148. )
  149. res = self.testapp.get(
  150. '/api/v2/workspaces/40/html-documents/6',
  151. status=400
  152. )
  153. def test_api__update_html_document__ok_200__nominal_case(self) -> None:
  154. """
  155. Update(put) one html document of a content
  156. """
  157. self.testapp.authorization = (
  158. 'Basic',
  159. (
  160. 'admin@admin.admin',
  161. 'admin@admin.admin'
  162. )
  163. )
  164. params = {
  165. 'label': 'My New label',
  166. 'raw_content': '<p> Le nouveau contenu </p>',
  167. }
  168. res = self.testapp.put_json(
  169. '/api/v2/workspaces/2/html-documents/6',
  170. params=params,
  171. status=200
  172. )
  173. content = res.json_body
  174. assert content['content_type'] == 'html-documents'
  175. assert content['content_id'] == 6
  176. assert content['is_archived'] is False
  177. assert content['is_deleted'] is False
  178. assert content['label'] == 'My New label'
  179. assert content['parent_id'] == 3
  180. assert content['show_in_ui'] is True
  181. assert content['slug'] == 'my-new-label'
  182. assert content['status'] == 'open'
  183. assert content['workspace_id'] == 2
  184. assert content['current_revision_id'] == 28
  185. # TODO - G.M - 2018-06-173 - check date format
  186. assert content['created']
  187. assert content['author']
  188. assert content['author']['user_id'] == 1
  189. assert content['author']['avatar_url'] is None
  190. assert content['author']['public_name'] == 'Global manager'
  191. # TODO - G.M - 2018-06-173 - check date format
  192. assert content['modified']
  193. assert content['last_modifier'] == content['author']
  194. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  195. res = self.testapp.get(
  196. '/api/v2/workspaces/2/html-documents/6',
  197. status=200
  198. )
  199. content = res.json_body
  200. assert content['content_type'] == 'html-documents'
  201. assert content['content_id'] == 6
  202. assert content['is_archived'] is False
  203. assert content['is_deleted'] is False
  204. assert content['label'] == 'My New label'
  205. assert content['parent_id'] == 3
  206. assert content['show_in_ui'] is True
  207. assert content['slug'] == 'my-new-label'
  208. assert content['status'] == 'open'
  209. assert content['workspace_id'] == 2
  210. assert content['current_revision_id'] == 28
  211. # TODO - G.M - 2018-06-173 - check date format
  212. assert content['created']
  213. assert content['author']
  214. assert content['author']['user_id'] == 1
  215. assert content['author']['avatar_url'] is None
  216. assert content['author']['public_name'] == 'Global manager'
  217. # TODO - G.M - 2018-06-173 - check date format
  218. assert content['modified']
  219. assert content['last_modifier'] == content['author']
  220. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  221. def test_api__get_html_document_revisions__ok_200__nominal_case(
  222. self
  223. ) -> None:
  224. """
  225. Get one html document of a content
  226. """
  227. self.testapp.authorization = (
  228. 'Basic',
  229. (
  230. 'admin@admin.admin',
  231. 'admin@admin.admin'
  232. )
  233. )
  234. res = self.testapp.get(
  235. '/api/v2/workspaces/2/html-documents/6/revisions',
  236. status=200
  237. )
  238. revisions = res.json_body
  239. assert len(revisions) == 3
  240. revision = revisions[0]
  241. assert revision['content_type'] == 'html-documents'
  242. assert revision['content_id'] == 6
  243. assert revision['is_archived'] is False
  244. assert revision['is_deleted'] is False
  245. assert revision['label'] == 'Tiramisu Recipes!!!'
  246. assert revision['parent_id'] == 3
  247. assert revision['show_in_ui'] is True
  248. assert revision['slug'] == 'tiramisu-recipes'
  249. assert revision['status'] == 'open'
  250. assert revision['workspace_id'] == 2
  251. assert revision['revision_id'] == 6
  252. assert revision['sub_content_types']
  253. # TODO - G.M - 2018-06-173 - Test with real comments
  254. assert revision['comment_ids'] == []
  255. # TODO - G.M - 2018-06-173 - check date format
  256. assert revision['created']
  257. assert revision['author']
  258. assert revision['author']['user_id'] == 1
  259. assert revision['author']['avatar_url'] is None
  260. assert revision['author']['public_name'] == 'Global manager'
  261. revision = revisions[1]
  262. assert revision['content_type'] == 'html-documents'
  263. assert revision['content_id'] == 6
  264. assert revision['is_archived'] is False
  265. assert revision['is_deleted'] is False
  266. assert revision['label'] == 'Tiramisu Recipes!!!'
  267. assert revision['parent_id'] == 3
  268. assert revision['show_in_ui'] is True
  269. assert revision['slug'] == 'tiramisu-recipes'
  270. assert revision['status'] == 'open'
  271. assert revision['workspace_id'] == 2
  272. assert revision['revision_id'] == 7
  273. assert revision['sub_content_types']
  274. # TODO - G.M - 2018-06-173 - Test with real comments
  275. assert revision['comment_ids'] == []
  276. # TODO - G.M - 2018-06-173 - check date format
  277. assert revision['created']
  278. assert revision['author']
  279. assert revision['author']['user_id'] == 1
  280. assert revision['author']['avatar_url'] is None
  281. assert revision['author']['public_name'] == 'Global manager'
  282. revision = revisions[2]
  283. assert revision['content_type'] == 'html-documents'
  284. assert revision['content_id'] == 6
  285. assert revision['is_archived'] is False
  286. assert revision['is_deleted'] is False
  287. assert revision['label'] == 'Tiramisu Recipe'
  288. assert revision['parent_id'] == 3
  289. assert revision['show_in_ui'] is True
  290. assert revision['slug'] == 'tiramisu-recipe'
  291. assert revision['status'] == 'open'
  292. assert revision['workspace_id'] == 2
  293. assert revision['revision_id'] == 27
  294. assert revision['sub_content_types']
  295. # TODO - G.M - 2018-06-173 - Test with real comments
  296. assert revision['comment_ids'] == []
  297. # TODO - G.M - 2018-06-173 - check date format
  298. assert revision['created']
  299. assert revision['author']
  300. assert revision['author']['user_id'] == 3
  301. assert revision['author']['avatar_url'] is None
  302. assert revision['author']['public_name'] == 'Bob i.'
  303. def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
  304. """
  305. Get one html document of a content
  306. """
  307. self.testapp.authorization = (
  308. 'Basic',
  309. (
  310. 'admin@admin.admin',
  311. 'admin@admin.admin'
  312. )
  313. )
  314. params = {
  315. 'status': 'closed-deprecated',
  316. }
  317. # before
  318. res = self.testapp.get(
  319. '/api/v2/workspaces/2/html-documents/6',
  320. status=200
  321. )
  322. content = res.json_body
  323. assert content['content_type'] == 'html-documents'
  324. assert content['content_id'] == 6
  325. assert content['status'] == 'open'
  326. # set status
  327. res = self.testapp.put_json(
  328. '/api/v2/workspaces/2/html-documents/6/status',
  329. params=params,
  330. status=204
  331. )
  332. # after
  333. res = self.testapp.get(
  334. '/api/v2/workspaces/2/html-documents/6',
  335. status=200
  336. )
  337. content = res.json_body
  338. assert content['content_type'] == 'html-documents'
  339. assert content['content_id'] == 6
  340. assert content['status'] == 'closed-deprecated'
  341. class TestThreads(FunctionalTest):
  342. """
  343. Tests for /api/v2/workspaces/{workspace_id}/threads/{content_id}
  344. endpoint
  345. """
  346. fixtures = [BaseFixture, ContentFixtures]
  347. def test_api__get_thread__err_400__wrong_content_type(self) -> None:
  348. """
  349. Get one html document of a content
  350. """
  351. self.testapp.authorization = (
  352. 'Basic',
  353. (
  354. 'admin@admin.admin',
  355. 'admin@admin.admin'
  356. )
  357. )
  358. res = self.testapp.get(
  359. '/api/v2/workspaces/2/threads/6',
  360. status=400
  361. )
  362. def test_api__get_thread__ok_200__nominal_case(self) -> None:
  363. """
  364. Get one html document of a content
  365. """
  366. self.testapp.authorization = (
  367. 'Basic',
  368. (
  369. 'admin@admin.admin',
  370. 'admin@admin.admin'
  371. )
  372. )
  373. res = self.testapp.get(
  374. '/api/v2/workspaces/2/threads/7',
  375. status=200
  376. ) # nopep8
  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'] == 'Best Cakes?'
  383. assert content['parent_id'] == 3
  384. assert content['show_in_ui'] is True
  385. assert content['slug'] == 'best-cakes'
  386. assert content['status'] == 'open'
  387. assert content['workspace_id'] == 2
  388. assert content['current_revision_id'] == 26
  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['last_modifier']['user_id'] == 3
  399. assert content['last_modifier']['public_name'] == 'Bob i.'
  400. assert content['last_modifier']['avatar_url'] is None
  401. assert content['raw_content'] == 'What is the best cake?' # nopep8
  402. def test_api__get_thread__err_400__content_does_not_exist(self) -> None:
  403. """
  404. Get one thread (content 170 does not exist)
  405. """
  406. self.testapp.authorization = (
  407. 'Basic',
  408. (
  409. 'admin@admin.admin',
  410. 'admin@admin.admin'
  411. )
  412. )
  413. res = self.testapp.get(
  414. '/api/v2/workspaces/2/threads/170',
  415. status=400
  416. )
  417. def test_api__get_thread__err_400__content_not_in_workspace(self) -> None:
  418. """
  419. Get one thread(content 7 is in workspace 2)
  420. """
  421. self.testapp.authorization = (
  422. 'Basic',
  423. (
  424. 'admin@admin.admin',
  425. 'admin@admin.admin'
  426. )
  427. )
  428. res = self.testapp.get(
  429. '/api/v2/workspaces/1/threads/7',
  430. status=400
  431. )
  432. def test_api__get_thread__err_400__workspace_does_not_exist(self) -> None: # nopep8
  433. """
  434. Get one thread (Workspace 40 does not exist)
  435. """
  436. self.testapp.authorization = (
  437. 'Basic',
  438. (
  439. 'admin@admin.admin',
  440. 'admin@admin.admin'
  441. )
  442. )
  443. res = self.testapp.get(
  444. '/api/v2/workspaces/40/threads/7',
  445. status=400
  446. )
  447. def test_api__update_thread__ok_200__nominal_case(self) -> None:
  448. """
  449. Update(put) thread
  450. """
  451. self.testapp.authorization = (
  452. 'Basic',
  453. (
  454. 'admin@admin.admin',
  455. 'admin@admin.admin'
  456. )
  457. )
  458. params = {
  459. 'label': 'My New label',
  460. 'raw_content': '<p> Le nouveau contenu </p>',
  461. }
  462. res = self.testapp.put_json(
  463. '/api/v2/workspaces/2/threads/7',
  464. params=params,
  465. status=200
  466. )
  467. content = res.json_body
  468. assert content['content_type'] == 'thread'
  469. assert content['content_id'] == 7
  470. assert content['is_archived'] is False
  471. assert content['is_deleted'] is False
  472. assert content['label'] == 'My New label'
  473. assert content['parent_id'] == 3
  474. assert content['show_in_ui'] is True
  475. assert content['slug'] == 'my-new-label'
  476. assert content['status'] == 'open'
  477. assert content['workspace_id'] == 2
  478. assert content['current_revision_id'] == 28
  479. # TODO - G.M - 2018-06-173 - check date format
  480. assert content['created']
  481. assert content['author']
  482. assert content['author']['user_id'] == 1
  483. assert content['author']['avatar_url'] is None
  484. assert content['author']['public_name'] == 'Global manager'
  485. # TODO - G.M - 2018-06-173 - check date format
  486. assert content['modified']
  487. assert content['last_modifier'] == content['author']
  488. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  489. res = self.testapp.get(
  490. '/api/v2/workspaces/2/threads/7',
  491. status=200
  492. ) # nopep8
  493. content = res.json_body
  494. assert content['content_type'] == 'thread'
  495. assert content['content_id'] == 7
  496. assert content['is_archived'] is False
  497. assert content['is_deleted'] is False
  498. assert content['label'] == 'My New label'
  499. assert content['parent_id'] == 3
  500. assert content['show_in_ui'] is True
  501. assert content['slug'] == 'my-new-label'
  502. assert content['status'] == 'open'
  503. assert content['workspace_id'] == 2
  504. assert content['current_revision_id'] == 28
  505. # TODO - G.M - 2018-06-173 - check date format
  506. assert content['created']
  507. assert content['author']
  508. assert content['author']['user_id'] == 1
  509. assert content['author']['avatar_url'] is None
  510. assert content['author']['public_name'] == 'Global manager'
  511. # TODO - G.M - 2018-06-173 - check date format
  512. assert content['modified']
  513. assert content['last_modifier'] == content['author']
  514. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  515. def test_api__get_thread_revisions__ok_200__nominal_case(
  516. self
  517. ) -> None:
  518. """
  519. Get threads revisions
  520. """
  521. self.testapp.authorization = (
  522. 'Basic',
  523. (
  524. 'admin@admin.admin',
  525. 'admin@admin.admin'
  526. )
  527. )
  528. res = self.testapp.get(
  529. '/api/v2/workspaces/2/threads/7/revisions',
  530. status=200
  531. )
  532. revisions = res.json_body
  533. assert len(revisions) == 2
  534. revision = revisions[0]
  535. assert revision['content_type'] == 'thread'
  536. assert revision['content_id'] == 7
  537. assert revision['is_archived'] is False
  538. assert revision['is_deleted'] is False
  539. assert revision['label'] == 'Best Cake'
  540. assert revision['parent_id'] == 3
  541. assert revision['show_in_ui'] is True
  542. assert revision['slug'] == 'best-cake'
  543. assert revision['status'] == 'open'
  544. assert revision['workspace_id'] == 2
  545. assert revision['revision_id'] == 8
  546. assert revision['sub_content_types']
  547. assert revision['comment_ids'] == [18, 19, 20]
  548. # TODO - G.M - 2018-06-173 - check date format
  549. assert revision['created']
  550. assert revision['author']
  551. assert revision['author']['user_id'] == 1
  552. assert revision['author']['avatar_url'] is None
  553. assert revision['author']['public_name'] == 'Global manager'
  554. revision = revisions[1]
  555. assert revision['content_type'] == 'thread'
  556. assert revision['content_id'] == 7
  557. assert revision['is_archived'] is False
  558. assert revision['is_deleted'] is False
  559. assert revision['label'] == 'Best Cakes?'
  560. assert revision['parent_id'] == 3
  561. assert revision['show_in_ui'] is True
  562. assert revision['slug'] == 'best-cakes'
  563. assert revision['status'] == 'open'
  564. assert revision['workspace_id'] == 2
  565. assert revision['revision_id'] == 26
  566. assert revision['sub_content_types']
  567. assert revision['comment_ids'] == []
  568. # TODO - G.M - 2018-06-173 - check date format
  569. assert revision['created']
  570. assert revision['author']
  571. assert revision['author']['user_id'] == 3
  572. assert revision['author']['avatar_url'] is None
  573. assert revision['author']['public_name'] == 'Bob i.'
  574. def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
  575. """
  576. Set thread status
  577. """
  578. self.testapp.authorization = (
  579. 'Basic',
  580. (
  581. 'admin@admin.admin',
  582. 'admin@admin.admin'
  583. )
  584. )
  585. params = {
  586. 'status': 'closed-deprecated',
  587. }
  588. # before
  589. res = self.testapp.get(
  590. '/api/v2/workspaces/2/threads/7',
  591. status=200
  592. ) # nopep8
  593. content = res.json_body
  594. assert content['content_type'] == 'thread'
  595. assert content['content_id'] == 7
  596. assert content['status'] == 'open'
  597. # set status
  598. res = self.testapp.put_json(
  599. '/api/v2/workspaces/2/threads/7/status',
  600. params=params,
  601. status=204
  602. )
  603. # after
  604. res = self.testapp.get(
  605. '/api/v2/workspaces/2/threads/7',
  606. status=200
  607. ) # nopep8
  608. content = res.json_body
  609. assert content['content_type'] == 'thread'
  610. assert content['content_id'] == 7
  611. assert content['status'] == 'closed-deprecated'