test_workspaces.py 50KB

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