test_workspaces.py 46KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for /api/v2/workspaces subpath endpoints.
  4. """
  5. from tracim.tests import FunctionalTest
  6. from tracim.fixtures.content import Content as ContentFixtures
  7. from tracim.fixtures.users_and_groups import Base as BaseFixture
  8. class TestWorkspaceEndpoint(FunctionalTest):
  9. """
  10. Tests for /api/v2/workspaces/{workspace_id} endpoint
  11. """
  12. fixtures = [BaseFixture, ContentFixtures]
  13. def test_api__get_workspace__ok_200__nominal_case(self) -> None:
  14. """
  15. Check obtain workspace reachable for user.
  16. """
  17. self.testapp.authorization = (
  18. 'Basic',
  19. (
  20. 'admin@admin.admin',
  21. 'admin@admin.admin'
  22. )
  23. )
  24. res = self.testapp.get('/api/v2/workspaces/1', status=200)
  25. workspace = res.json_body
  26. assert workspace['workspace_id'] == 1
  27. assert workspace['slug'] == 'business'
  28. assert workspace['label'] == 'Business'
  29. assert workspace['description'] == 'All importants documents'
  30. assert len(workspace['sidebar_entries']) == 7
  31. sidebar_entry = workspace['sidebar_entries'][0]
  32. assert sidebar_entry['slug'] == 'dashboard'
  33. assert sidebar_entry['label'] == 'Dashboard'
  34. assert sidebar_entry['route'] == '/#/workspaces/1/dashboard' # nopep8
  35. assert sidebar_entry['hexcolor'] == "#252525"
  36. assert sidebar_entry['fa_icon'] == ""
  37. sidebar_entry = workspace['sidebar_entries'][1]
  38. assert sidebar_entry['slug'] == 'contents/all'
  39. assert sidebar_entry['label'] == 'All Contents'
  40. assert sidebar_entry['route'] == "/#/workspaces/1/contents" # nopep8
  41. assert sidebar_entry['hexcolor'] == "#fdfdfd"
  42. assert sidebar_entry['fa_icon'] == ""
  43. sidebar_entry = workspace['sidebar_entries'][2]
  44. assert sidebar_entry['slug'] == 'contents/htmlpage'
  45. assert sidebar_entry['label'] == 'Text Documents'
  46. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=htmlpage' # nopep8
  47. assert sidebar_entry['hexcolor'] == "#3f52e3"
  48. assert sidebar_entry['fa_icon'] == "file-text-o"
  49. sidebar_entry = workspace['sidebar_entries'][3]
  50. assert sidebar_entry['slug'] == 'contents/markdownpluspage'
  51. assert sidebar_entry['label'] == 'Markdown Plus Documents'
  52. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=markdownpluspage" # nopep8
  53. assert sidebar_entry['hexcolor'] == "#f12d2d"
  54. assert sidebar_entry['fa_icon'] == "file-code"
  55. sidebar_entry = workspace['sidebar_entries'][4]
  56. assert sidebar_entry['slug'] == 'contents/files'
  57. assert sidebar_entry['label'] == 'Files'
  58. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file" # nopep8
  59. assert sidebar_entry['hexcolor'] == "#FF9900"
  60. assert sidebar_entry['fa_icon'] == "paperclip"
  61. sidebar_entry = workspace['sidebar_entries'][5]
  62. assert sidebar_entry['slug'] == 'contents/threads'
  63. assert sidebar_entry['label'] == 'Threads'
  64. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread" # nopep8
  65. assert sidebar_entry['hexcolor'] == "#ad4cf9"
  66. assert sidebar_entry['fa_icon'] == "comments-o"
  67. sidebar_entry = workspace['sidebar_entries'][6]
  68. assert sidebar_entry['slug'] == 'calendar'
  69. assert sidebar_entry['label'] == 'Calendar'
  70. assert sidebar_entry['route'] == "/#/workspaces/1/calendar" # nopep8
  71. assert sidebar_entry['hexcolor'] == "#757575"
  72. assert sidebar_entry['fa_icon'] == "calendar-alt"
  73. def test_api__get_workspace__err_403__unallowed_user(self) -> None:
  74. """
  75. Check obtain workspace unreachable for user
  76. """
  77. self.testapp.authorization = (
  78. 'Basic',
  79. (
  80. 'lawrence-not-real-email@fsf.local',
  81. 'foobarbaz'
  82. )
  83. )
  84. res = self.testapp.get('/api/v2/workspaces/1', status=403)
  85. assert isinstance(res.json, dict)
  86. assert 'code' in res.json.keys()
  87. assert 'message' in res.json.keys()
  88. assert 'details' in res.json.keys()
  89. def test_api__get_workspace__err_401__unregistered_user(self) -> None:
  90. """
  91. Check obtain workspace without registered user.
  92. """
  93. self.testapp.authorization = (
  94. 'Basic',
  95. (
  96. 'john@doe.doe',
  97. 'lapin'
  98. )
  99. )
  100. res = self.testapp.get('/api/v2/workspaces/1', status=401)
  101. assert isinstance(res.json, dict)
  102. assert 'code' in res.json.keys()
  103. assert 'message' in res.json.keys()
  104. assert 'details' in res.json.keys()
  105. def test_api__get_workspace__err_403__workspace_does_not_exist(self) -> None: # nopep8
  106. """
  107. Check obtain workspace who does not exist with an existing user.
  108. """
  109. self.testapp.authorization = (
  110. 'Basic',
  111. (
  112. 'admin@admin.admin',
  113. 'admin@admin.admin'
  114. )
  115. )
  116. res = self.testapp.get('/api/v2/workspaces/5', status=403)
  117. assert isinstance(res.json, dict)
  118. assert 'code' in res.json.keys()
  119. assert 'message' in res.json.keys()
  120. assert 'details' in res.json.keys()
  121. class TestWorkspaceMembersEndpoint(FunctionalTest):
  122. """
  123. Tests for /api/v2/workspaces/{workspace_id}/members endpoint
  124. """
  125. fixtures = [BaseFixture, ContentFixtures]
  126. def test_api__get_workspace_members__ok_200__nominal_case(self):
  127. """
  128. Check obtain workspace members list with a reachable workspace for user
  129. """
  130. self.testapp.authorization = (
  131. 'Basic',
  132. (
  133. 'admin@admin.admin',
  134. 'admin@admin.admin'
  135. )
  136. )
  137. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  138. assert len(res) == 1
  139. user_role = res[0]
  140. assert user_role['role'] == 'workspace-manager'
  141. assert user_role['user_id'] == 1
  142. assert user_role['workspace_id'] == 1
  143. assert user_role['user']['public_name'] == 'Global manager'
  144. # TODO - G.M - 24-05-2018 - [Avatar] Replace
  145. # by correct value when avatar feature will be enabled
  146. assert user_role['user']['avatar_url'] is None
  147. def test_api__get_workspace_members__err_403__unallowed_user(self):
  148. """
  149. Check obtain workspace members list with an unreachable workspace for
  150. user
  151. """
  152. self.testapp.authorization = (
  153. 'Basic',
  154. (
  155. 'lawrence-not-real-email@fsf.local',
  156. 'foobarbaz'
  157. )
  158. )
  159. res = self.testapp.get('/api/v2/workspaces/3/members', status=403)
  160. assert isinstance(res.json, dict)
  161. assert 'code' in res.json.keys()
  162. assert 'message' in res.json.keys()
  163. assert 'details' in res.json.keys()
  164. def test_api__get_workspace_members__err_401__unregistered_user(self):
  165. """
  166. Check obtain workspace members list with an unregistered user
  167. """
  168. self.testapp.authorization = (
  169. 'Basic',
  170. (
  171. 'john@doe.doe',
  172. 'lapin'
  173. )
  174. )
  175. res = self.testapp.get('/api/v2/workspaces/1/members', status=401)
  176. assert isinstance(res.json, dict)
  177. assert 'code' in res.json.keys()
  178. assert 'message' in res.json.keys()
  179. assert 'details' in res.json.keys()
  180. def test_api__get_workspace_members__err_403__workspace_does_not_exist(self): # nopep8
  181. """
  182. Check obtain workspace members list with an existing user but
  183. an unexisting workspace
  184. """
  185. self.testapp.authorization = (
  186. 'Basic',
  187. (
  188. 'admin@admin.admin',
  189. 'admin@admin.admin'
  190. )
  191. )
  192. res = self.testapp.get('/api/v2/workspaces/5/members', status=403)
  193. assert isinstance(res.json, dict)
  194. assert 'code' in res.json.keys()
  195. assert 'message' in res.json.keys()
  196. assert 'details' in res.json.keys()
  197. class TestWorkspaceContents(FunctionalTest):
  198. """
  199. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  200. """
  201. fixtures = [BaseFixture, ContentFixtures]
  202. def test_api__get_workspace_content__ok_200__get_default(self):
  203. """
  204. Check obtain workspace contents with defaults filters
  205. """
  206. self.testapp.authorization = (
  207. 'Basic',
  208. (
  209. 'admin@admin.admin',
  210. 'admin@admin.admin'
  211. )
  212. )
  213. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  214. # TODO - G.M - 30-05-2018 - Check this test
  215. assert len(res) == 3
  216. content = res[0]
  217. assert content['content_id'] == 1
  218. assert content['is_archived'] is False
  219. assert content['is_deleted'] is False
  220. assert content['label'] == 'Tools'
  221. assert content['parent_id'] is None
  222. assert content['show_in_ui'] is True
  223. assert content['slug'] == 'tools'
  224. assert content['status'] == 'open'
  225. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  226. assert content['workspace_id'] == 1
  227. content = res[1]
  228. assert content['content_id'] == 2
  229. assert content['is_archived'] is False
  230. assert content['is_deleted'] is False
  231. assert content['label'] == 'Menus'
  232. assert content['parent_id'] is None
  233. assert content['show_in_ui'] is True
  234. assert content['slug'] == 'menus'
  235. assert content['status'] == 'open'
  236. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  237. assert content['workspace_id'] == 1
  238. content = res[2]
  239. assert content['content_id'] == 11
  240. assert content['is_archived'] is False
  241. assert content['is_deleted'] is False
  242. assert content['label'] == 'Current Menu'
  243. assert content['parent_id'] == 2
  244. assert content['show_in_ui'] is True
  245. assert content['slug'] == 'current-menu'
  246. assert content['status'] == 'open'
  247. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  248. assert content['workspace_id'] == 1
  249. # Root related
  250. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  251. """
  252. Check obtain workspace all root contents
  253. """
  254. params = {
  255. 'parent_id': 0,
  256. 'show_archived': 1,
  257. 'show_deleted': 1,
  258. 'show_active': 1,
  259. }
  260. self.testapp.authorization = (
  261. 'Basic',
  262. (
  263. 'bob@fsf.local',
  264. 'foobarbaz'
  265. )
  266. )
  267. res = self.testapp.get(
  268. '/api/v2/workspaces/3/contents',
  269. status=200,
  270. params=params,
  271. ).json_body # nopep8
  272. # TODO - G.M - 30-05-2018 - Check this test
  273. assert len(res) == 4
  274. content = res[1]
  275. assert content['content_type'] == 'page'
  276. assert content['content_id'] == 15
  277. assert content['is_archived'] is False
  278. assert content['is_deleted'] is False
  279. assert content['label'] == 'New Fruit Salad'
  280. assert content['parent_id'] is None
  281. assert content['show_in_ui'] is True
  282. assert content['slug'] == 'new-fruit-salad'
  283. assert content['status'] == 'open'
  284. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  285. assert content['workspace_id'] == 3
  286. content = res[2]
  287. assert content['content_type'] == 'page'
  288. assert content['content_id'] == 16
  289. assert content['is_archived'] is True
  290. assert content['is_deleted'] is False
  291. assert content['label'].startswith('Fruit Salad')
  292. assert content['parent_id'] is None
  293. assert content['show_in_ui'] is True
  294. assert content['slug'].startswith('fruit-salad')
  295. assert content['status'] == 'open'
  296. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  297. assert content['workspace_id'] == 3
  298. content = res[3]
  299. assert content['content_type'] == 'page'
  300. assert content['content_id'] == 17
  301. assert content['is_archived'] is False
  302. assert content['is_deleted'] is True
  303. assert content['label'].startswith('Bad Fruit Salad')
  304. assert content['parent_id'] is None
  305. assert content['show_in_ui'] is True
  306. assert content['slug'].startswith('bad-fruit-salad')
  307. assert content['status'] == 'open'
  308. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  309. assert content['workspace_id'] == 3
  310. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8
  311. """
  312. Check obtain workspace root active contents
  313. """
  314. params = {
  315. 'parent_id': 0,
  316. 'show_archived': 0,
  317. 'show_deleted': 0,
  318. 'show_active': 1,
  319. }
  320. self.testapp.authorization = (
  321. 'Basic',
  322. (
  323. 'bob@fsf.local',
  324. 'foobarbaz'
  325. )
  326. )
  327. res = self.testapp.get(
  328. '/api/v2/workspaces/3/contents',
  329. status=200,
  330. params=params,
  331. ).json_body # nopep8
  332. # TODO - G.M - 30-05-2018 - Check this test
  333. assert len(res) == 2
  334. content = res[1]
  335. assert content['content_type'] == 'page'
  336. assert content['content_id'] == 15
  337. assert content['is_archived'] is False
  338. assert content['is_deleted'] is False
  339. assert content['label'] == 'New Fruit Salad'
  340. assert content['parent_id'] is None
  341. assert content['show_in_ui'] is True
  342. assert content['slug'] == 'new-fruit-salad'
  343. assert content['status'] == 'open'
  344. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  345. assert content['workspace_id'] == 3
  346. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8
  347. """
  348. Check obtain workspace root archived contents
  349. """
  350. params = {
  351. 'parent_id': 0,
  352. 'show_archived': 1,
  353. 'show_deleted': 0,
  354. 'show_active': 0,
  355. }
  356. self.testapp.authorization = (
  357. 'Basic',
  358. (
  359. 'bob@fsf.local',
  360. 'foobarbaz'
  361. )
  362. )
  363. res = self.testapp.get(
  364. '/api/v2/workspaces/3/contents',
  365. status=200,
  366. params=params,
  367. ).json_body # nopep8
  368. assert len(res) == 1
  369. content = res[0]
  370. assert content['content_type'] == 'page'
  371. assert content['content_id'] == 16
  372. assert content['is_archived'] is True
  373. assert content['is_deleted'] is False
  374. assert content['label'].startswith('Fruit Salad')
  375. assert content['parent_id'] is None
  376. assert content['show_in_ui'] is True
  377. assert content['slug'].startswith('fruit-salad')
  378. assert content['status'] == 'open'
  379. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  380. assert content['workspace_id'] == 3
  381. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8
  382. """
  383. Check obtain workspace root deleted contents
  384. """
  385. params = {
  386. 'parent_id': 0,
  387. 'show_archived': 0,
  388. 'show_deleted': 1,
  389. 'show_active': 0,
  390. }
  391. self.testapp.authorization = (
  392. 'Basic',
  393. (
  394. 'bob@fsf.local',
  395. 'foobarbaz'
  396. )
  397. )
  398. res = self.testapp.get(
  399. '/api/v2/workspaces/3/contents',
  400. status=200,
  401. params=params,
  402. ).json_body # nopep8
  403. # TODO - G.M - 30-05-2018 - Check this test
  404. assert len(res) == 1
  405. content = res[0]
  406. assert content['content_type'] == 'page'
  407. assert content['content_id'] == 17
  408. assert content['is_archived'] is False
  409. assert content['is_deleted'] is True
  410. assert content['label'].startswith('Bad Fruit Salad')
  411. assert content['parent_id'] is None
  412. assert content['show_in_ui'] is True
  413. assert content['slug'].startswith('bad-fruit-salad')
  414. assert content['status'] == 'open'
  415. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  416. assert content['workspace_id'] == 3
  417. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  418. """
  419. Check obtain workspace root content who does not match any type
  420. (archived, deleted, active) result should be empty list.
  421. """
  422. params = {
  423. 'parent_id': 0,
  424. 'show_archived': 0,
  425. 'show_deleted': 0,
  426. 'show_active': 0,
  427. }
  428. self.testapp.authorization = (
  429. 'Basic',
  430. (
  431. 'bob@fsf.local',
  432. 'foobarbaz'
  433. )
  434. )
  435. res = self.testapp.get(
  436. '/api/v2/workspaces/3/contents',
  437. status=200,
  438. params=params,
  439. ).json_body # nopep8
  440. # TODO - G.M - 30-05-2018 - Check this test
  441. assert res == []
  442. # Folder related
  443. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  444. """
  445. Check obtain workspace folder all contents
  446. """
  447. params = {
  448. 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id
  449. 'show_archived': 1,
  450. 'show_deleted': 1,
  451. 'show_active': 1,
  452. }
  453. self.testapp.authorization = (
  454. 'Basic',
  455. (
  456. 'admin@admin.admin',
  457. 'admin@admin.admin'
  458. )
  459. )
  460. res = self.testapp.get(
  461. '/api/v2/workspaces/2/contents',
  462. status=200,
  463. params=params,
  464. ).json_body # nopep8
  465. assert len(res) == 3
  466. content = res[0]
  467. assert content['content_type'] == 'page'
  468. assert content['content_id'] == 12
  469. assert content['is_archived'] is False
  470. assert content['is_deleted'] is False
  471. assert content['label'] == 'New Fruit Salad'
  472. assert content['parent_id'] == 10
  473. assert content['show_in_ui'] is True
  474. assert content['slug'] == 'new-fruit-salad'
  475. assert content['status'] == 'open'
  476. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  477. assert content['workspace_id'] == 2
  478. content = res[1]
  479. assert content['content_type'] == 'page'
  480. assert content['content_id'] == 13
  481. assert content['is_archived'] is True
  482. assert content['is_deleted'] is False
  483. assert content['label'].startswith('Fruit Salad')
  484. assert content['parent_id'] == 10
  485. assert content['show_in_ui'] is True
  486. assert content['slug'].startswith('fruit-salad')
  487. assert content['status'] == 'open'
  488. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  489. assert content['workspace_id'] == 2
  490. content = res[2]
  491. assert content['content_type'] == 'page'
  492. assert content['content_id'] == 14
  493. assert content['is_archived'] is False
  494. assert content['is_deleted'] is True
  495. assert content['label'].startswith('Bad Fruit Salad')
  496. assert content['parent_id'] == 10
  497. assert content['show_in_ui'] is True
  498. assert content['slug'].startswith('bad-fruit-salad')
  499. assert content['status'] == 'open'
  500. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  501. assert content['workspace_id'] == 2
  502. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8
  503. """
  504. Check obtain workspace folder active contents
  505. """
  506. params = {
  507. 'parent_id': 10,
  508. 'show_archived': 0,
  509. 'show_deleted': 0,
  510. 'show_active': 1,
  511. }
  512. self.testapp.authorization = (
  513. 'Basic',
  514. (
  515. 'admin@admin.admin',
  516. 'admin@admin.admin'
  517. )
  518. )
  519. res = self.testapp.get(
  520. '/api/v2/workspaces/2/contents',
  521. status=200,
  522. params=params,
  523. ).json_body # nopep8
  524. assert len(res) == 1
  525. content = res[0]
  526. assert content['content_type']
  527. assert content['content_id'] == 12
  528. assert content['is_archived'] is False
  529. assert content['is_deleted'] is False
  530. assert content['label'] == 'New Fruit Salad'
  531. assert content['parent_id'] == 10
  532. assert content['show_in_ui'] is True
  533. assert content['slug'] == 'new-fruit-salad'
  534. assert content['status'] == 'open'
  535. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  536. assert content['workspace_id'] == 2
  537. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8
  538. """
  539. Check obtain workspace folder archived contents
  540. """
  541. params = {
  542. 'parent_id': 10,
  543. 'show_archived': 1,
  544. 'show_deleted': 0,
  545. 'show_active': 0,
  546. }
  547. self.testapp.authorization = (
  548. 'Basic',
  549. (
  550. 'admin@admin.admin',
  551. 'admin@admin.admin'
  552. )
  553. )
  554. res = self.testapp.get(
  555. '/api/v2/workspaces/2/contents',
  556. status=200,
  557. params=params,
  558. ).json_body # nopep8
  559. assert len(res) == 1
  560. content = res[0]
  561. assert content['content_type'] == 'page'
  562. assert content['content_id'] == 13
  563. assert content['is_archived'] is True
  564. assert content['is_deleted'] is False
  565. assert content['label'].startswith('Fruit Salad')
  566. assert content['parent_id'] == 10
  567. assert content['show_in_ui'] is True
  568. assert content['slug'].startswith('fruit-salad')
  569. assert content['status'] == 'open'
  570. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  571. assert content['workspace_id'] == 2
  572. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8
  573. """
  574. Check obtain workspace folder deleted contents
  575. """
  576. params = {
  577. 'parent_id': 10,
  578. 'show_archived': 0,
  579. 'show_deleted': 1,
  580. 'show_active': 0,
  581. }
  582. self.testapp.authorization = (
  583. 'Basic',
  584. (
  585. 'admin@admin.admin',
  586. 'admin@admin.admin'
  587. )
  588. )
  589. res = self.testapp.get(
  590. '/api/v2/workspaces/2/contents',
  591. status=200,
  592. params=params,
  593. ).json_body # nopep8
  594. assert len(res) == 1
  595. content = res[0]
  596. assert content['content_type'] == 'page'
  597. assert content['content_id'] == 14
  598. assert content['is_archived'] is False
  599. assert content['is_deleted'] is True
  600. assert content['label'].startswith('Bad Fruit Salad')
  601. assert content['parent_id'] == 10
  602. assert content['show_in_ui'] is True
  603. assert content['slug'].startswith('bad-fruit-salad')
  604. assert content['status'] == 'open'
  605. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  606. assert content['workspace_id'] == 2
  607. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8
  608. """
  609. Check obtain workspace folder content who does not match any type
  610. (archived, deleted, active) result should be empty list.
  611. """
  612. params = {
  613. 'parent_id': 10,
  614. 'show_archived': 0,
  615. 'show_deleted': 0,
  616. 'show_active': 0,
  617. }
  618. self.testapp.authorization = (
  619. 'Basic',
  620. (
  621. 'admin@admin.admin',
  622. 'admin@admin.admin'
  623. )
  624. )
  625. res = self.testapp.get(
  626. '/api/v2/workspaces/2/contents',
  627. status=200,
  628. params=params,
  629. ).json_body # nopep8
  630. # TODO - G.M - 30-05-2018 - Check this test
  631. assert res == []
  632. # Error case
  633. def test_api__get_workspace_content__err_403__unallowed_user(self):
  634. """
  635. Check obtain workspace content list with an unreachable workspace for
  636. user
  637. """
  638. self.testapp.authorization = (
  639. 'Basic',
  640. (
  641. 'lawrence-not-real-email@fsf.local',
  642. 'foobarbaz'
  643. )
  644. )
  645. res = self.testapp.get('/api/v2/workspaces/3/contents', status=403)
  646. assert isinstance(res.json, dict)
  647. assert 'code' in res.json.keys()
  648. assert 'message' in res.json.keys()
  649. assert 'details' in res.json.keys()
  650. def test_api__get_workspace_content__err_401__unregistered_user(self):
  651. """
  652. Check obtain workspace content list with an unregistered user
  653. """
  654. self.testapp.authorization = (
  655. 'Basic',
  656. (
  657. 'john@doe.doe',
  658. 'lapin'
  659. )
  660. )
  661. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  662. assert isinstance(res.json, dict)
  663. assert 'code' in res.json.keys()
  664. assert 'message' in res.json.keys()
  665. assert 'details' in res.json.keys()
  666. def test_api__get_workspace_content__err_403__workspace_does_not_exist(self): # nopep8
  667. """
  668. Check obtain workspace contents list with an existing user but
  669. an unexisting workspace
  670. """
  671. self.testapp.authorization = (
  672. 'Basic',
  673. (
  674. 'admin@admin.admin',
  675. 'admin@admin.admin'
  676. )
  677. )
  678. res = self.testapp.get('/api/v2/workspaces/5/contents', status=403)
  679. assert isinstance(res.json, dict)
  680. assert 'code' in res.json.keys()
  681. assert 'message' in res.json.keys()
  682. assert 'details' in res.json.keys()
  683. def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8
  684. """
  685. Create generic content
  686. """
  687. self.testapp.authorization = (
  688. 'Basic',
  689. (
  690. 'admin@admin.admin',
  691. 'admin@admin.admin'
  692. )
  693. )
  694. params = {
  695. 'label': 'GenericCreatedContent',
  696. 'content_type': 'markdownpage',
  697. }
  698. res = self.testapp.post_json(
  699. '/api/v2/workspaces/1/contents',
  700. params=params,
  701. status=200
  702. )
  703. assert res
  704. assert res.json_body
  705. assert res.json_body['status'] == 'open'
  706. assert res.json_body['content_id']
  707. assert res.json_body['content_type'] == 'markdownpage'
  708. assert res.json_body['is_archived'] is False
  709. assert res.json_body['is_deleted'] is False
  710. assert res.json_body['workspace_id'] == 1
  711. assert res.json_body['slug'] == 'genericcreatedcontent'
  712. assert res.json_body['parent_id'] is None
  713. assert res.json_body['show_in_ui'] is True
  714. assert res.json_body['sub_content_types']
  715. params_active = {
  716. 'parent_id': 0,
  717. 'show_archived': 0,
  718. 'show_deleted': 0,
  719. 'show_active': 1,
  720. }
  721. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  722. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  723. assert res.json_body in active_contents
  724. def test_api_put_move_content__ok_200__nominal_case(self):
  725. """
  726. Move content
  727. move Apple_Pie (content_id: 8)
  728. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  729. of workspace Recipes.
  730. """
  731. self.testapp.authorization = (
  732. 'Basic',
  733. (
  734. 'admin@admin.admin',
  735. 'admin@admin.admin'
  736. )
  737. )
  738. params = {
  739. 'new_parent_id': '4', # Salads
  740. }
  741. params_folder1 = {
  742. 'parent_id': 3,
  743. 'show_archived': 0,
  744. 'show_deleted': 0,
  745. 'show_active': 1,
  746. }
  747. params_folder2 = {
  748. 'parent_id': 4,
  749. 'show_archived': 0,
  750. 'show_deleted': 0,
  751. 'show_active': 1,
  752. }
  753. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  754. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  755. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  756. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  757. # TODO - G.M - 2018-06-163 - Check content
  758. res = self.testapp.put_json(
  759. '/api/v2/workspaces/2/contents/8/move',
  760. params=params,
  761. status=200
  762. )
  763. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  764. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  765. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  766. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  767. assert res.json_body
  768. assert res.json_body['parent_id'] == 4
  769. assert res.json_body['content_id'] == 8
  770. assert res.json_body['workspace_id'] == 2
  771. def test_api_put_move_content__ok_200__to_root(self):
  772. """
  773. Move content
  774. move Apple_Pie (content_id: 8)
  775. from Desserts folder(content_id: 3) to root (content_id: 0)
  776. of workspace Recipes.
  777. """
  778. self.testapp.authorization = (
  779. 'Basic',
  780. (
  781. 'admin@admin.admin',
  782. 'admin@admin.admin'
  783. )
  784. )
  785. params = {
  786. 'new_parent_id': '0', # root
  787. }
  788. params_folder1 = {
  789. 'parent_id': 3,
  790. 'show_archived': 0,
  791. 'show_deleted': 0,
  792. 'show_active': 1,
  793. }
  794. params_folder2 = {
  795. 'parent_id': 0,
  796. 'show_archived': 0,
  797. 'show_deleted': 0,
  798. 'show_active': 1,
  799. }
  800. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  801. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  802. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  803. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  804. # TODO - G.M - 2018-06-163 - Check content
  805. res = self.testapp.put_json(
  806. '/api/v2/workspaces/2/contents/8/move',
  807. params=params,
  808. status=200
  809. )
  810. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  811. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  812. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  813. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  814. assert res.json_body
  815. assert res.json_body['parent_id'] == 0
  816. assert res.json_body['content_id'] == 8
  817. assert res.json_body['workspace_id'] == 2
  818. def test_api_put_move_content__ok_200__with_workspace_id(self):
  819. """
  820. Move content
  821. move Apple_Pie (content_id: 8)
  822. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  823. of workspace Recipes.
  824. """
  825. self.testapp.authorization = (
  826. 'Basic',
  827. (
  828. 'admin@admin.admin',
  829. 'admin@admin.admin'
  830. )
  831. )
  832. params = {
  833. 'new_parent_id': '4', # Salads
  834. 'new_workspace_id': '2',
  835. }
  836. params_folder1 = {
  837. 'parent_id': 3,
  838. 'show_archived': 0,
  839. 'show_deleted': 0,
  840. 'show_active': 1,
  841. }
  842. params_folder2 = {
  843. 'parent_id': 4,
  844. 'show_archived': 0,
  845. 'show_deleted': 0,
  846. 'show_active': 1,
  847. }
  848. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  849. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  850. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  851. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  852. # TODO - G.M - 2018-06-163 - Check content
  853. res = self.testapp.put_json(
  854. '/api/v2/workspaces/2/contents/8/move',
  855. params=params,
  856. status=200
  857. )
  858. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  859. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  860. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  861. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  862. assert res.json_body
  863. assert res.json_body['parent_id'] == 4
  864. assert res.json_body['content_id'] == 8
  865. assert res.json_body['workspace_id'] == 2
  866. def test_api_put_move_content__ok_200__to_another_workspace(self):
  867. """
  868. Move content
  869. move Apple_Pie (content_id: 8)
  870. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  871. of workspace Business.
  872. """
  873. self.testapp.authorization = (
  874. 'Basic',
  875. (
  876. 'admin@admin.admin',
  877. 'admin@admin.admin'
  878. )
  879. )
  880. params = {
  881. 'new_parent_id': '2', # Menus
  882. }
  883. params_folder1 = {
  884. 'parent_id': 3,
  885. 'show_archived': 0,
  886. 'show_deleted': 0,
  887. 'show_active': 1,
  888. }
  889. params_folder2 = {
  890. 'parent_id': 2,
  891. 'show_archived': 0,
  892. 'show_deleted': 0,
  893. 'show_active': 1,
  894. }
  895. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  896. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  897. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  898. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  899. # TODO - G.M - 2018-06-163 - Check content
  900. res = self.testapp.put_json(
  901. '/api/v2/workspaces/2/contents/8/move',
  902. params=params,
  903. status=200
  904. )
  905. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  906. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  907. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  908. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  909. assert res.json_body
  910. assert res.json_body['parent_id'] == 2
  911. assert res.json_body['content_id'] == 8
  912. assert res.json_body['workspace_id'] == 1
  913. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  914. """
  915. Move content
  916. move Apple_Pie (content_id: 8)
  917. from Desserts folder(content_id: 3) to root (content_id: 0)
  918. of workspace Business.
  919. """
  920. self.testapp.authorization = (
  921. 'Basic',
  922. (
  923. 'admin@admin.admin',
  924. 'admin@admin.admin'
  925. )
  926. )
  927. params = {
  928. 'new_parent_id': '0', # root
  929. 'new_workspace_id': '1',
  930. }
  931. params_folder1 = {
  932. 'parent_id': 3,
  933. 'show_archived': 0,
  934. 'show_deleted': 0,
  935. 'show_active': 1,
  936. }
  937. params_folder2 = {
  938. 'parent_id': 0,
  939. 'show_archived': 0,
  940. 'show_deleted': 0,
  941. 'show_active': 1,
  942. }
  943. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  944. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  945. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  946. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  947. # TODO - G.M - 2018-06-163 - Check content
  948. res = self.testapp.put_json(
  949. '/api/v2/workspaces/2/contents/8/move',
  950. params=params,
  951. status=200
  952. )
  953. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  954. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  955. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  956. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  957. assert res.json_body
  958. assert res.json_body['parent_id'] == 0
  959. assert res.json_body['content_id'] == 8
  960. assert res.json_body['workspace_id'] == 1
  961. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  962. """
  963. Move content
  964. move Apple_Pie (content_id: 8)
  965. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  966. of workspace Recipes.
  967. Workspace_id of parent_id don't match with workspace_id of workspace
  968. """
  969. self.testapp.authorization = (
  970. 'Basic',
  971. (
  972. 'admin@admin.admin',
  973. 'admin@admin.admin'
  974. )
  975. )
  976. params = {
  977. 'new_parent_id': '4', # Salads
  978. 'new_workspace_id': '1',
  979. }
  980. params_folder1 = {
  981. 'parent_id': 3,
  982. 'show_archived': 0,
  983. 'show_deleted': 0,
  984. 'show_active': 1,
  985. }
  986. params_folder2 = {
  987. 'parent_id': 4,
  988. 'show_archived': 0,
  989. 'show_deleted': 0,
  990. 'show_active': 1,
  991. }
  992. res = self.testapp.put_json(
  993. '/api/v2/workspaces/2/contents/8/move',
  994. params=params,
  995. status=400,
  996. )
  997. def test_api_put_delete_content__ok_200__nominal_case(self):
  998. """
  999. delete content
  1000. delete Apple_pie ( content_id: 8, parent_id: 3)
  1001. """
  1002. self.testapp.authorization = (
  1003. 'Basic',
  1004. (
  1005. 'admin@admin.admin',
  1006. 'admin@admin.admin'
  1007. )
  1008. )
  1009. params_active = {
  1010. 'parent_id': 3,
  1011. 'show_archived': 0,
  1012. 'show_deleted': 0,
  1013. 'show_active': 1,
  1014. }
  1015. params_deleted = {
  1016. 'parent_id': 3,
  1017. 'show_archived': 0,
  1018. 'show_deleted': 1,
  1019. 'show_active': 0,
  1020. }
  1021. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1022. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1023. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1024. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1025. # TODO - G.M - 2018-06-163 - Check content
  1026. res = self.testapp.put_json(
  1027. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1028. '/api/v2/workspaces/2/contents/8/delete',
  1029. status=204
  1030. )
  1031. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1032. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1033. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1034. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1035. def test_api_put_archive_content__ok_200__nominal_case(self):
  1036. """
  1037. archive content
  1038. archive Apple_pie ( content_id: 8, parent_id: 3)
  1039. """
  1040. self.testapp.authorization = (
  1041. 'Basic',
  1042. (
  1043. 'admin@admin.admin',
  1044. 'admin@admin.admin'
  1045. )
  1046. )
  1047. params_active = {
  1048. 'parent_id': 3,
  1049. 'show_archived': 0,
  1050. 'show_deleted': 0,
  1051. 'show_active': 1,
  1052. }
  1053. params_archived = {
  1054. 'parent_id': 3,
  1055. 'show_archived': 1,
  1056. 'show_deleted': 0,
  1057. 'show_active': 0,
  1058. }
  1059. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1060. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1061. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1062. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1063. res = self.testapp.put_json(
  1064. '/api/v2/workspaces/2/contents/8/archive',
  1065. status=204
  1066. )
  1067. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1068. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1069. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1070. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1071. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1072. """
  1073. Undelete content
  1074. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1075. """
  1076. self.testapp.authorization = (
  1077. 'Basic',
  1078. (
  1079. 'bob@fsf.local',
  1080. 'foobarbaz'
  1081. )
  1082. )
  1083. params_active = {
  1084. 'parent_id': 10,
  1085. 'show_archived': 0,
  1086. 'show_deleted': 0,
  1087. 'show_active': 1,
  1088. }
  1089. params_deleted = {
  1090. 'parent_id': 10,
  1091. 'show_archived': 0,
  1092. 'show_deleted': 1,
  1093. 'show_active': 0,
  1094. }
  1095. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1096. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1097. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1098. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1099. res = self.testapp.put_json(
  1100. '/api/v2/workspaces/2/contents/14/undelete',
  1101. status=204
  1102. )
  1103. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1104. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1105. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1106. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1107. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1108. """
  1109. unarchive content,
  1110. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1111. """
  1112. self.testapp.authorization = (
  1113. 'Basic',
  1114. (
  1115. 'bob@fsf.local',
  1116. 'foobarbaz'
  1117. )
  1118. )
  1119. params_active = {
  1120. 'parent_id': 10,
  1121. 'show_archived': 0,
  1122. 'show_deleted': 0,
  1123. 'show_active': 1,
  1124. }
  1125. params_archived = {
  1126. 'parent_id': 10,
  1127. 'show_archived': 1,
  1128. 'show_deleted': 0,
  1129. 'show_active': 0,
  1130. }
  1131. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1132. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1133. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  1134. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  1135. res = self.testapp.put_json(
  1136. '/api/v2/workspaces/2/contents/13/unarchive',
  1137. status=204
  1138. )
  1139. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1140. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1141. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  1142. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8