test_contents.py 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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__get_html_document__err_400__workspace_id_is_not_int(self) -> None: # nopep8
  154. """
  155. Get one html document of a content, workspace id is not int
  156. """
  157. self.testapp.authorization = (
  158. 'Basic',
  159. (
  160. 'admin@admin.admin',
  161. 'admin@admin.admin'
  162. )
  163. )
  164. res = self.testapp.get(
  165. '/api/v2/workspaces/coucou/html-documents/6',
  166. status=400
  167. )
  168. def test_api__get_html_document__err_400__content_id_is_not_int(self) -> None: # nopep8
  169. """
  170. Get one html document of a content, content_id is not int
  171. """
  172. self.testapp.authorization = (
  173. 'Basic',
  174. (
  175. 'admin@admin.admin',
  176. 'admin@admin.admin'
  177. )
  178. )
  179. res = self.testapp.get(
  180. '/api/v2/workspaces/2/html-documents/coucou',
  181. status=400
  182. )
  183. def test_api__update_html_document__err_400__empty_label(self) -> None: # nopep8
  184. """
  185. Update(put) one html document of a content
  186. """
  187. self.testapp.authorization = (
  188. 'Basic',
  189. (
  190. 'admin@admin.admin',
  191. 'admin@admin.admin'
  192. )
  193. )
  194. params = {
  195. 'label': '',
  196. 'raw_content': '<p> Le nouveau contenu </p>',
  197. }
  198. res = self.testapp.put_json(
  199. '/api/v2/workspaces/2/html-documents/6',
  200. params=params,
  201. status=400
  202. )
  203. def test_api__update_html_document__ok_200__nominal_case(self) -> None:
  204. """
  205. Update(put) one html document of a content
  206. """
  207. self.testapp.authorization = (
  208. 'Basic',
  209. (
  210. 'admin@admin.admin',
  211. 'admin@admin.admin'
  212. )
  213. )
  214. params = {
  215. 'label': 'My New label',
  216. 'raw_content': '<p> Le nouveau contenu </p>',
  217. }
  218. res = self.testapp.put_json(
  219. '/api/v2/workspaces/2/html-documents/6',
  220. params=params,
  221. status=200
  222. )
  223. content = res.json_body
  224. assert content['content_type'] == 'html-documents'
  225. assert content['content_id'] == 6
  226. assert content['is_archived'] is False
  227. assert content['is_deleted'] is False
  228. assert content['label'] == 'My New label'
  229. assert content['parent_id'] == 3
  230. assert content['show_in_ui'] is True
  231. assert content['slug'] == 'my-new-label'
  232. assert content['status'] == 'open'
  233. assert content['workspace_id'] == 2
  234. assert content['current_revision_id'] == 28
  235. # TODO - G.M - 2018-06-173 - check date format
  236. assert content['created']
  237. assert content['author']
  238. assert content['author']['user_id'] == 1
  239. assert content['author']['avatar_url'] is None
  240. assert content['author']['public_name'] == 'Global manager'
  241. # TODO - G.M - 2018-06-173 - check date format
  242. assert content['modified']
  243. assert content['last_modifier'] == content['author']
  244. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  245. res = self.testapp.get(
  246. '/api/v2/workspaces/2/html-documents/6',
  247. status=200
  248. )
  249. content = res.json_body
  250. assert content['content_type'] == 'html-documents'
  251. assert content['content_id'] == 6
  252. assert content['is_archived'] is False
  253. assert content['is_deleted'] is False
  254. assert content['label'] == 'My New label'
  255. assert content['parent_id'] == 3
  256. assert content['show_in_ui'] is True
  257. assert content['slug'] == 'my-new-label'
  258. assert content['status'] == 'open'
  259. assert content['workspace_id'] == 2
  260. assert content['current_revision_id'] == 28
  261. # TODO - G.M - 2018-06-173 - check date format
  262. assert content['created']
  263. assert content['author']
  264. assert content['author']['user_id'] == 1
  265. assert content['author']['avatar_url'] is None
  266. assert content['author']['public_name'] == 'Global manager'
  267. # TODO - G.M - 2018-06-173 - check date format
  268. assert content['modified']
  269. assert content['last_modifier'] == content['author']
  270. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  271. def test_api__get_html_document_revisions__ok_200__nominal_case(
  272. self
  273. ) -> None:
  274. """
  275. Get one html document of a content
  276. """
  277. self.testapp.authorization = (
  278. 'Basic',
  279. (
  280. 'admin@admin.admin',
  281. 'admin@admin.admin'
  282. )
  283. )
  284. res = self.testapp.get(
  285. '/api/v2/workspaces/2/html-documents/6/revisions',
  286. status=200
  287. )
  288. revisions = res.json_body
  289. assert len(revisions) == 3
  290. revision = revisions[0]
  291. assert revision['content_type'] == 'html-documents'
  292. assert revision['content_id'] == 6
  293. assert revision['is_archived'] is False
  294. assert revision['is_deleted'] is False
  295. assert revision['label'] == 'Tiramisu Recipes!!!'
  296. assert revision['parent_id'] == 3
  297. assert revision['show_in_ui'] is True
  298. assert revision['slug'] == 'tiramisu-recipes'
  299. assert revision['status'] == 'open'
  300. assert revision['workspace_id'] == 2
  301. assert revision['revision_id'] == 6
  302. assert revision['sub_content_types']
  303. # TODO - G.M - 2018-06-173 - Test with real comments
  304. assert revision['comment_ids'] == []
  305. # TODO - G.M - 2018-06-173 - check date format
  306. assert revision['created']
  307. assert revision['author']
  308. assert revision['author']['user_id'] == 1
  309. assert revision['author']['avatar_url'] is None
  310. assert revision['author']['public_name'] == 'Global manager'
  311. revision = revisions[1]
  312. assert revision['content_type'] == 'html-documents'
  313. assert revision['content_id'] == 6
  314. assert revision['is_archived'] is False
  315. assert revision['is_deleted'] is False
  316. assert revision['label'] == 'Tiramisu Recipes!!!'
  317. assert revision['parent_id'] == 3
  318. assert revision['show_in_ui'] is True
  319. assert revision['slug'] == 'tiramisu-recipes'
  320. assert revision['status'] == 'open'
  321. assert revision['workspace_id'] == 2
  322. assert revision['revision_id'] == 7
  323. assert revision['sub_content_types']
  324. # TODO - G.M - 2018-06-173 - Test with real comments
  325. assert revision['comment_ids'] == []
  326. # TODO - G.M - 2018-06-173 - check date format
  327. assert revision['created']
  328. assert revision['author']
  329. assert revision['author']['user_id'] == 1
  330. assert revision['author']['avatar_url'] is None
  331. assert revision['author']['public_name'] == 'Global manager'
  332. revision = revisions[2]
  333. assert revision['content_type'] == 'html-documents'
  334. assert revision['content_id'] == 6
  335. assert revision['is_archived'] is False
  336. assert revision['is_deleted'] is False
  337. assert revision['label'] == 'Tiramisu Recipe'
  338. assert revision['parent_id'] == 3
  339. assert revision['show_in_ui'] is True
  340. assert revision['slug'] == 'tiramisu-recipe'
  341. assert revision['status'] == 'open'
  342. assert revision['workspace_id'] == 2
  343. assert revision['revision_id'] == 27
  344. assert revision['sub_content_types']
  345. # TODO - G.M - 2018-06-173 - Test with real comments
  346. assert revision['comment_ids'] == []
  347. # TODO - G.M - 2018-06-173 - check date format
  348. assert revision['created']
  349. assert revision['author']
  350. assert revision['author']['user_id'] == 3
  351. assert revision['author']['avatar_url'] is None
  352. assert revision['author']['public_name'] == 'Bob i.'
  353. def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
  354. """
  355. Get one html document of a content
  356. """
  357. self.testapp.authorization = (
  358. 'Basic',
  359. (
  360. 'admin@admin.admin',
  361. 'admin@admin.admin'
  362. )
  363. )
  364. params = {
  365. 'status': 'closed-deprecated',
  366. }
  367. # before
  368. res = self.testapp.get(
  369. '/api/v2/workspaces/2/html-documents/6',
  370. status=200
  371. )
  372. content = res.json_body
  373. assert content['content_type'] == 'html-documents'
  374. assert content['content_id'] == 6
  375. assert content['status'] == 'open'
  376. # set status
  377. res = self.testapp.put_json(
  378. '/api/v2/workspaces/2/html-documents/6/status',
  379. params=params,
  380. status=204
  381. )
  382. # after
  383. res = self.testapp.get(
  384. '/api/v2/workspaces/2/html-documents/6',
  385. status=200
  386. )
  387. content = res.json_body
  388. assert content['content_type'] == 'html-documents'
  389. assert content['content_id'] == 6
  390. assert content['status'] == 'closed-deprecated'
  391. def test_api__set_html_document_status__err_400__wrong_status(self) -> None:
  392. """
  393. Get one html document of a content
  394. """
  395. self.testapp.authorization = (
  396. 'Basic',
  397. (
  398. 'admin@admin.admin',
  399. 'admin@admin.admin'
  400. )
  401. )
  402. params = {
  403. 'status': 'unexistant-status',
  404. }
  405. res = self.testapp.put_json(
  406. '/api/v2/workspaces/2/html-documents/6/status',
  407. params=params,
  408. status=400
  409. )
  410. class TestThreads(FunctionalTest):
  411. """
  412. Tests for /api/v2/workspaces/{workspace_id}/threads/{content_id}
  413. endpoint
  414. """
  415. fixtures = [BaseFixture, ContentFixtures]
  416. def test_api__get_thread__err_400__wrong_content_type(self) -> None:
  417. """
  418. Get one html document of a content
  419. """
  420. self.testapp.authorization = (
  421. 'Basic',
  422. (
  423. 'admin@admin.admin',
  424. 'admin@admin.admin'
  425. )
  426. )
  427. res = self.testapp.get(
  428. '/api/v2/workspaces/2/threads/6',
  429. status=400
  430. )
  431. def test_api__get_thread__ok_200__nominal_case(self) -> None:
  432. """
  433. Get one html document of a content
  434. """
  435. self.testapp.authorization = (
  436. 'Basic',
  437. (
  438. 'admin@admin.admin',
  439. 'admin@admin.admin'
  440. )
  441. )
  442. res = self.testapp.get(
  443. '/api/v2/workspaces/2/threads/7',
  444. status=200
  445. ) # nopep8
  446. content = res.json_body
  447. assert content['content_type'] == 'thread'
  448. assert content['content_id'] == 7
  449. assert content['is_archived'] is False
  450. assert content['is_deleted'] is False
  451. assert content['label'] == 'Best Cakes?'
  452. assert content['parent_id'] == 3
  453. assert content['show_in_ui'] is True
  454. assert content['slug'] == 'best-cakes'
  455. assert content['status'] == 'open'
  456. assert content['workspace_id'] == 2
  457. assert content['current_revision_id'] == 26
  458. # TODO - G.M - 2018-06-173 - check date format
  459. assert content['created']
  460. assert content['author']
  461. assert content['author']['user_id'] == 1
  462. assert content['author']['avatar_url'] is None
  463. assert content['author']['public_name'] == 'Global manager'
  464. # TODO - G.M - 2018-06-173 - check date format
  465. assert content['modified']
  466. assert content['last_modifier'] != content['author']
  467. assert content['last_modifier']['user_id'] == 3
  468. assert content['last_modifier']['public_name'] == 'Bob i.'
  469. assert content['last_modifier']['avatar_url'] is None
  470. assert content['raw_content'] == 'What is the best cake?' # nopep8
  471. def test_api__get_thread__err_400__content_does_not_exist(self) -> None:
  472. """
  473. Get one thread (content 170 does not exist)
  474. """
  475. self.testapp.authorization = (
  476. 'Basic',
  477. (
  478. 'admin@admin.admin',
  479. 'admin@admin.admin'
  480. )
  481. )
  482. res = self.testapp.get(
  483. '/api/v2/workspaces/2/threads/170',
  484. status=400
  485. )
  486. def test_api__get_thread__err_400__content_not_in_workspace(self) -> None:
  487. """
  488. Get one thread(content 7 is in workspace 2)
  489. """
  490. self.testapp.authorization = (
  491. 'Basic',
  492. (
  493. 'admin@admin.admin',
  494. 'admin@admin.admin'
  495. )
  496. )
  497. res = self.testapp.get(
  498. '/api/v2/workspaces/1/threads/7',
  499. status=400
  500. )
  501. def test_api__get_thread__err_400__workspace_does_not_exist(self) -> None: # nopep8
  502. """
  503. Get one thread (Workspace 40 does not exist)
  504. """
  505. self.testapp.authorization = (
  506. 'Basic',
  507. (
  508. 'admin@admin.admin',
  509. 'admin@admin.admin'
  510. )
  511. )
  512. res = self.testapp.get(
  513. '/api/v2/workspaces/40/threads/7',
  514. status=400
  515. )
  516. def test_api__get_thread__err_400__workspace_id_is_not_int(self) -> None: # nopep8
  517. """
  518. Get one thread, workspace id is not int
  519. """
  520. self.testapp.authorization = (
  521. 'Basic',
  522. (
  523. 'admin@admin.admin',
  524. 'admin@admin.admin'
  525. )
  526. )
  527. res = self.testapp.get(
  528. '/api/v2/workspaces/coucou/threads/7',
  529. status=400
  530. )
  531. def test_api__get_thread__err_400_content_id_is_not_int(self) -> None: # nopep8
  532. """
  533. Get one thread, content id is not int
  534. """
  535. self.testapp.authorization = (
  536. 'Basic',
  537. (
  538. 'admin@admin.admin',
  539. 'admin@admin.admin'
  540. )
  541. )
  542. res = self.testapp.get(
  543. '/api/v2/workspaces/2/threads/coucou',
  544. status=400
  545. )
  546. def test_api__update_thread__ok_200__nominal_case(self) -> None:
  547. """
  548. Update(put) thread
  549. """
  550. self.testapp.authorization = (
  551. 'Basic',
  552. (
  553. 'admin@admin.admin',
  554. 'admin@admin.admin'
  555. )
  556. )
  557. params = {
  558. 'label': 'My New label',
  559. 'raw_content': '<p> Le nouveau contenu </p>',
  560. }
  561. res = self.testapp.put_json(
  562. '/api/v2/workspaces/2/threads/7',
  563. params=params,
  564. status=200
  565. )
  566. content = res.json_body
  567. assert content['content_type'] == 'thread'
  568. assert content['content_id'] == 7
  569. assert content['is_archived'] is False
  570. assert content['is_deleted'] is False
  571. assert content['label'] == 'My New label'
  572. assert content['parent_id'] == 3
  573. assert content['show_in_ui'] is True
  574. assert content['slug'] == 'my-new-label'
  575. assert content['status'] == 'open'
  576. assert content['workspace_id'] == 2
  577. assert content['current_revision_id'] == 28
  578. # TODO - G.M - 2018-06-173 - check date format
  579. assert content['created']
  580. assert content['author']
  581. assert content['author']['user_id'] == 1
  582. assert content['author']['avatar_url'] is None
  583. assert content['author']['public_name'] == 'Global manager'
  584. # TODO - G.M - 2018-06-173 - check date format
  585. assert content['modified']
  586. assert content['last_modifier'] == content['author']
  587. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  588. res = self.testapp.get(
  589. '/api/v2/workspaces/2/threads/7',
  590. status=200
  591. ) # nopep8
  592. content = res.json_body
  593. assert content['content_type'] == 'thread'
  594. assert content['content_id'] == 7
  595. assert content['is_archived'] is False
  596. assert content['is_deleted'] is False
  597. assert content['label'] == 'My New label'
  598. assert content['parent_id'] == 3
  599. assert content['show_in_ui'] is True
  600. assert content['slug'] == 'my-new-label'
  601. assert content['status'] == 'open'
  602. assert content['workspace_id'] == 2
  603. assert content['current_revision_id'] == 28
  604. # TODO - G.M - 2018-06-173 - check date format
  605. assert content['created']
  606. assert content['author']
  607. assert content['author']['user_id'] == 1
  608. assert content['author']['avatar_url'] is None
  609. assert content['author']['public_name'] == 'Global manager'
  610. # TODO - G.M - 2018-06-173 - check date format
  611. assert content['modified']
  612. assert content['last_modifier'] == content['author']
  613. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  614. def test_api__update_thread__err_400__empty_label(self) -> None:
  615. """
  616. Update(put) thread
  617. """
  618. self.testapp.authorization = (
  619. 'Basic',
  620. (
  621. 'admin@admin.admin',
  622. 'admin@admin.admin'
  623. )
  624. )
  625. params = {
  626. 'label': '',
  627. 'raw_content': '<p> Le nouveau contenu </p>',
  628. }
  629. res = self.testapp.put_json(
  630. '/api/v2/workspaces/2/threads/7',
  631. params=params,
  632. status=400
  633. )
  634. def test_api__get_thread_revisions__ok_200__nominal_case(
  635. self
  636. ) -> None:
  637. """
  638. Get threads revisions
  639. """
  640. self.testapp.authorization = (
  641. 'Basic',
  642. (
  643. 'admin@admin.admin',
  644. 'admin@admin.admin'
  645. )
  646. )
  647. res = self.testapp.get(
  648. '/api/v2/workspaces/2/threads/7/revisions',
  649. status=200
  650. )
  651. revisions = res.json_body
  652. assert len(revisions) == 2
  653. revision = revisions[0]
  654. assert revision['content_type'] == 'thread'
  655. assert revision['content_id'] == 7
  656. assert revision['is_archived'] is False
  657. assert revision['is_deleted'] is False
  658. assert revision['label'] == 'Best Cake'
  659. assert revision['parent_id'] == 3
  660. assert revision['show_in_ui'] is True
  661. assert revision['slug'] == 'best-cake'
  662. assert revision['status'] == 'open'
  663. assert revision['workspace_id'] == 2
  664. assert revision['revision_id'] == 8
  665. assert revision['sub_content_types']
  666. assert revision['comment_ids'] == [18, 19, 20]
  667. # TODO - G.M - 2018-06-173 - check date format
  668. assert revision['created']
  669. assert revision['author']
  670. assert revision['author']['user_id'] == 1
  671. assert revision['author']['avatar_url'] is None
  672. assert revision['author']['public_name'] == 'Global manager'
  673. revision = revisions[1]
  674. assert revision['content_type'] == 'thread'
  675. assert revision['content_id'] == 7
  676. assert revision['is_archived'] is False
  677. assert revision['is_deleted'] is False
  678. assert revision['label'] == 'Best Cakes?'
  679. assert revision['parent_id'] == 3
  680. assert revision['show_in_ui'] is True
  681. assert revision['slug'] == 'best-cakes'
  682. assert revision['status'] == 'open'
  683. assert revision['workspace_id'] == 2
  684. assert revision['revision_id'] == 26
  685. assert revision['sub_content_types']
  686. assert revision['comment_ids'] == []
  687. # TODO - G.M - 2018-06-173 - check date format
  688. assert revision['created']
  689. assert revision['author']
  690. assert revision['author']['user_id'] == 3
  691. assert revision['author']['avatar_url'] is None
  692. assert revision['author']['public_name'] == 'Bob i.'
  693. def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
  694. """
  695. Set thread status
  696. """
  697. self.testapp.authorization = (
  698. 'Basic',
  699. (
  700. 'admin@admin.admin',
  701. 'admin@admin.admin'
  702. )
  703. )
  704. params = {
  705. 'status': 'closed-deprecated',
  706. }
  707. # before
  708. res = self.testapp.get(
  709. '/api/v2/workspaces/2/threads/7',
  710. status=200
  711. ) # nopep8
  712. content = res.json_body
  713. assert content['content_type'] == 'thread'
  714. assert content['content_id'] == 7
  715. assert content['status'] == 'open'
  716. # set status
  717. res = self.testapp.put_json(
  718. '/api/v2/workspaces/2/threads/7/status',
  719. params=params,
  720. status=204
  721. )
  722. # after
  723. res = self.testapp.get(
  724. '/api/v2/workspaces/2/threads/7',
  725. status=200
  726. ) # nopep8
  727. content = res.json_body
  728. assert content['content_type'] == 'thread'
  729. assert content['content_id'] == 7
  730. assert content['status'] == 'closed-deprecated'
  731. def test_api__set_thread_status__ok_400__wrong_status(self) -> None:
  732. """
  733. Set thread status
  734. """
  735. self.testapp.authorization = (
  736. 'Basic',
  737. (
  738. 'admin@admin.admin',
  739. 'admin@admin.admin'
  740. )
  741. )
  742. params = {
  743. 'status': 'unexistant-status',
  744. }
  745. res = self.testapp.put_json(
  746. '/api/v2/workspaces/2/threads/7/status',
  747. params=params,
  748. status=400
  749. )