test_workspaces.py 61KB

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