test_contents.py 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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['revision_type'] == 'creation'
  303. assert revision['sub_content_types']
  304. # TODO - G.M - 2018-06-173 - Test with real comments
  305. assert revision['comment_ids'] == []
  306. # TODO - G.M - 2018-06-173 - check date format
  307. assert revision['created']
  308. assert revision['author']
  309. assert revision['author']['user_id'] == 1
  310. assert revision['author']['avatar_url'] is None
  311. assert revision['author']['public_name'] == 'Global manager'
  312. revision = revisions[1]
  313. assert revision['content_type'] == 'html-documents'
  314. assert revision['content_id'] == 6
  315. assert revision['is_archived'] is False
  316. assert revision['is_deleted'] is False
  317. assert revision['label'] == 'Tiramisu Recipes!!!'
  318. assert revision['parent_id'] == 3
  319. assert revision['show_in_ui'] is True
  320. assert revision['slug'] == 'tiramisu-recipes'
  321. assert revision['status'] == 'open'
  322. assert revision['workspace_id'] == 2
  323. assert revision['revision_id'] == 7
  324. assert revision['revision_type'] == 'edition'
  325. assert revision['sub_content_types']
  326. # TODO - G.M - 2018-06-173 - Test with real comments
  327. assert revision['comment_ids'] == []
  328. # TODO - G.M - 2018-06-173 - check date format
  329. assert revision['created']
  330. assert revision['author']
  331. assert revision['author']['user_id'] == 1
  332. assert revision['author']['avatar_url'] is None
  333. assert revision['author']['public_name'] == 'Global manager'
  334. revision = revisions[2]
  335. assert revision['content_type'] == 'html-documents'
  336. assert revision['content_id'] == 6
  337. assert revision['is_archived'] is False
  338. assert revision['is_deleted'] is False
  339. assert revision['label'] == 'Tiramisu Recipe'
  340. assert revision['parent_id'] == 3
  341. assert revision['show_in_ui'] is True
  342. assert revision['slug'] == 'tiramisu-recipe'
  343. assert revision['status'] == 'open'
  344. assert revision['workspace_id'] == 2
  345. assert revision['revision_id'] == 27
  346. assert revision['revision_type'] == 'edition'
  347. assert revision['sub_content_types']
  348. # TODO - G.M - 2018-06-173 - Test with real comments
  349. assert revision['comment_ids'] == []
  350. # TODO - G.M - 2018-06-173 - check date format
  351. assert revision['created']
  352. assert revision['author']
  353. assert revision['author']['user_id'] == 3
  354. assert revision['author']['avatar_url'] is None
  355. assert revision['author']['public_name'] == 'Bob i.'
  356. def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
  357. """
  358. Get one html document of a content
  359. """
  360. self.testapp.authorization = (
  361. 'Basic',
  362. (
  363. 'admin@admin.admin',
  364. 'admin@admin.admin'
  365. )
  366. )
  367. params = {
  368. 'status': 'closed-deprecated',
  369. }
  370. # before
  371. res = self.testapp.get(
  372. '/api/v2/workspaces/2/html-documents/6',
  373. status=200
  374. )
  375. content = res.json_body
  376. assert content['content_type'] == 'html-documents'
  377. assert content['content_id'] == 6
  378. assert content['status'] == 'open'
  379. # set status
  380. res = self.testapp.put_json(
  381. '/api/v2/workspaces/2/html-documents/6/status',
  382. params=params,
  383. status=204
  384. )
  385. # after
  386. res = self.testapp.get(
  387. '/api/v2/workspaces/2/html-documents/6',
  388. status=200
  389. )
  390. content = res.json_body
  391. assert content['content_type'] == 'html-documents'
  392. assert content['content_id'] == 6
  393. assert content['status'] == 'closed-deprecated'
  394. def test_api__set_html_document_status__err_400__wrong_status(self) -> None:
  395. """
  396. Get one html document of a content
  397. """
  398. self.testapp.authorization = (
  399. 'Basic',
  400. (
  401. 'admin@admin.admin',
  402. 'admin@admin.admin'
  403. )
  404. )
  405. params = {
  406. 'status': 'unexistant-status',
  407. }
  408. res = self.testapp.put_json(
  409. '/api/v2/workspaces/2/html-documents/6/status',
  410. params=params,
  411. status=400
  412. )
  413. class TestThreads(FunctionalTest):
  414. """
  415. Tests for /api/v2/workspaces/{workspace_id}/threads/{content_id}
  416. endpoint
  417. """
  418. fixtures = [BaseFixture, ContentFixtures]
  419. def test_api__get_thread__err_400__wrong_content_type(self) -> None:
  420. """
  421. Get one html document of a content
  422. """
  423. self.testapp.authorization = (
  424. 'Basic',
  425. (
  426. 'admin@admin.admin',
  427. 'admin@admin.admin'
  428. )
  429. )
  430. res = self.testapp.get(
  431. '/api/v2/workspaces/2/threads/6',
  432. status=400
  433. )
  434. def test_api__get_thread__ok_200__nominal_case(self) -> None:
  435. """
  436. Get one html document of a content
  437. """
  438. self.testapp.authorization = (
  439. 'Basic',
  440. (
  441. 'admin@admin.admin',
  442. 'admin@admin.admin'
  443. )
  444. )
  445. res = self.testapp.get(
  446. '/api/v2/workspaces/2/threads/7',
  447. status=200
  448. ) # nopep8
  449. content = res.json_body
  450. assert content['content_type'] == 'thread'
  451. assert content['content_id'] == 7
  452. assert content['is_archived'] is False
  453. assert content['is_deleted'] is False
  454. assert content['label'] == 'Best Cakes?'
  455. assert content['parent_id'] == 3
  456. assert content['show_in_ui'] is True
  457. assert content['slug'] == 'best-cakes'
  458. assert content['status'] == 'open'
  459. assert content['workspace_id'] == 2
  460. assert content['current_revision_id'] == 26
  461. # TODO - G.M - 2018-06-173 - check date format
  462. assert content['created']
  463. assert content['author']
  464. assert content['author']['user_id'] == 1
  465. assert content['author']['avatar_url'] is None
  466. assert content['author']['public_name'] == 'Global manager'
  467. # TODO - G.M - 2018-06-173 - check date format
  468. assert content['modified']
  469. assert content['last_modifier'] != content['author']
  470. assert content['last_modifier']['user_id'] == 3
  471. assert content['last_modifier']['public_name'] == 'Bob i.'
  472. assert content['last_modifier']['avatar_url'] is None
  473. assert content['raw_content'] == 'What is the best cake?' # nopep8
  474. def test_api__get_thread__err_400__content_does_not_exist(self) -> None:
  475. """
  476. Get one thread (content 170 does not exist)
  477. """
  478. self.testapp.authorization = (
  479. 'Basic',
  480. (
  481. 'admin@admin.admin',
  482. 'admin@admin.admin'
  483. )
  484. )
  485. res = self.testapp.get(
  486. '/api/v2/workspaces/2/threads/170',
  487. status=400
  488. )
  489. def test_api__get_thread__err_400__content_not_in_workspace(self) -> None:
  490. """
  491. Get one thread(content 7 is in workspace 2)
  492. """
  493. self.testapp.authorization = (
  494. 'Basic',
  495. (
  496. 'admin@admin.admin',
  497. 'admin@admin.admin'
  498. )
  499. )
  500. res = self.testapp.get(
  501. '/api/v2/workspaces/1/threads/7',
  502. status=400
  503. )
  504. def test_api__get_thread__err_400__workspace_does_not_exist(self) -> None: # nopep8
  505. """
  506. Get one thread (Workspace 40 does not exist)
  507. """
  508. self.testapp.authorization = (
  509. 'Basic',
  510. (
  511. 'admin@admin.admin',
  512. 'admin@admin.admin'
  513. )
  514. )
  515. res = self.testapp.get(
  516. '/api/v2/workspaces/40/threads/7',
  517. status=400
  518. )
  519. def test_api__get_thread__err_400__workspace_id_is_not_int(self) -> None: # nopep8
  520. """
  521. Get one thread, workspace id is not int
  522. """
  523. self.testapp.authorization = (
  524. 'Basic',
  525. (
  526. 'admin@admin.admin',
  527. 'admin@admin.admin'
  528. )
  529. )
  530. res = self.testapp.get(
  531. '/api/v2/workspaces/coucou/threads/7',
  532. status=400
  533. )
  534. def test_api__get_thread__err_400_content_id_is_not_int(self) -> None: # nopep8
  535. """
  536. Get one thread, content id is not int
  537. """
  538. self.testapp.authorization = (
  539. 'Basic',
  540. (
  541. 'admin@admin.admin',
  542. 'admin@admin.admin'
  543. )
  544. )
  545. res = self.testapp.get(
  546. '/api/v2/workspaces/2/threads/coucou',
  547. status=400
  548. )
  549. def test_api__update_thread__ok_200__nominal_case(self) -> None:
  550. """
  551. Update(put) thread
  552. """
  553. self.testapp.authorization = (
  554. 'Basic',
  555. (
  556. 'admin@admin.admin',
  557. 'admin@admin.admin'
  558. )
  559. )
  560. params = {
  561. 'label': 'My New label',
  562. 'raw_content': '<p> Le nouveau contenu </p>',
  563. }
  564. res = self.testapp.put_json(
  565. '/api/v2/workspaces/2/threads/7',
  566. params=params,
  567. status=200
  568. )
  569. content = res.json_body
  570. assert content['content_type'] == 'thread'
  571. assert content['content_id'] == 7
  572. assert content['is_archived'] is False
  573. assert content['is_deleted'] is False
  574. assert content['label'] == 'My New label'
  575. assert content['parent_id'] == 3
  576. assert content['show_in_ui'] is True
  577. assert content['slug'] == 'my-new-label'
  578. assert content['status'] == 'open'
  579. assert content['workspace_id'] == 2
  580. assert content['current_revision_id'] == 28
  581. # TODO - G.M - 2018-06-173 - check date format
  582. assert content['created']
  583. assert content['author']
  584. assert content['author']['user_id'] == 1
  585. assert content['author']['avatar_url'] is None
  586. assert content['author']['public_name'] == 'Global manager'
  587. # TODO - G.M - 2018-06-173 - check date format
  588. assert content['modified']
  589. assert content['last_modifier'] == content['author']
  590. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  591. res = self.testapp.get(
  592. '/api/v2/workspaces/2/threads/7',
  593. status=200
  594. ) # nopep8
  595. content = res.json_body
  596. assert content['content_type'] == 'thread'
  597. assert content['content_id'] == 7
  598. assert content['is_archived'] is False
  599. assert content['is_deleted'] is False
  600. assert content['label'] == 'My New label'
  601. assert content['parent_id'] == 3
  602. assert content['show_in_ui'] is True
  603. assert content['slug'] == 'my-new-label'
  604. assert content['status'] == 'open'
  605. assert content['workspace_id'] == 2
  606. assert content['current_revision_id'] == 28
  607. # TODO - G.M - 2018-06-173 - check date format
  608. assert content['created']
  609. assert content['author']
  610. assert content['author']['user_id'] == 1
  611. assert content['author']['avatar_url'] is None
  612. assert content['author']['public_name'] == 'Global manager'
  613. # TODO - G.M - 2018-06-173 - check date format
  614. assert content['modified']
  615. assert content['last_modifier'] == content['author']
  616. assert content['raw_content'] == '<p> Le nouveau contenu </p>'
  617. def test_api__update_thread__err_400__empty_label(self) -> None:
  618. """
  619. Update(put) thread
  620. """
  621. self.testapp.authorization = (
  622. 'Basic',
  623. (
  624. 'admin@admin.admin',
  625. 'admin@admin.admin'
  626. )
  627. )
  628. params = {
  629. 'label': '',
  630. 'raw_content': '<p> Le nouveau contenu </p>',
  631. }
  632. res = self.testapp.put_json(
  633. '/api/v2/workspaces/2/threads/7',
  634. params=params,
  635. status=400
  636. )
  637. def test_api__get_thread_revisions__ok_200__nominal_case(
  638. self
  639. ) -> None:
  640. """
  641. Get threads revisions
  642. """
  643. self.testapp.authorization = (
  644. 'Basic',
  645. (
  646. 'admin@admin.admin',
  647. 'admin@admin.admin'
  648. )
  649. )
  650. res = self.testapp.get(
  651. '/api/v2/workspaces/2/threads/7/revisions',
  652. status=200
  653. )
  654. revisions = res.json_body
  655. assert len(revisions) == 2
  656. revision = revisions[0]
  657. assert revision['content_type'] == 'thread'
  658. assert revision['content_id'] == 7
  659. assert revision['is_archived'] is False
  660. assert revision['is_deleted'] is False
  661. assert revision['label'] == 'Best Cake'
  662. assert revision['parent_id'] == 3
  663. assert revision['show_in_ui'] is True
  664. assert revision['slug'] == 'best-cake'
  665. assert revision['status'] == 'open'
  666. assert revision['workspace_id'] == 2
  667. assert revision['revision_id'] == 8
  668. assert revision['sub_content_types']
  669. assert revision['revision_type'] == 'creation'
  670. assert revision['comment_ids'] == [18, 19, 20]
  671. # TODO - G.M - 2018-06-173 - check date format
  672. assert revision['created']
  673. assert revision['author']
  674. assert revision['author']['user_id'] == 1
  675. assert revision['author']['avatar_url'] is None
  676. assert revision['author']['public_name'] == 'Global manager'
  677. revision = revisions[1]
  678. assert revision['content_type'] == 'thread'
  679. assert revision['content_id'] == 7
  680. assert revision['is_archived'] is False
  681. assert revision['is_deleted'] is False
  682. assert revision['label'] == 'Best Cakes?'
  683. assert revision['parent_id'] == 3
  684. assert revision['show_in_ui'] is True
  685. assert revision['slug'] == 'best-cakes'
  686. assert revision['status'] == 'open'
  687. assert revision['workspace_id'] == 2
  688. assert revision['revision_id'] == 26
  689. assert revision['revision_type'] == 'edition'
  690. assert revision['sub_content_types']
  691. assert revision['comment_ids'] == []
  692. # TODO - G.M - 2018-06-173 - check date format
  693. assert revision['created']
  694. assert revision['author']
  695. assert revision['author']['user_id'] == 3
  696. assert revision['author']['avatar_url'] is None
  697. assert revision['author']['public_name'] == 'Bob i.'
  698. def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
  699. """
  700. Set thread status
  701. """
  702. self.testapp.authorization = (
  703. 'Basic',
  704. (
  705. 'admin@admin.admin',
  706. 'admin@admin.admin'
  707. )
  708. )
  709. params = {
  710. 'status': 'closed-deprecated',
  711. }
  712. # before
  713. res = self.testapp.get(
  714. '/api/v2/workspaces/2/threads/7',
  715. status=200
  716. ) # nopep8
  717. content = res.json_body
  718. assert content['content_type'] == 'thread'
  719. assert content['content_id'] == 7
  720. assert content['status'] == 'open'
  721. # set status
  722. res = self.testapp.put_json(
  723. '/api/v2/workspaces/2/threads/7/status',
  724. params=params,
  725. status=204
  726. )
  727. # after
  728. res = self.testapp.get(
  729. '/api/v2/workspaces/2/threads/7',
  730. status=200
  731. ) # nopep8
  732. content = res.json_body
  733. assert content['content_type'] == 'thread'
  734. assert content['content_id'] == 7
  735. assert content['status'] == 'closed-deprecated'
  736. def test_api__set_thread_status__ok_400__wrong_status(self) -> None:
  737. """
  738. Set thread status
  739. """
  740. self.testapp.authorization = (
  741. 'Basic',
  742. (
  743. 'admin@admin.admin',
  744. 'admin@admin.admin'
  745. )
  746. )
  747. params = {
  748. 'status': 'unexistant-status',
  749. }
  750. res = self.testapp.put_json(
  751. '/api/v2/workspaces/2/threads/7/status',
  752. params=params,
  753. status=400
  754. )