test_workspaces.py 46KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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/html-documents'
  45. assert sidebar_entry['label'] == 'Text Documents'
  46. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=html-documents' # 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', 'html-documents', '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', 'html-documents', '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', 'html-documents', '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'] == 'html-documents'
  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', 'html-documents', 'folder', 'file'} # nopep8
  285. assert content['workspace_id'] == 3
  286. content = res[2]
  287. assert content['content_type'] == 'html-documents'
  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', 'html-documents', 'folder', 'file'} # nopep8
  297. assert content['workspace_id'] == 3
  298. content = res[3]
  299. assert content['content_type'] == 'html-documents'
  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', 'html-documents', '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'] == 'html-documents'
  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', 'html-documents', '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'] == 'html-documents'
  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', 'html-documents', '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'] == 'html-documents'
  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', 'html-documents', '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'] == 'html-documents'
  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', 'html-documents', 'folder', 'file'} # nopep8
  477. assert content['workspace_id'] == 2
  478. content = res[1]
  479. assert content['content_type'] == 'html-documents'
  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', 'html-documents', 'folder', 'file'} # nopep8
  489. assert content['workspace_id'] == 2
  490. content = res[2]
  491. assert content['content_type'] == 'html-documents'
  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', 'html-documents', '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', 'html-documents', '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'] == 'html-documents'
  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', 'html-documents', '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'] == 'html-documents'
  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', 'html-documents', '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. 'new_workspace_id': '2',
  741. }
  742. params_folder1 = {
  743. 'parent_id': 3,
  744. 'show_archived': 0,
  745. 'show_deleted': 0,
  746. 'show_active': 1,
  747. }
  748. params_folder2 = {
  749. 'parent_id': 4,
  750. 'show_archived': 0,
  751. 'show_deleted': 0,
  752. 'show_active': 1,
  753. }
  754. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  755. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  756. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  757. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  758. # TODO - G.M - 2018-06-163 - Check content
  759. res = self.testapp.put_json(
  760. '/api/v2/workspaces/2/contents/8/move',
  761. params=params,
  762. status=200
  763. )
  764. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  765. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  766. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  767. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  768. assert res.json_body
  769. assert res.json_body['parent_id'] == 4
  770. assert res.json_body['content_id'] == 8
  771. assert res.json_body['workspace_id'] == 2
  772. def test_api_put_move_content__ok_200__to_root(self):
  773. """
  774. Move content
  775. move Apple_Pie (content_id: 8)
  776. from Desserts folder(content_id: 3) to root (content_id: 0)
  777. of workspace Recipes.
  778. """
  779. self.testapp.authorization = (
  780. 'Basic',
  781. (
  782. 'admin@admin.admin',
  783. 'admin@admin.admin'
  784. )
  785. )
  786. params = {
  787. 'new_parent_id': None, # root
  788. 'new_workspace_id': 2,
  789. }
  790. params_folder1 = {
  791. 'parent_id': 3,
  792. 'show_archived': 0,
  793. 'show_deleted': 0,
  794. 'show_active': 1,
  795. }
  796. params_folder2 = {
  797. 'parent_id': 0,
  798. 'show_archived': 0,
  799. 'show_deleted': 0,
  800. 'show_active': 1,
  801. }
  802. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  803. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  804. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  805. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  806. # TODO - G.M - 2018-06-163 - Check content
  807. res = self.testapp.put_json(
  808. '/api/v2/workspaces/2/contents/8/move',
  809. params=params,
  810. status=200
  811. )
  812. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  813. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  814. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  815. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  816. assert res.json_body
  817. assert res.json_body['parent_id'] is None
  818. assert res.json_body['content_id'] == 8
  819. assert res.json_body['workspace_id'] == 2
  820. def test_api_put_move_content__ok_200__with_workspace_id(self):
  821. """
  822. Move content
  823. move Apple_Pie (content_id: 8)
  824. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  825. of workspace Recipes.
  826. """
  827. self.testapp.authorization = (
  828. 'Basic',
  829. (
  830. 'admin@admin.admin',
  831. 'admin@admin.admin'
  832. )
  833. )
  834. params = {
  835. 'new_parent_id': '4', # Salads
  836. 'new_workspace_id': '2',
  837. }
  838. params_folder1 = {
  839. 'parent_id': 3,
  840. 'show_archived': 0,
  841. 'show_deleted': 0,
  842. 'show_active': 1,
  843. }
  844. params_folder2 = {
  845. 'parent_id': 4,
  846. 'show_archived': 0,
  847. 'show_deleted': 0,
  848. 'show_active': 1,
  849. }
  850. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  851. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  852. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  853. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  854. # TODO - G.M - 2018-06-163 - Check content
  855. res = self.testapp.put_json(
  856. '/api/v2/workspaces/2/contents/8/move',
  857. params=params,
  858. status=200
  859. )
  860. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  861. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  862. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  863. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  864. assert res.json_body
  865. assert res.json_body['parent_id'] == 4
  866. assert res.json_body['content_id'] == 8
  867. assert res.json_body['workspace_id'] == 2
  868. def test_api_put_move_content__ok_200__to_another_workspace(self):
  869. """
  870. Move content
  871. move Apple_Pie (content_id: 8)
  872. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  873. of workspace Business.
  874. """
  875. self.testapp.authorization = (
  876. 'Basic',
  877. (
  878. 'admin@admin.admin',
  879. 'admin@admin.admin'
  880. )
  881. )
  882. params = {
  883. 'new_parent_id': '2', # Menus
  884. 'new_workspace_id': '1',
  885. }
  886. params_folder1 = {
  887. 'parent_id': 3,
  888. 'show_archived': 0,
  889. 'show_deleted': 0,
  890. 'show_active': 1,
  891. }
  892. params_folder2 = {
  893. 'parent_id': 2,
  894. 'show_archived': 0,
  895. 'show_deleted': 0,
  896. 'show_active': 1,
  897. }
  898. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  899. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  900. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  901. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  902. # TODO - G.M - 2018-06-163 - Check content
  903. res = self.testapp.put_json(
  904. '/api/v2/workspaces/2/contents/8/move',
  905. params=params,
  906. status=200
  907. )
  908. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  909. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  910. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  911. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  912. assert res.json_body
  913. assert res.json_body['parent_id'] == 2
  914. assert res.json_body['content_id'] == 8
  915. assert res.json_body['workspace_id'] == 1
  916. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  917. """
  918. Move content
  919. move Apple_Pie (content_id: 8)
  920. from Desserts folder(content_id: 3) to root (content_id: 0)
  921. of workspace Business.
  922. """
  923. self.testapp.authorization = (
  924. 'Basic',
  925. (
  926. 'admin@admin.admin',
  927. 'admin@admin.admin'
  928. )
  929. )
  930. params = {
  931. 'new_parent_id': None, # root
  932. 'new_workspace_id': '1',
  933. }
  934. params_folder1 = {
  935. 'parent_id': 3,
  936. 'show_archived': 0,
  937. 'show_deleted': 0,
  938. 'show_active': 1,
  939. }
  940. params_folder2 = {
  941. 'parent_id': 0,
  942. 'show_archived': 0,
  943. 'show_deleted': 0,
  944. 'show_active': 1,
  945. }
  946. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  947. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  948. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  949. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  950. # TODO - G.M - 2018-06-163 - Check content
  951. res = self.testapp.put_json(
  952. '/api/v2/workspaces/2/contents/8/move',
  953. params=params,
  954. status=200
  955. )
  956. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  957. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  958. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  959. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  960. assert res.json_body
  961. assert res.json_body['parent_id'] is None
  962. assert res.json_body['content_id'] == 8
  963. assert res.json_body['workspace_id'] == 1
  964. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  965. """
  966. Move content
  967. move Apple_Pie (content_id: 8)
  968. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  969. of workspace Recipes.
  970. Workspace_id of parent_id don't match with workspace_id of workspace
  971. """
  972. self.testapp.authorization = (
  973. 'Basic',
  974. (
  975. 'admin@admin.admin',
  976. 'admin@admin.admin'
  977. )
  978. )
  979. params = {
  980. 'new_parent_id': '4', # Salads
  981. 'new_workspace_id': '1',
  982. }
  983. params_folder1 = {
  984. 'parent_id': 3,
  985. 'show_archived': 0,
  986. 'show_deleted': 0,
  987. 'show_active': 1,
  988. }
  989. params_folder2 = {
  990. 'parent_id': 4,
  991. 'show_archived': 0,
  992. 'show_deleted': 0,
  993. 'show_active': 1,
  994. }
  995. res = self.testapp.put_json(
  996. '/api/v2/workspaces/2/contents/8/move',
  997. params=params,
  998. status=400,
  999. )
  1000. def test_api_put_delete_content__ok_200__nominal_case(self):
  1001. """
  1002. delete content
  1003. delete Apple_pie ( content_id: 8, parent_id: 3)
  1004. """
  1005. self.testapp.authorization = (
  1006. 'Basic',
  1007. (
  1008. 'admin@admin.admin',
  1009. 'admin@admin.admin'
  1010. )
  1011. )
  1012. params_active = {
  1013. 'parent_id': 3,
  1014. 'show_archived': 0,
  1015. 'show_deleted': 0,
  1016. 'show_active': 1,
  1017. }
  1018. params_deleted = {
  1019. 'parent_id': 3,
  1020. 'show_archived': 0,
  1021. 'show_deleted': 1,
  1022. 'show_active': 0,
  1023. }
  1024. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1025. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1026. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1027. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1028. # TODO - G.M - 2018-06-163 - Check content
  1029. res = self.testapp.put_json(
  1030. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1031. '/api/v2/workspaces/2/contents/8/delete',
  1032. status=204
  1033. )
  1034. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1035. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1036. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1037. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1038. def test_api_put_archive_content__ok_200__nominal_case(self):
  1039. """
  1040. archive content
  1041. archive Apple_pie ( content_id: 8, parent_id: 3)
  1042. """
  1043. self.testapp.authorization = (
  1044. 'Basic',
  1045. (
  1046. 'admin@admin.admin',
  1047. 'admin@admin.admin'
  1048. )
  1049. )
  1050. params_active = {
  1051. 'parent_id': 3,
  1052. 'show_archived': 0,
  1053. 'show_deleted': 0,
  1054. 'show_active': 1,
  1055. }
  1056. params_archived = {
  1057. 'parent_id': 3,
  1058. 'show_archived': 1,
  1059. 'show_deleted': 0,
  1060. 'show_active': 0,
  1061. }
  1062. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1063. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1064. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1065. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1066. res = self.testapp.put_json(
  1067. '/api/v2/workspaces/2/contents/8/archive',
  1068. status=204
  1069. )
  1070. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1071. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1072. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1073. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1074. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1075. """
  1076. Undelete content
  1077. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1078. """
  1079. self.testapp.authorization = (
  1080. 'Basic',
  1081. (
  1082. 'bob@fsf.local',
  1083. 'foobarbaz'
  1084. )
  1085. )
  1086. params_active = {
  1087. 'parent_id': 10,
  1088. 'show_archived': 0,
  1089. 'show_deleted': 0,
  1090. 'show_active': 1,
  1091. }
  1092. params_deleted = {
  1093. 'parent_id': 10,
  1094. 'show_archived': 0,
  1095. 'show_deleted': 1,
  1096. 'show_active': 0,
  1097. }
  1098. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1099. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1100. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1101. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1102. res = self.testapp.put_json(
  1103. '/api/v2/workspaces/2/contents/14/undelete',
  1104. status=204
  1105. )
  1106. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1107. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1108. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1109. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1110. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1111. """
  1112. unarchive content,
  1113. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1114. """
  1115. self.testapp.authorization = (
  1116. 'Basic',
  1117. (
  1118. 'bob@fsf.local',
  1119. 'foobarbaz'
  1120. )
  1121. )
  1122. params_active = {
  1123. 'parent_id': 10,
  1124. 'show_archived': 0,
  1125. 'show_deleted': 0,
  1126. 'show_active': 1,
  1127. }
  1128. params_archived = {
  1129. 'parent_id': 10,
  1130. 'show_archived': 1,
  1131. 'show_deleted': 0,
  1132. 'show_active': 0,
  1133. }
  1134. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1135. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1136. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  1137. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  1138. res = self.testapp.put_json(
  1139. '/api/v2/workspaces/2/contents/13/unarchive',
  1140. status=204
  1141. )
  1142. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1143. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1144. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  1145. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8