test_contents.py 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. # -*- coding: utf-8 -*-
  2. import transaction
  3. from tracim import models
  4. from tracim.lib.core.content import ContentApi
  5. from tracim.lib.core.workspace import WorkspaceApi
  6. from tracim.models import get_tm_session
  7. from tracim.models.contents import ContentTypeLegacy as ContentType
  8. from tracim.models.revision_protection import new_revision
  9. from tracim.tests import FunctionalTest
  10. from tracim.tests import set_html_document_slug_to_legacy
  11. from tracim.fixtures.content import Content as ContentFixtures
  12. from tracim.fixtures.users_and_groups import Base as BaseFixture
  13. class TestHtmlDocuments(FunctionalTest):
  14. """
  15. Tests for /api/v2/workspaces/{workspace_id}/html-documents/{content_id}
  16. endpoint
  17. """
  18. fixtures = [BaseFixture, ContentFixtures]
  19. def test_api__get_html_document__ok_200__legacy_slug(self) -> None:
  20. """
  21. Get one html document of a content
  22. """
  23. self.testapp.authorization = (
  24. 'Basic',
  25. (
  26. 'admin@admin.admin',
  27. 'admin@admin.admin'
  28. )
  29. )
  30. set_html_document_slug_to_legacy(self.session_factory)
  31. res = self.testapp.get(
  32. '/api/v2/workspaces/2/html-documents/6',
  33. status=200
  34. )
  35. content = res.json_body
  36. assert content['content_type'] == 'html-documents'
  37. assert content['content_id'] == 6
  38. assert content['is_archived'] is False
  39. assert content['is_deleted'] is False
  40. assert content['label'] == 'Tiramisu Recipe'
  41. assert content['parent_id'] == 3
  42. assert content['show_in_ui'] is True
  43. assert content['slug'] == 'tiramisu-recipe'
  44. assert content['status'] == 'open'
  45. assert content['workspace_id'] == 2
  46. assert content['current_revision_id'] == 27
  47. # TODO - G.M - 2018-06-173 - check date format
  48. assert content['created']
  49. assert content['author']
  50. assert content['author']['user_id'] == 1
  51. assert content['author']['avatar_url'] is None
  52. assert content['author']['public_name'] == 'Global manager'
  53. # TODO - G.M - 2018-06-173 - check date format
  54. assert content['modified']
  55. assert content['last_modifier'] != content['author']
  56. assert content['last_modifier']['user_id'] == 3
  57. assert content['last_modifier']['public_name'] == 'Bob i.'
  58. assert content['last_modifier']['avatar_url'] is None
  59. assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>' # nopep8
  60. def test_api__get_html_document__ok_200__nominal_case(self) -> None:
  61. """
  62. Get one html document of a content
  63. """
  64. self.testapp.authorization = (
  65. 'Basic',
  66. (
  67. 'admin@admin.admin',
  68. 'admin@admin.admin'
  69. )
  70. )
  71. res = self.testapp.get(
  72. '/api/v2/workspaces/2/html-documents/6',
  73. status=200
  74. )
  75. content = res.json_body
  76. assert content['content_type'] == 'html-documents'
  77. assert content['content_id'] == 6
  78. assert content['is_archived'] is False
  79. assert content['is_deleted'] is False
  80. assert content['label'] == 'Tiramisu Recipe'
  81. assert content['parent_id'] == 3
  82. assert content['show_in_ui'] is True
  83. assert content['slug'] == 'tiramisu-recipe'
  84. assert content['status'] == 'open'
  85. assert content['workspace_id'] == 2
  86. assert content['current_revision_id'] == 27
  87. # TODO - G.M - 2018-06-173 - check date format
  88. assert content['created']
  89. assert content['author']
  90. assert content['author']['user_id'] == 1
  91. assert content['author']['avatar_url'] is None
  92. assert content['author']['public_name'] == 'Global manager'
  93. # TODO - G.M - 2018-06-173 - check date format
  94. assert content['modified']
  95. assert content['last_modifier'] != content['author']
  96. assert content['last_modifier']['user_id'] == 3
  97. assert content['last_modifier']['public_name'] == 'Bob i.'
  98. assert content['last_modifier']['avatar_url'] is None
  99. assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>' # nopep8
  100. def test_api__get_html_document__err_400__wrong_content_type(self) -> None:
  101. """
  102. Get one html document of a content content 7 is not html_document
  103. """
  104. self.testapp.authorization = (
  105. 'Basic',
  106. (
  107. 'admin@admin.admin',
  108. 'admin@admin.admin'
  109. )
  110. )
  111. res = self.testapp.get(
  112. '/api/v2/workspaces/2/html-documents/7',
  113. status=400
  114. )
  115. def test_api__get_html_document__err_400__content_does_not_exist(self) -> None: # nopep8
  116. """
  117. Get one html document of a content (content 170 does not exist in db
  118. """
  119. self.testapp.authorization = (
  120. 'Basic',
  121. (
  122. 'admin@admin.admin',
  123. 'admin@admin.admin'
  124. )
  125. )
  126. res = self.testapp.get(
  127. '/api/v2/workspaces/2/html-documents/170',
  128. status=400
  129. )
  130. def test_api__get_html_document__err_400__content_not_in_workspace(self) -> None: # nopep8
  131. """
  132. Get one html document of a content (content 6 is in workspace 2)
  133. """
  134. self.testapp.authorization = (
  135. 'Basic',
  136. (
  137. 'admin@admin.admin',
  138. 'admin@admin.admin'
  139. )
  140. )
  141. res = self.testapp.get(
  142. '/api/v2/workspaces/1/html-documents/6',
  143. status=400
  144. )
  145. def test_api__get_html_document__err_400__workspace_does_not_exist(self) -> None: # nopep8
  146. """
  147. Get one html document of a content (Workspace 40 does not exist)
  148. """
  149. self.testapp.authorization = (
  150. 'Basic',
  151. (
  152. 'admin@admin.admin',
  153. 'admin@admin.admin'
  154. )
  155. )
  156. res = self.testapp.get(
  157. '/api/v2/workspaces/40/html-documents/6',
  158. status=400
  159. )
  160. def test_api__get_html_document__err_400__workspace_id_is_not_int(self) -> None: # nopep8
  161. """
  162. Get one html document of a content, workspace id is not int
  163. """
  164. self.testapp.authorization = (
  165. 'Basic',
  166. (
  167. 'admin@admin.admin',
  168. 'admin@admin.admin'
  169. )
  170. )
  171. res = self.testapp.get(
  172. '/api/v2/workspaces/coucou/html-documents/6',
  173. status=400
  174. )
  175. def test_api__get_html_document__err_400__content_id_is_not_int(self) -> None: # nopep8
  176. """
  177. Get one html document of a content, content_id is not int
  178. """
  179. self.testapp.authorization = (
  180. 'Basic',
  181. (
  182. 'admin@admin.admin',
  183. 'admin@admin.admin'
  184. )
  185. )
  186. res = self.testapp.get(
  187. '/api/v2/workspaces/2/html-documents/coucou',
  188. status=400
  189. )
  190. def test_api__update_html_document__err_400__empty_label(self) -> None: # nopep8
  191. """
  192. Update(put) one html document of a content
  193. """
  194. self.testapp.authorization = (
  195. 'Basic',
  196. (
  197. 'admin@admin.admin',
  198. 'admin@admin.admin'
  199. )
  200. )
  201. params = {
  202. 'label': '',
  203. 'raw_content': '<p> Le nouveau contenu </p>',
  204. }
  205. res = self.testapp.put_json(
  206. '/api/v2/workspaces/2/html-documents/6',
  207. params=params,
  208. status=400
  209. )
  210. def test_api__update_html_document__ok_200__nominal_case(self) -> None:
  211. """
  212. Update(put) one html document of a content
  213. """
  214. self.testapp.authorization = (
  215. 'Basic',
  216. (
  217. 'admin@admin.admin',
  218. 'admin@admin.admin'
  219. )
  220. )
  221. params = {
  222. 'label': 'My New label',
  223. 'raw_content': '<p> Le nouveau contenu </p>',
  224. }
  225. res = self.testapp.put_json(
  226. '/api/v2/workspaces/2/html-documents/6',
  227. params=params,
  228. status=200
  229. )
  230. content = res.json_body
  231. assert content['content_type'] == 'html-documents'
  232. assert content['content_id'] == 6
  233. assert content['is_archived'] is False
  234. assert content['is_deleted'] is False
  235. assert content['label'] == 'My New label'
  236. assert content['parent_id'] == 3
  237. assert content['show_in_ui'] is True
  238. assert content['slug'] == 'my-new-label'
  239. assert content['status'] == 'open'
  240. assert content['workspace_id'] == 2
  241. assert content['current_revision_id'] == 28
  242. # TODO - G.M - 2018-06-173 - check date format
  243. assert content['created']
  244. assert content['author']
  245. assert content['author']['user_id'] == 1
  246. assert content['author']['avatar_url'] is None
  247. assert content['author']['public_name'] == 'Global manager'
  248. # TODO - G.M - 2018-06-173 - check date format
  249. assert content['modified']
  250. assert content['last_modifier'] == content['author']
  251. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  252. res = self.testapp.get(
  253. '/api/v2/workspaces/2/html-documents/6',
  254. status=200
  255. )
  256. content = res.json_body
  257. assert content['content_type'] == 'html-documents'
  258. assert content['content_id'] == 6
  259. assert content['is_archived'] is False
  260. assert content['is_deleted'] is False
  261. assert content['label'] == 'My New label'
  262. assert content['parent_id'] == 3
  263. assert content['show_in_ui'] is True
  264. assert content['slug'] == 'my-new-label'
  265. assert content['status'] == 'open'
  266. assert content['workspace_id'] == 2
  267. assert content['current_revision_id'] == 28
  268. # TODO - G.M - 2018-06-173 - check date format
  269. assert content['created']
  270. assert content['author']
  271. assert content['author']['user_id'] == 1
  272. assert content['author']['avatar_url'] is None
  273. assert content['author']['public_name'] == 'Global manager'
  274. # TODO - G.M - 2018-06-173 - check date format
  275. assert content['modified']
  276. assert content['last_modifier'] == content['author']
  277. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  278. def test_api__get_html_document_revisions__ok_200__nominal_case(
  279. self
  280. ) -> None:
  281. """
  282. Get one html document of a content
  283. """
  284. self.testapp.authorization = (
  285. 'Basic',
  286. (
  287. 'admin@admin.admin',
  288. 'admin@admin.admin'
  289. )
  290. )
  291. res = self.testapp.get(
  292. '/api/v2/workspaces/2/html-documents/6/revisions',
  293. status=200
  294. )
  295. revisions = res.json_body
  296. assert len(revisions) == 3
  297. revision = revisions[0]
  298. assert revision['content_type'] == 'html-documents'
  299. assert revision['content_id'] == 6
  300. assert revision['is_archived'] is False
  301. assert revision['is_deleted'] is False
  302. assert revision['label'] == 'Tiramisu Recipes!!!'
  303. assert revision['parent_id'] == 3
  304. assert revision['show_in_ui'] is True
  305. assert revision['slug'] == 'tiramisu-recipes'
  306. assert revision['status'] == 'open'
  307. assert revision['workspace_id'] == 2
  308. assert revision['revision_id'] == 6
  309. assert revision['revision_type'] == 'creation'
  310. assert revision['sub_content_types']
  311. # TODO - G.M - 2018-06-173 - Test with real comments
  312. assert revision['comment_ids'] == []
  313. # TODO - G.M - 2018-06-173 - check date format
  314. assert revision['created']
  315. assert revision['author']
  316. assert revision['author']['user_id'] == 1
  317. assert revision['author']['avatar_url'] is None
  318. assert revision['author']['public_name'] == 'Global manager'
  319. revision = revisions[1]
  320. assert revision['content_type'] == 'html-documents'
  321. assert revision['content_id'] == 6
  322. assert revision['is_archived'] is False
  323. assert revision['is_deleted'] is False
  324. assert revision['label'] == 'Tiramisu Recipes!!!'
  325. assert revision['parent_id'] == 3
  326. assert revision['show_in_ui'] is True
  327. assert revision['slug'] == 'tiramisu-recipes'
  328. assert revision['status'] == 'open'
  329. assert revision['workspace_id'] == 2
  330. assert revision['revision_id'] == 7
  331. assert revision['revision_type'] == 'edition'
  332. assert revision['sub_content_types']
  333. # TODO - G.M - 2018-06-173 - Test with real comments
  334. assert revision['comment_ids'] == []
  335. # TODO - G.M - 2018-06-173 - check date format
  336. assert revision['created']
  337. assert revision['author']
  338. assert revision['author']['user_id'] == 1
  339. assert revision['author']['avatar_url'] is None
  340. assert revision['author']['public_name'] == 'Global manager'
  341. revision = revisions[2]
  342. assert revision['content_type'] == 'html-documents'
  343. assert revision['content_id'] == 6
  344. assert revision['is_archived'] is False
  345. assert revision['is_deleted'] is False
  346. assert revision['label'] == 'Tiramisu Recipe'
  347. assert revision['parent_id'] == 3
  348. assert revision['show_in_ui'] is True
  349. assert revision['slug'] == 'tiramisu-recipe'
  350. assert revision['status'] == 'open'
  351. assert revision['workspace_id'] == 2
  352. assert revision['revision_id'] == 27
  353. assert revision['revision_type'] == 'edition'
  354. assert revision['sub_content_types']
  355. # TODO - G.M - 2018-06-173 - Test with real comments
  356. assert revision['comment_ids'] == []
  357. # TODO - G.M - 2018-06-173 - check date format
  358. assert revision['created']
  359. assert revision['author']
  360. assert revision['author']['user_id'] == 3
  361. assert revision['author']['avatar_url'] is None
  362. assert revision['author']['public_name'] == 'Bob i.'
  363. def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
  364. """
  365. Get one html document of a content
  366. """
  367. self.testapp.authorization = (
  368. 'Basic',
  369. (
  370. 'admin@admin.admin',
  371. 'admin@admin.admin'
  372. )
  373. )
  374. params = {
  375. 'status': 'closed-deprecated',
  376. }
  377. # before
  378. res = self.testapp.get(
  379. '/api/v2/workspaces/2/html-documents/6',
  380. status=200
  381. )
  382. content = res.json_body
  383. assert content['content_type'] == 'html-documents'
  384. assert content['content_id'] == 6
  385. assert content['status'] == 'open'
  386. # set status
  387. res = self.testapp.put_json(
  388. '/api/v2/workspaces/2/html-documents/6/status',
  389. params=params,
  390. status=204
  391. )
  392. # after
  393. res = self.testapp.get(
  394. '/api/v2/workspaces/2/html-documents/6',
  395. status=200
  396. )
  397. content = res.json_body
  398. assert content['content_type'] == 'html-documents'
  399. assert content['content_id'] == 6
  400. assert content['status'] == 'closed-deprecated'
  401. def test_api__set_html_document_status__err_400__wrong_status(self) -> None:
  402. """
  403. Get one html document of a content
  404. """
  405. self.testapp.authorization = (
  406. 'Basic',
  407. (
  408. 'admin@admin.admin',
  409. 'admin@admin.admin'
  410. )
  411. )
  412. params = {
  413. 'status': 'unexistant-status',
  414. }
  415. res = self.testapp.put_json(
  416. '/api/v2/workspaces/2/html-documents/6/status',
  417. params=params,
  418. status=400
  419. )
  420. class TestThreads(FunctionalTest):
  421. """
  422. Tests for /api/v2/workspaces/{workspace_id}/threads/{content_id}
  423. endpoint
  424. """
  425. fixtures = [BaseFixture, ContentFixtures]
  426. def test_api__get_thread__err_400__wrong_content_type(self) -> None:
  427. """
  428. Get one html document of a content
  429. """
  430. self.testapp.authorization = (
  431. 'Basic',
  432. (
  433. 'admin@admin.admin',
  434. 'admin@admin.admin'
  435. )
  436. )
  437. res = self.testapp.get(
  438. '/api/v2/workspaces/2/threads/6',
  439. status=400
  440. )
  441. def test_api__get_thread__ok_200__nominal_case(self) -> None:
  442. """
  443. Get one html document of a content
  444. """
  445. self.testapp.authorization = (
  446. 'Basic',
  447. (
  448. 'admin@admin.admin',
  449. 'admin@admin.admin'
  450. )
  451. )
  452. res = self.testapp.get(
  453. '/api/v2/workspaces/2/threads/7',
  454. status=200
  455. ) # nopep8
  456. content = res.json_body
  457. assert content['content_type'] == 'thread'
  458. assert content['content_id'] == 7
  459. assert content['is_archived'] is False
  460. assert content['is_deleted'] is False
  461. assert content['label'] == 'Best Cakes?'
  462. assert content['parent_id'] == 3
  463. assert content['show_in_ui'] is True
  464. assert content['slug'] == 'best-cakes'
  465. assert content['status'] == 'open'
  466. assert content['workspace_id'] == 2
  467. assert content['current_revision_id'] == 26
  468. # TODO - G.M - 2018-06-173 - check date format
  469. assert content['created']
  470. assert content['author']
  471. assert content['author']['user_id'] == 1
  472. assert content['author']['avatar_url'] is None
  473. assert content['author']['public_name'] == 'Global manager'
  474. # TODO - G.M - 2018-06-173 - check date format
  475. assert content['modified']
  476. assert content['last_modifier'] != content['author']
  477. assert content['last_modifier']['user_id'] == 3
  478. assert content['last_modifier']['public_name'] == 'Bob i.'
  479. assert content['last_modifier']['avatar_url'] is None
  480. assert content['raw_content'] == 'What is the best cake?' # nopep8
  481. def test_api__get_thread__err_400__content_does_not_exist(self) -> None:
  482. """
  483. Get one thread (content 170 does not exist)
  484. """
  485. self.testapp.authorization = (
  486. 'Basic',
  487. (
  488. 'admin@admin.admin',
  489. 'admin@admin.admin'
  490. )
  491. )
  492. res = self.testapp.get(
  493. '/api/v2/workspaces/2/threads/170',
  494. status=400
  495. )
  496. def test_api__get_thread__err_400__content_not_in_workspace(self) -> None:
  497. """
  498. Get one thread(content 7 is in workspace 2)
  499. """
  500. self.testapp.authorization = (
  501. 'Basic',
  502. (
  503. 'admin@admin.admin',
  504. 'admin@admin.admin'
  505. )
  506. )
  507. res = self.testapp.get(
  508. '/api/v2/workspaces/1/threads/7',
  509. status=400
  510. )
  511. def test_api__get_thread__err_400__workspace_does_not_exist(self) -> None: # nopep8
  512. """
  513. Get one thread (Workspace 40 does not exist)
  514. """
  515. self.testapp.authorization = (
  516. 'Basic',
  517. (
  518. 'admin@admin.admin',
  519. 'admin@admin.admin'
  520. )
  521. )
  522. res = self.testapp.get(
  523. '/api/v2/workspaces/40/threads/7',
  524. status=400
  525. )
  526. def test_api__get_thread__err_400__workspace_id_is_not_int(self) -> None: # nopep8
  527. """
  528. Get one thread, workspace id is not int
  529. """
  530. self.testapp.authorization = (
  531. 'Basic',
  532. (
  533. 'admin@admin.admin',
  534. 'admin@admin.admin'
  535. )
  536. )
  537. res = self.testapp.get(
  538. '/api/v2/workspaces/coucou/threads/7',
  539. status=400
  540. )
  541. def test_api__get_thread__err_400_content_id_is_not_int(self) -> None: # nopep8
  542. """
  543. Get one thread, content id is not int
  544. """
  545. self.testapp.authorization = (
  546. 'Basic',
  547. (
  548. 'admin@admin.admin',
  549. 'admin@admin.admin'
  550. )
  551. )
  552. res = self.testapp.get(
  553. '/api/v2/workspaces/2/threads/coucou',
  554. status=400
  555. )
  556. def test_api__update_thread__ok_200__nominal_case(self) -> None:
  557. """
  558. Update(put) thread
  559. """
  560. self.testapp.authorization = (
  561. 'Basic',
  562. (
  563. 'admin@admin.admin',
  564. 'admin@admin.admin'
  565. )
  566. )
  567. params = {
  568. 'label': 'My New label',
  569. 'raw_content': '<p> Le nouveau contenu </p>',
  570. }
  571. res = self.testapp.put_json(
  572. '/api/v2/workspaces/2/threads/7',
  573. params=params,
  574. status=200
  575. )
  576. content = res.json_body
  577. assert content['content_type'] == 'thread'
  578. assert content['content_id'] == 7
  579. assert content['is_archived'] is False
  580. assert content['is_deleted'] is False
  581. assert content['label'] == 'My New label'
  582. assert content['parent_id'] == 3
  583. assert content['show_in_ui'] is True
  584. assert content['slug'] == 'my-new-label'
  585. assert content['status'] == 'open'
  586. assert content['workspace_id'] == 2
  587. assert content['current_revision_id'] == 28
  588. # TODO - G.M - 2018-06-173 - check date format
  589. assert content['created']
  590. assert content['author']
  591. assert content['author']['user_id'] == 1
  592. assert content['author']['avatar_url'] is None
  593. assert content['author']['public_name'] == 'Global manager'
  594. # TODO - G.M - 2018-06-173 - check date format
  595. assert content['modified']
  596. assert content['last_modifier'] == content['author']
  597. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  598. res = self.testapp.get(
  599. '/api/v2/workspaces/2/threads/7',
  600. status=200
  601. ) # nopep8
  602. content = res.json_body
  603. assert content['content_type'] == 'thread'
  604. assert content['content_id'] == 7
  605. assert content['is_archived'] is False
  606. assert content['is_deleted'] is False
  607. assert content['label'] == 'My New label'
  608. assert content['parent_id'] == 3
  609. assert content['show_in_ui'] is True
  610. assert content['slug'] == 'my-new-label'
  611. assert content['status'] == 'open'
  612. assert content['workspace_id'] == 2
  613. assert content['current_revision_id'] == 28
  614. # TODO - G.M - 2018-06-173 - check date format
  615. assert content['created']
  616. assert content['author']
  617. assert content['author']['user_id'] == 1
  618. assert content['author']['avatar_url'] is None
  619. assert content['author']['public_name'] == 'Global manager'
  620. # TODO - G.M - 2018-06-173 - check date format
  621. assert content['modified']
  622. assert content['last_modifier'] == content['author']
  623. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  624. def test_api__update_thread__err_400__empty_label(self) -> None:
  625. """
  626. Update(put) thread
  627. """
  628. self.testapp.authorization = (
  629. 'Basic',
  630. (
  631. 'admin@admin.admin',
  632. 'admin@admin.admin'
  633. )
  634. )
  635. params = {
  636. 'label': '',
  637. 'raw_content': '<p> Le nouveau contenu </p>',
  638. }
  639. res = self.testapp.put_json(
  640. '/api/v2/workspaces/2/threads/7',
  641. params=params,
  642. status=400
  643. )
  644. def test_api__get_thread_revisions__ok_200__nominal_case(
  645. self
  646. ) -> None:
  647. """
  648. Get threads revisions
  649. """
  650. self.testapp.authorization = (
  651. 'Basic',
  652. (
  653. 'admin@admin.admin',
  654. 'admin@admin.admin'
  655. )
  656. )
  657. res = self.testapp.get(
  658. '/api/v2/workspaces/2/threads/7/revisions',
  659. status=200
  660. )
  661. revisions = res.json_body
  662. assert len(revisions) == 2
  663. revision = revisions[0]
  664. assert revision['content_type'] == 'thread'
  665. assert revision['content_id'] == 7
  666. assert revision['is_archived'] is False
  667. assert revision['is_deleted'] is False
  668. assert revision['label'] == 'Best Cake'
  669. assert revision['parent_id'] == 3
  670. assert revision['show_in_ui'] is True
  671. assert revision['slug'] == 'best-cake'
  672. assert revision['status'] == 'open'
  673. assert revision['workspace_id'] == 2
  674. assert revision['revision_id'] == 8
  675. assert revision['sub_content_types']
  676. assert revision['revision_type'] == 'creation'
  677. assert revision['comment_ids'] == [18, 19, 20]
  678. # TODO - G.M - 2018-06-173 - check date format
  679. assert revision['created']
  680. assert revision['author']
  681. assert revision['author']['user_id'] == 1
  682. assert revision['author']['avatar_url'] is None
  683. assert revision['author']['public_name'] == 'Global manager'
  684. revision = revisions[1]
  685. assert revision['content_type'] == 'thread'
  686. assert revision['content_id'] == 7
  687. assert revision['is_archived'] is False
  688. assert revision['is_deleted'] is False
  689. assert revision['label'] == 'Best Cakes?'
  690. assert revision['parent_id'] == 3
  691. assert revision['show_in_ui'] is True
  692. assert revision['slug'] == 'best-cakes'
  693. assert revision['status'] == 'open'
  694. assert revision['workspace_id'] == 2
  695. assert revision['revision_id'] == 26
  696. assert revision['revision_type'] == 'edition'
  697. assert revision['sub_content_types']
  698. assert revision['comment_ids'] == []
  699. # TODO - G.M - 2018-06-173 - check date format
  700. assert revision['created']
  701. assert revision['author']
  702. assert revision['author']['user_id'] == 3
  703. assert revision['author']['avatar_url'] is None
  704. assert revision['author']['public_name'] == 'Bob i.'
  705. def test_api__get_thread_revisions__ok_200__most_revision_type(self) -> None:
  706. """
  707. get threads revisions
  708. """
  709. dbsession = get_tm_session(self.session_factory, transaction.manager)
  710. admin = dbsession.query(models.User) \
  711. .filter(models.User.email == 'admin@admin.admin') \
  712. .one()
  713. workspace_api = WorkspaceApi(
  714. current_user=admin,
  715. session=dbsession,
  716. config=self.app_config
  717. )
  718. business_workspace = workspace_api.get_one(1)
  719. content_api = ContentApi(
  720. current_user=admin,
  721. session=dbsession,
  722. config=self.app_config
  723. )
  724. tool_folder = content_api.get_one(1, content_type=ContentType.Any)
  725. test_thread = content_api.create(
  726. content_type=ContentType.Thread,
  727. workspace=business_workspace,
  728. parent=tool_folder,
  729. label='Test Thread',
  730. do_save=True,
  731. do_notify=False,
  732. )
  733. with new_revision(
  734. session=dbsession,
  735. tm=transaction.manager,
  736. content=test_thread,
  737. ):
  738. content_api.update_content(
  739. test_thread,
  740. new_label='test_thread_updated',
  741. new_content='Just a test'
  742. )
  743. content_api.save(test_thread)
  744. with new_revision(
  745. session=dbsession,
  746. tm=transaction.manager,
  747. content=test_thread,
  748. ):
  749. content_api.archive(test_thread)
  750. content_api.save(test_thread)
  751. with new_revision(
  752. session=dbsession,
  753. tm=transaction.manager,
  754. content=test_thread,
  755. ):
  756. content_api.unarchive(test_thread)
  757. content_api.save(test_thread)
  758. with new_revision(
  759. session=dbsession,
  760. tm=transaction.manager,
  761. content=test_thread,
  762. ):
  763. content_api.delete(test_thread)
  764. content_api.save(test_thread)
  765. with new_revision(
  766. session=dbsession,
  767. tm=transaction.manager,
  768. content=test_thread,
  769. ):
  770. content_api.undelete(test_thread)
  771. content_api.save(test_thread)
  772. dbsession.flush()
  773. transaction.commit()
  774. self.testapp.authorization = (
  775. 'Basic',
  776. (
  777. 'admin@admin.admin',
  778. 'admin@admin.admin'
  779. )
  780. )
  781. res = self.testapp.get(
  782. '/api/v2/workspaces/1/threads/{}/revisions'.format(test_thread.content_id), # nopep8
  783. status=200
  784. )
  785. revisions = res.json_body
  786. assert len(revisions) == 6
  787. for revision in revisions:
  788. revision['content_type'] == 'thread'
  789. revision['workspace_id'] == 1
  790. revision['content_id'] == test_thread.content_id
  791. revision = revisions[0]
  792. revision['revision_type'] == 'creation'
  793. revision = revisions[1]
  794. revision['revision_type'] == 'archiving'
  795. revision = revisions[2]
  796. revision['revision_type'] == 'unarchiving'
  797. revision = revisions[3]
  798. revision['revision_type'] == 'deletion'
  799. revision = revisions[4]
  800. revision['revision_type'] == 'undeletion'
  801. def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
  802. """
  803. Set thread status
  804. """
  805. self.testapp.authorization = (
  806. 'Basic',
  807. (
  808. 'admin@admin.admin',
  809. 'admin@admin.admin'
  810. )
  811. )
  812. params = {
  813. 'status': 'closed-deprecated',
  814. }
  815. # before
  816. res = self.testapp.get(
  817. '/api/v2/workspaces/2/threads/7',
  818. status=200
  819. ) # nopep8
  820. content = res.json_body
  821. assert content['content_type'] == 'thread'
  822. assert content['content_id'] == 7
  823. assert content['status'] == 'open'
  824. # set status
  825. res = self.testapp.put_json(
  826. '/api/v2/workspaces/2/threads/7/status',
  827. params=params,
  828. status=204
  829. )
  830. # after
  831. res = self.testapp.get(
  832. '/api/v2/workspaces/2/threads/7',
  833. status=200
  834. ) # nopep8
  835. content = res.json_body
  836. assert content['content_type'] == 'thread'
  837. assert content['content_id'] == 7
  838. assert content['status'] == 'closed-deprecated'
  839. def test_api__set_thread_status__ok_400__wrong_status(self) -> None:
  840. """
  841. Set thread status
  842. """
  843. self.testapp.authorization = (
  844. 'Basic',
  845. (
  846. 'admin@admin.admin',
  847. 'admin@admin.admin'
  848. )
  849. )
  850. params = {
  851. 'status': 'unexistant-status',
  852. }
  853. res = self.testapp.put_json(
  854. '/api/v2/workspaces/2/threads/7/status',
  855. params=params,
  856. status=400
  857. )