test_workspaces.py 75KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050
  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_backend import models
  8. from tracim_backend.lib.core.content import ContentApi
  9. from tracim_backend.lib.core.workspace import WorkspaceApi
  10. from tracim_backend.models import get_tm_session
  11. from tracim_backend.models.data import ContentType
  12. from tracim_backend.tests import FunctionalTest
  13. from tracim_backend.tests import set_html_document_slug_to_legacy
  14. from tracim_backend.fixtures.content import Content as ContentFixtures
  15. from tracim_backend.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-document'
  53. assert sidebar_entry['label'] == 'Text Documents'
  54. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=html-document' # 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/file'
  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/thread'
  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__update_workspace__ok_200__nominal_case(self) -> None:
  82. """
  83. Test update workspace
  84. """
  85. self.testapp.authorization = (
  86. 'Basic',
  87. (
  88. 'admin@admin.admin',
  89. 'admin@admin.admin'
  90. )
  91. )
  92. params = {
  93. 'label': 'superworkspace',
  94. 'description': 'mysuperdescription'
  95. }
  96. # Before
  97. res = self.testapp.get(
  98. '/api/v2/workspaces/1',
  99. status=200
  100. )
  101. assert res.json_body
  102. workspace = res.json_body
  103. assert workspace['workspace_id'] == 1
  104. assert workspace['slug'] == 'business'
  105. assert workspace['label'] == 'Business'
  106. assert workspace['description'] == 'All importants documents'
  107. assert len(workspace['sidebar_entries']) == 7
  108. # modify workspace
  109. res = self.testapp.put_json(
  110. '/api/v2/workspaces/1',
  111. status=200,
  112. params=params,
  113. )
  114. assert res.json_body
  115. workspace = res.json_body
  116. assert workspace['workspace_id'] == 1
  117. assert workspace['slug'] == 'superworkspace'
  118. assert workspace['label'] == 'superworkspace'
  119. assert workspace['description'] == 'mysuperdescription'
  120. assert len(workspace['sidebar_entries']) == 7
  121. # after
  122. res = self.testapp.get(
  123. '/api/v2/workspaces/1',
  124. status=200
  125. )
  126. assert res.json_body
  127. workspace = res.json_body
  128. assert workspace['workspace_id'] == 1
  129. assert workspace['slug'] == 'superworkspace'
  130. assert workspace['label'] == 'superworkspace'
  131. assert workspace['description'] == 'mysuperdescription'
  132. assert len(workspace['sidebar_entries']) == 7
  133. def test_api__update_workspace__err_400__empty_label(self) -> None:
  134. """
  135. Test update workspace with empty label
  136. """
  137. self.testapp.authorization = (
  138. 'Basic',
  139. (
  140. 'admin@admin.admin',
  141. 'admin@admin.admin'
  142. )
  143. )
  144. params = {
  145. 'label': '',
  146. 'description': 'mysuperdescription'
  147. }
  148. res = self.testapp.put_json(
  149. '/api/v2/workspaces/1',
  150. status=400,
  151. params=params,
  152. )
  153. def test_api__create_workspace__ok_200__nominal_case(self) -> None:
  154. """
  155. Test create workspace
  156. """
  157. self.testapp.authorization = (
  158. 'Basic',
  159. (
  160. 'admin@admin.admin',
  161. 'admin@admin.admin'
  162. )
  163. )
  164. params = {
  165. 'label': 'superworkspace',
  166. 'description': 'mysuperdescription'
  167. }
  168. res = self.testapp.post_json(
  169. '/api/v2/workspaces',
  170. status=200,
  171. params=params,
  172. )
  173. assert res.json_body
  174. workspace = res.json_body
  175. workspace_id = res.json_body['workspace_id']
  176. res = self.testapp.get(
  177. '/api/v2/workspaces/{}'.format(workspace_id),
  178. status=200
  179. )
  180. workspace_2 = res.json_body
  181. assert workspace == workspace_2
  182. def test_api__create_workspace__err_400__empty_label(self) -> None:
  183. """
  184. Test create workspace with empty label
  185. """
  186. self.testapp.authorization = (
  187. 'Basic',
  188. (
  189. 'admin@admin.admin',
  190. 'admin@admin.admin'
  191. )
  192. )
  193. params = {
  194. 'label': '',
  195. 'description': 'mysuperdescription'
  196. }
  197. res = self.testapp.post_json(
  198. '/api/v2/workspaces',
  199. status=400,
  200. params=params,
  201. )
  202. def test_api__get_workspace__err_400__unallowed_user(self) -> None:
  203. """
  204. Check obtain workspace unreachable for user
  205. """
  206. self.testapp.authorization = (
  207. 'Basic',
  208. (
  209. 'lawrence-not-real-email@fsf.local',
  210. 'foobarbaz'
  211. )
  212. )
  213. res = self.testapp.get('/api/v2/workspaces/1', status=400)
  214. assert isinstance(res.json, dict)
  215. assert 'code' in res.json.keys()
  216. assert 'message' in res.json.keys()
  217. assert 'details' in res.json.keys()
  218. def test_api__get_workspace__err_401__unregistered_user(self) -> None:
  219. """
  220. Check obtain workspace without registered user.
  221. """
  222. self.testapp.authorization = (
  223. 'Basic',
  224. (
  225. 'john@doe.doe',
  226. 'lapin'
  227. )
  228. )
  229. res = self.testapp.get('/api/v2/workspaces/1', status=401)
  230. assert isinstance(res.json, dict)
  231. assert 'code' in res.json.keys()
  232. assert 'message' in res.json.keys()
  233. assert 'details' in res.json.keys()
  234. def test_api__get_workspace__err_400__workspace_does_not_exist(self) -> None: # nopep8
  235. """
  236. Check obtain workspace who does not exist with an existing user.
  237. """
  238. self.testapp.authorization = (
  239. 'Basic',
  240. (
  241. 'admin@admin.admin',
  242. 'admin@admin.admin'
  243. )
  244. )
  245. res = self.testapp.get('/api/v2/workspaces/5', status=400)
  246. assert isinstance(res.json, dict)
  247. assert 'code' in res.json.keys()
  248. assert 'message' in res.json.keys()
  249. assert 'details' in res.json.keys()
  250. class TestWorkspaceMembersEndpoint(FunctionalTest):
  251. """
  252. Tests for /api/v2/workspaces/{workspace_id}/members endpoint
  253. """
  254. fixtures = [BaseFixture, ContentFixtures]
  255. def test_api__get_workspace_members__ok_200__nominal_case(self):
  256. """
  257. Check obtain workspace members list with a reachable workspace for user
  258. """
  259. self.testapp.authorization = (
  260. 'Basic',
  261. (
  262. 'admin@admin.admin',
  263. 'admin@admin.admin'
  264. )
  265. )
  266. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  267. assert len(res) == 1
  268. user_role = res[0]
  269. assert user_role['role'] == 'workspace-manager'
  270. assert user_role['user_id'] == 1
  271. assert user_role['workspace_id'] == 1
  272. assert user_role['workspace']['workspace_id'] == 1
  273. assert user_role['workspace']['label'] == 'Business'
  274. assert user_role['workspace']['slug'] == 'business'
  275. assert user_role['user']['public_name'] == 'Global manager'
  276. assert user_role['user']['user_id'] == 1
  277. assert user_role['is_active'] is True
  278. # TODO - G.M - 24-05-2018 - [Avatar] Replace
  279. # by correct value when avatar feature will be enabled
  280. assert user_role['user']['avatar_url'] is None
  281. def test_api__get_workspace_members__err_400__unallowed_user(self):
  282. """
  283. Check obtain workspace members list with an unreachable workspace for
  284. user
  285. """
  286. self.testapp.authorization = (
  287. 'Basic',
  288. (
  289. 'lawrence-not-real-email@fsf.local',
  290. 'foobarbaz'
  291. )
  292. )
  293. res = self.testapp.get('/api/v2/workspaces/3/members', status=400)
  294. assert isinstance(res.json, dict)
  295. assert 'code' in res.json.keys()
  296. assert 'message' in res.json.keys()
  297. assert 'details' in res.json.keys()
  298. def test_api__get_workspace_members__err_401__unregistered_user(self):
  299. """
  300. Check obtain workspace members list with an unregistered user
  301. """
  302. self.testapp.authorization = (
  303. 'Basic',
  304. (
  305. 'john@doe.doe',
  306. 'lapin'
  307. )
  308. )
  309. res = self.testapp.get('/api/v2/workspaces/1/members', status=401)
  310. assert isinstance(res.json, dict)
  311. assert 'code' in res.json.keys()
  312. assert 'message' in res.json.keys()
  313. assert 'details' in res.json.keys()
  314. def test_api__get_workspace_members__err_400__workspace_does_not_exist(self): # nopep8
  315. """
  316. Check obtain workspace members list with an existing user but
  317. an unexisting workspace
  318. """
  319. self.testapp.authorization = (
  320. 'Basic',
  321. (
  322. 'admin@admin.admin',
  323. 'admin@admin.admin'
  324. )
  325. )
  326. res = self.testapp.get('/api/v2/workspaces/5/members', status=400)
  327. assert isinstance(res.json, dict)
  328. assert 'code' in res.json.keys()
  329. assert 'message' in res.json.keys()
  330. assert 'details' in res.json.keys()
  331. def test_api__create_workspace_member_role__ok_200__user_id(self):
  332. """
  333. Create workspace member role
  334. :return:
  335. """
  336. self.testapp.authorization = (
  337. 'Basic',
  338. (
  339. 'admin@admin.admin',
  340. 'admin@admin.admin'
  341. )
  342. )
  343. # create workspace role
  344. params = {
  345. 'user_id': 2,
  346. 'user_email_or_public_name': None,
  347. 'role': 'content-manager',
  348. }
  349. res = self.testapp.post_json(
  350. '/api/v2/workspaces/1/members',
  351. status=200,
  352. params=params,
  353. )
  354. user_role_found = res.json_body
  355. assert user_role_found['role'] == 'content-manager'
  356. assert user_role_found['user_id'] == 2
  357. assert user_role_found['workspace_id'] == 1
  358. assert user_role_found['newly_created'] is False
  359. assert user_role_found['email_sent'] is False
  360. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  361. assert len(res) == 2
  362. user_role = res[0]
  363. assert user_role['role'] == 'workspace-manager'
  364. assert user_role['user_id'] == 1
  365. assert user_role['workspace_id'] == 1
  366. user_role = res[1]
  367. assert user_role_found['role'] == user_role['role']
  368. assert user_role_found['user_id'] == user_role['user_id']
  369. assert user_role_found['workspace_id'] == user_role['workspace_id']
  370. def test_api__create_workspace_member_role__ok_200__user_email(self):
  371. """
  372. Create workspace member role
  373. :return:
  374. """
  375. self.testapp.authorization = (
  376. 'Basic',
  377. (
  378. 'admin@admin.admin',
  379. 'admin@admin.admin'
  380. )
  381. )
  382. # create workspace role
  383. params = {
  384. 'user_id': None,
  385. 'user_email_or_public_name': 'lawrence-not-real-email@fsf.local',
  386. 'role': 'content-manager',
  387. }
  388. res = self.testapp.post_json(
  389. '/api/v2/workspaces/1/members',
  390. status=200,
  391. params=params,
  392. )
  393. user_role_found = res.json_body
  394. assert user_role_found['role'] == 'content-manager'
  395. assert user_role_found['user_id'] == 2
  396. assert user_role_found['workspace_id'] == 1
  397. assert user_role_found['newly_created'] is False
  398. assert user_role_found['email_sent'] is False
  399. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  400. assert len(res) == 2
  401. user_role = res[0]
  402. assert user_role['role'] == 'workspace-manager'
  403. assert user_role['user_id'] == 1
  404. assert user_role['workspace_id'] == 1
  405. user_role = res[1]
  406. assert user_role_found['role'] == user_role['role']
  407. assert user_role_found['user_id'] == user_role['user_id']
  408. assert user_role_found['workspace_id'] == user_role['workspace_id']
  409. def test_api__create_workspace_member_role__ok_200__user_public_name(self):
  410. """
  411. Create workspace member role
  412. :return:
  413. """
  414. self.testapp.authorization = (
  415. 'Basic',
  416. (
  417. 'admin@admin.admin',
  418. 'admin@admin.admin'
  419. )
  420. )
  421. # create workspace role
  422. params = {
  423. 'user_id': None,
  424. 'user_email_or_public_name': 'Lawrence L.',
  425. 'role': 'content-manager',
  426. }
  427. res = self.testapp.post_json(
  428. '/api/v2/workspaces/1/members',
  429. status=200,
  430. params=params,
  431. )
  432. user_role_found = res.json_body
  433. assert user_role_found['role'] == 'content-manager'
  434. assert user_role_found['user_id'] == 2
  435. assert user_role_found['workspace_id'] == 1
  436. assert user_role_found['newly_created'] is False
  437. assert user_role_found['email_sent'] is False
  438. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  439. assert len(res) == 2
  440. user_role = res[0]
  441. assert user_role['role'] == 'workspace-manager'
  442. assert user_role['user_id'] == 1
  443. assert user_role['workspace_id'] == 1
  444. user_role = res[1]
  445. assert user_role_found['role'] == user_role['role']
  446. assert user_role_found['user_id'] == user_role['user_id']
  447. assert user_role_found['workspace_id'] == user_role['workspace_id']
  448. def test_api__create_workspace_member_role__err_400__nothing(self):
  449. """
  450. Create workspace member role
  451. :return:
  452. """
  453. self.testapp.authorization = (
  454. 'Basic',
  455. (
  456. 'admin@admin.admin',
  457. 'admin@admin.admin'
  458. )
  459. )
  460. # create workspace role
  461. params = {
  462. 'user_id': None,
  463. 'user_email_or_public_name': None,
  464. 'role': 'content-manager',
  465. }
  466. res = self.testapp.post_json(
  467. '/api/v2/workspaces/1/members',
  468. status=400,
  469. params=params,
  470. )
  471. def test_api__create_workspace_member_role__err_400__wrong_user_id(self):
  472. """
  473. Create workspace member role
  474. :return:
  475. """
  476. self.testapp.authorization = (
  477. 'Basic',
  478. (
  479. 'admin@admin.admin',
  480. 'admin@admin.admin'
  481. )
  482. )
  483. # create workspace role
  484. params = {
  485. 'user_id': 47,
  486. 'user_email_or_public_name': None,
  487. 'role': 'content-manager',
  488. }
  489. res = self.testapp.post_json(
  490. '/api/v2/workspaces/1/members',
  491. status=400,
  492. params=params,
  493. )
  494. def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8
  495. """
  496. Create workspace member role
  497. :return:
  498. """
  499. self.testapp.authorization = (
  500. 'Basic',
  501. (
  502. 'admin@admin.admin',
  503. 'admin@admin.admin'
  504. )
  505. )
  506. # create workspace role
  507. params = {
  508. 'user_id': None,
  509. 'user_email_or_public_name': 'nothing@nothing.nothing',
  510. 'role': 'content-manager',
  511. }
  512. res = self.testapp.post_json(
  513. '/api/v2/workspaces/1/members',
  514. status=200,
  515. params=params,
  516. )
  517. user_role_found = res.json_body
  518. assert user_role_found['role'] == 'content-manager'
  519. assert user_role_found['user_id']
  520. user_id = user_role_found['user_id']
  521. assert user_role_found['workspace_id'] == 1
  522. assert user_role_found['newly_created'] is True
  523. assert user_role_found['email_sent'] is False
  524. res = self.testapp.get('/api/v2/workspaces/1/members',
  525. status=200).json_body # nopep8
  526. assert len(res) == 2
  527. user_role = res[0]
  528. assert user_role['role'] == 'workspace-manager'
  529. assert user_role['user_id'] == 1
  530. assert user_role['workspace_id'] == 1
  531. user_role = res[1]
  532. assert user_role_found['role'] == user_role['role']
  533. assert user_role_found['user_id'] == user_role['user_id']
  534. assert user_role_found['workspace_id'] == user_role['workspace_id']
  535. def test_api__update_workspace_member_role__ok_200__nominal_case(self):
  536. """
  537. Update worskpace member role
  538. """
  539. # before
  540. self.testapp.authorization = (
  541. 'Basic',
  542. (
  543. 'admin@admin.admin',
  544. 'admin@admin.admin'
  545. )
  546. )
  547. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  548. assert len(res) == 1
  549. user_role = res[0]
  550. assert user_role['role'] == 'workspace-manager'
  551. assert user_role['user_id'] == 1
  552. assert user_role['workspace_id'] == 1
  553. # update workspace role
  554. params = {
  555. 'role': 'content-manager',
  556. }
  557. res = self.testapp.put_json(
  558. '/api/v2/workspaces/1/members/1',
  559. status=200,
  560. params=params,
  561. )
  562. user_role = res.json_body
  563. assert user_role['role'] == 'content-manager'
  564. assert user_role['user_id'] == 1
  565. assert user_role['workspace_id'] == 1
  566. # after
  567. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  568. assert len(res) == 1
  569. user_role = res[0]
  570. assert user_role['role'] == 'content-manager'
  571. assert user_role['user_id'] == 1
  572. assert user_role['workspace_id'] == 1
  573. class TestWorkspaceContents(FunctionalTest):
  574. """
  575. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  576. """
  577. fixtures = [BaseFixture, ContentFixtures]
  578. def test_api__get_workspace_content__ok_200__get_default(self):
  579. """
  580. Check obtain workspace contents with defaults filters
  581. """
  582. self.testapp.authorization = (
  583. 'Basic',
  584. (
  585. 'admin@admin.admin',
  586. 'admin@admin.admin'
  587. )
  588. )
  589. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  590. # TODO - G.M - 30-05-2018 - Check this test
  591. assert len(res) == 3
  592. content = res[0]
  593. assert content['content_id'] == 1
  594. assert content['content_type'] == 'folder'
  595. assert content['is_archived'] is False
  596. assert content['is_deleted'] is False
  597. assert content['label'] == 'Tools'
  598. assert content['parent_id'] is None
  599. assert content['show_in_ui'] is True
  600. assert content['slug'] == 'tools'
  601. assert content['status'] == 'open'
  602. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  603. assert content['workspace_id'] == 1
  604. content = res[1]
  605. assert content['content_id'] == 2
  606. assert content['content_type'] == 'folder'
  607. assert content['is_archived'] is False
  608. assert content['is_deleted'] is False
  609. assert content['label'] == 'Menus'
  610. assert content['parent_id'] is None
  611. assert content['show_in_ui'] is True
  612. assert content['slug'] == 'menus'
  613. assert content['status'] == 'open'
  614. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  615. assert content['workspace_id'] == 1
  616. content = res[2]
  617. assert content['content_id'] == 11
  618. assert content['content_type'] == 'html-document'
  619. assert content['is_archived'] is False
  620. assert content['is_deleted'] is False
  621. assert content['label'] == 'Current Menu'
  622. assert content['parent_id'] == 2
  623. assert content['show_in_ui'] is True
  624. assert content['slug'] == 'current-menu'
  625. assert content['status'] == 'open'
  626. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  627. assert content['workspace_id'] == 1
  628. def test_api__get_workspace_content__ok_200__get_default_html_documents(self):
  629. """
  630. Check obtain workspace contents with defaults filters + content_filter
  631. """
  632. self.testapp.authorization = (
  633. 'Basic',
  634. (
  635. 'admin@admin.admin',
  636. 'admin@admin.admin'
  637. )
  638. )
  639. params = {
  640. 'content_type': 'html-document',
  641. }
  642. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200, params=params).json_body # nopep8
  643. assert len(res) == 1
  644. content = res[0]
  645. assert content
  646. assert content['content_id'] == 11
  647. assert content['content_type'] == 'html-document'
  648. assert content['is_archived'] is False
  649. assert content['is_deleted'] is False
  650. assert content['label'] == 'Current Menu'
  651. assert content['parent_id'] == 2
  652. assert content['show_in_ui'] is True
  653. assert content['slug'] == 'current-menu'
  654. assert content['status'] == 'open'
  655. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  656. assert content['workspace_id'] == 1
  657. # Root related
  658. def test_api__get_workspace_content__ok_200__get_all_root_content__legacy_html_slug(self): # nopep8
  659. """
  660. Check obtain workspace all root contents
  661. """
  662. set_html_document_slug_to_legacy(self.session_factory)
  663. params = {
  664. 'parent_id': 0,
  665. 'show_archived': 1,
  666. 'show_deleted': 1,
  667. 'show_active': 1,
  668. }
  669. self.testapp.authorization = (
  670. 'Basic',
  671. (
  672. 'bob@fsf.local',
  673. 'foobarbaz'
  674. )
  675. )
  676. res = self.testapp.get(
  677. '/api/v2/workspaces/3/contents',
  678. status=200,
  679. params=params,
  680. ).json_body # nopep8
  681. # TODO - G.M - 30-05-2018 - Check this test
  682. assert len(res) == 4
  683. content = res[1]
  684. assert content['content_type'] == 'html-document'
  685. assert content['content_id'] == 15
  686. assert content['is_archived'] is False
  687. assert content['is_deleted'] is False
  688. assert content['label'] == 'New Fruit Salad'
  689. assert content['parent_id'] is None
  690. assert content['show_in_ui'] is True
  691. assert content['slug'] == 'new-fruit-salad'
  692. assert content['status'] == 'open'
  693. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  694. assert content['workspace_id'] == 3
  695. content = res[2]
  696. assert content['content_type'] == 'html-document'
  697. assert content['content_id'] == 16
  698. assert content['is_archived'] is True
  699. assert content['is_deleted'] is False
  700. assert content['label'].startswith('Fruit Salad')
  701. assert content['parent_id'] is None
  702. assert content['show_in_ui'] is True
  703. assert content['slug'].startswith('fruit-salad')
  704. assert content['status'] == 'open'
  705. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  706. assert content['workspace_id'] == 3
  707. content = res[3]
  708. assert content['content_type'] == 'html-document'
  709. assert content['content_id'] == 17
  710. assert content['is_archived'] is False
  711. assert content['is_deleted'] is True
  712. assert content['label'].startswith('Bad Fruit Salad')
  713. assert content['parent_id'] is None
  714. assert content['show_in_ui'] is True
  715. assert content['slug'].startswith('bad-fruit-salad')
  716. assert content['status'] == 'open'
  717. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  718. assert content['workspace_id'] == 3
  719. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  720. """
  721. Check obtain workspace all root contents
  722. """
  723. params = {
  724. 'parent_id': 0,
  725. 'show_archived': 1,
  726. 'show_deleted': 1,
  727. 'show_active': 1,
  728. }
  729. self.testapp.authorization = (
  730. 'Basic',
  731. (
  732. 'bob@fsf.local',
  733. 'foobarbaz'
  734. )
  735. )
  736. res = self.testapp.get(
  737. '/api/v2/workspaces/3/contents',
  738. status=200,
  739. params=params,
  740. ).json_body # nopep8
  741. # TODO - G.M - 30-05-2018 - Check this test
  742. assert len(res) == 4
  743. content = res[1]
  744. assert content['content_type'] == 'html-document'
  745. assert content['content_id'] == 15
  746. assert content['is_archived'] is False
  747. assert content['is_deleted'] is False
  748. assert content['label'] == 'New Fruit Salad'
  749. assert content['parent_id'] is None
  750. assert content['show_in_ui'] is True
  751. assert content['slug'] == 'new-fruit-salad'
  752. assert content['status'] == 'open'
  753. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  754. assert content['workspace_id'] == 3
  755. content = res[2]
  756. assert content['content_type'] == 'html-document'
  757. assert content['content_id'] == 16
  758. assert content['is_archived'] is True
  759. assert content['is_deleted'] is False
  760. assert content['label'].startswith('Fruit Salad')
  761. assert content['parent_id'] is None
  762. assert content['show_in_ui'] is True
  763. assert content['slug'].startswith('fruit-salad')
  764. assert content['status'] == 'open'
  765. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  766. assert content['workspace_id'] == 3
  767. content = res[3]
  768. assert content['content_type'] == 'html-document'
  769. assert content['content_id'] == 17
  770. assert content['is_archived'] is False
  771. assert content['is_deleted'] is True
  772. assert content['label'].startswith('Bad Fruit Salad')
  773. assert content['parent_id'] is None
  774. assert content['show_in_ui'] is True
  775. assert content['slug'].startswith('bad-fruit-salad')
  776. assert content['status'] == 'open'
  777. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  778. assert content['workspace_id'] == 3
  779. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8
  780. """
  781. Check obtain workspace root active contents
  782. """
  783. params = {
  784. 'parent_id': 0,
  785. 'show_archived': 0,
  786. 'show_deleted': 0,
  787. 'show_active': 1,
  788. }
  789. self.testapp.authorization = (
  790. 'Basic',
  791. (
  792. 'bob@fsf.local',
  793. 'foobarbaz'
  794. )
  795. )
  796. res = self.testapp.get(
  797. '/api/v2/workspaces/3/contents',
  798. status=200,
  799. params=params,
  800. ).json_body # nopep8
  801. # TODO - G.M - 30-05-2018 - Check this test
  802. assert len(res) == 2
  803. content = res[1]
  804. assert content['content_type'] == 'html-document'
  805. assert content['content_id'] == 15
  806. assert content['is_archived'] is False
  807. assert content['is_deleted'] is False
  808. assert content['label'] == 'New Fruit Salad'
  809. assert content['parent_id'] is None
  810. assert content['show_in_ui'] is True
  811. assert content['slug'] == 'new-fruit-salad'
  812. assert content['status'] == 'open'
  813. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  814. assert content['workspace_id'] == 3
  815. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8
  816. """
  817. Check obtain workspace root archived contents
  818. """
  819. params = {
  820. 'parent_id': 0,
  821. 'show_archived': 1,
  822. 'show_deleted': 0,
  823. 'show_active': 0,
  824. }
  825. self.testapp.authorization = (
  826. 'Basic',
  827. (
  828. 'bob@fsf.local',
  829. 'foobarbaz'
  830. )
  831. )
  832. res = self.testapp.get(
  833. '/api/v2/workspaces/3/contents',
  834. status=200,
  835. params=params,
  836. ).json_body # nopep8
  837. assert len(res) == 1
  838. content = res[0]
  839. assert content['content_type'] == 'html-document'
  840. assert content['content_id'] == 16
  841. assert content['is_archived'] is True
  842. assert content['is_deleted'] is False
  843. assert content['label'].startswith('Fruit Salad')
  844. assert content['parent_id'] is None
  845. assert content['show_in_ui'] is True
  846. assert content['slug'].startswith('fruit-salad')
  847. assert content['status'] == 'open'
  848. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  849. assert content['workspace_id'] == 3
  850. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8
  851. """
  852. Check obtain workspace root deleted contents
  853. """
  854. params = {
  855. 'parent_id': 0,
  856. 'show_archived': 0,
  857. 'show_deleted': 1,
  858. 'show_active': 0,
  859. }
  860. self.testapp.authorization = (
  861. 'Basic',
  862. (
  863. 'bob@fsf.local',
  864. 'foobarbaz'
  865. )
  866. )
  867. res = self.testapp.get(
  868. '/api/v2/workspaces/3/contents',
  869. status=200,
  870. params=params,
  871. ).json_body # nopep8
  872. # TODO - G.M - 30-05-2018 - Check this test
  873. assert len(res) == 1
  874. content = res[0]
  875. assert content['content_type'] == 'html-document'
  876. assert content['content_id'] == 17
  877. assert content['is_archived'] is False
  878. assert content['is_deleted'] is True
  879. assert content['label'].startswith('Bad Fruit Salad')
  880. assert content['parent_id'] is None
  881. assert content['show_in_ui'] is True
  882. assert content['slug'].startswith('bad-fruit-salad')
  883. assert content['status'] == 'open'
  884. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  885. assert content['workspace_id'] == 3
  886. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  887. """
  888. Check obtain workspace root content who does not match any type
  889. (archived, deleted, active) result should be empty list.
  890. """
  891. params = {
  892. 'parent_id': 0,
  893. 'show_archived': 0,
  894. 'show_deleted': 0,
  895. 'show_active': 0,
  896. }
  897. self.testapp.authorization = (
  898. 'Basic',
  899. (
  900. 'bob@fsf.local',
  901. 'foobarbaz'
  902. )
  903. )
  904. res = self.testapp.get(
  905. '/api/v2/workspaces/3/contents',
  906. status=200,
  907. params=params,
  908. ).json_body # nopep8
  909. # TODO - G.M - 30-05-2018 - Check this test
  910. assert res == []
  911. # Folder related
  912. def test_api__get_workspace_content__ok_200__get_all_filter_content_thread(self):
  913. # prepare data
  914. dbsession = get_tm_session(self.session_factory, transaction.manager)
  915. admin = dbsession.query(models.User) \
  916. .filter(models.User.email == 'admin@admin.admin') \
  917. .one()
  918. workspace_api = WorkspaceApi(
  919. current_user=admin,
  920. session=dbsession,
  921. config=self.app_config
  922. )
  923. business_workspace = workspace_api.get_one(1)
  924. content_api = ContentApi(
  925. current_user=admin,
  926. session=dbsession,
  927. config=self.app_config
  928. )
  929. tool_folder = content_api.get_one(1, content_type=ContentType.Any)
  930. test_thread = content_api.create(
  931. content_type=ContentType.Thread,
  932. workspace=business_workspace,
  933. parent=tool_folder,
  934. label='Test Thread',
  935. do_save=False,
  936. do_notify=False,
  937. )
  938. test_thread.description = 'Thread description'
  939. dbsession.add(test_thread)
  940. test_file = content_api.create(
  941. content_type=ContentType.File,
  942. workspace=business_workspace,
  943. parent=tool_folder,
  944. label='Test file',
  945. do_save=False,
  946. do_notify=False,
  947. )
  948. test_file.file_extension = '.txt'
  949. test_file.depot_file = FileIntent(
  950. b'Test file',
  951. 'Test_file.txt',
  952. 'text/plain',
  953. )
  954. test_page_legacy = content_api.create(
  955. content_type=ContentType.Page,
  956. workspace=business_workspace,
  957. label='test_page',
  958. do_save=False,
  959. do_notify=False,
  960. )
  961. test_page_legacy.type = ContentType.PageLegacy
  962. content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
  963. test_html_document = content_api.create(
  964. content_type=ContentType.Page,
  965. workspace=business_workspace,
  966. label='test_html_page',
  967. do_save=False,
  968. do_notify=False,
  969. )
  970. content_api.update_content(test_html_document, 'test_page', '<p>HTML_DOCUMENT</p>') # nopep8
  971. dbsession.flush()
  972. transaction.commit()
  973. # test-itself
  974. params = {
  975. 'parent_id': 1,
  976. 'show_archived': 1,
  977. 'show_deleted': 1,
  978. 'show_active': 1,
  979. 'content_type': 'thread',
  980. }
  981. self.testapp.authorization = (
  982. 'Basic',
  983. (
  984. 'admin@admin.admin',
  985. 'admin@admin.admin'
  986. )
  987. )
  988. res = self.testapp.get(
  989. '/api/v2/workspaces/1/contents',
  990. status=200,
  991. params=params,
  992. ).json_body
  993. assert len(res) == 1
  994. content = res[0]
  995. assert content['content_type'] == 'thread'
  996. assert content['content_id']
  997. assert content['is_archived'] is False
  998. assert content['is_deleted'] is False
  999. assert content['label'] == 'Test Thread'
  1000. assert content['parent_id'] == 1
  1001. assert content['show_in_ui'] is True
  1002. assert content['slug'] == 'test-thread'
  1003. assert content['status'] == 'open'
  1004. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1005. assert content['workspace_id'] == 1
  1006. def test_api__get_workspace_content__ok_200__get_all_filter_content_html_and_legacy_page(self): # nopep8
  1007. # prepare data
  1008. dbsession = get_tm_session(self.session_factory, transaction.manager)
  1009. admin = dbsession.query(models.User) \
  1010. .filter(models.User.email == 'admin@admin.admin') \
  1011. .one()
  1012. workspace_api = WorkspaceApi(
  1013. current_user=admin,
  1014. session=dbsession,
  1015. config=self.app_config
  1016. )
  1017. business_workspace = workspace_api.get_one(1)
  1018. content_api = ContentApi(
  1019. current_user=admin,
  1020. session=dbsession,
  1021. config=self.app_config
  1022. )
  1023. tool_folder = content_api.get_one(1, content_type=ContentType.Any)
  1024. test_thread = content_api.create(
  1025. content_type=ContentType.Thread,
  1026. workspace=business_workspace,
  1027. parent=tool_folder,
  1028. label='Test Thread',
  1029. do_save=False,
  1030. do_notify=False,
  1031. )
  1032. test_thread.description = 'Thread description'
  1033. dbsession.add(test_thread)
  1034. test_file = content_api.create(
  1035. content_type=ContentType.File,
  1036. workspace=business_workspace,
  1037. parent=tool_folder,
  1038. label='Test file',
  1039. do_save=False,
  1040. do_notify=False,
  1041. )
  1042. test_file.file_extension = '.txt'
  1043. test_file.depot_file = FileIntent(
  1044. b'Test file',
  1045. 'Test_file.txt',
  1046. 'text/plain',
  1047. )
  1048. test_page_legacy = content_api.create(
  1049. content_type=ContentType.Page,
  1050. workspace=business_workspace,
  1051. parent=tool_folder,
  1052. label='test_page',
  1053. do_save=False,
  1054. do_notify=False,
  1055. )
  1056. test_page_legacy.type = ContentType.PageLegacy
  1057. content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
  1058. test_html_document = content_api.create(
  1059. content_type=ContentType.Page,
  1060. workspace=business_workspace,
  1061. parent=tool_folder,
  1062. label='test_html_page',
  1063. do_save=False,
  1064. do_notify=False,
  1065. )
  1066. content_api.update_content(test_html_document, 'test_html_page', '<p>HTML_DOCUMENT</p>') # nopep8
  1067. dbsession.flush()
  1068. transaction.commit()
  1069. # test-itself
  1070. params = {
  1071. 'parent_id': 1,
  1072. 'show_archived': 1,
  1073. 'show_deleted': 1,
  1074. 'show_active': 1,
  1075. 'content_type': 'html-document',
  1076. }
  1077. self.testapp.authorization = (
  1078. 'Basic',
  1079. (
  1080. 'admin@admin.admin',
  1081. 'admin@admin.admin'
  1082. )
  1083. )
  1084. res = self.testapp.get(
  1085. '/api/v2/workspaces/1/contents',
  1086. status=200,
  1087. params=params,
  1088. ).json_body
  1089. assert len(res) == 2
  1090. content = res[0]
  1091. assert content['content_type'] == 'html-document'
  1092. assert content['content_id']
  1093. assert content['is_archived'] is False
  1094. assert content['is_deleted'] is False
  1095. assert content['label'] == 'test_page'
  1096. assert content['parent_id'] == 1
  1097. assert content['show_in_ui'] is True
  1098. assert content['slug'] == 'test-page'
  1099. assert content['status'] == 'open'
  1100. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1101. assert content['workspace_id'] == 1
  1102. content = res[1]
  1103. assert content['content_type'] == 'html-document'
  1104. assert content['content_id']
  1105. assert content['is_archived'] is False
  1106. assert content['is_deleted'] is False
  1107. assert content['label'] == 'test_html_page'
  1108. assert content['parent_id'] == 1
  1109. assert content['show_in_ui'] is True
  1110. assert content['slug'] == 'test-html-page'
  1111. assert content['status'] == 'open'
  1112. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1113. assert content['workspace_id'] == 1
  1114. assert res[0]['content_id'] != res[1]['content_id']
  1115. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  1116. """
  1117. Check obtain workspace folder all contents
  1118. """
  1119. params = {
  1120. 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id
  1121. 'show_archived': 1,
  1122. 'show_deleted': 1,
  1123. 'show_active': 1,
  1124. 'content_type': 'any'
  1125. }
  1126. self.testapp.authorization = (
  1127. 'Basic',
  1128. (
  1129. 'admin@admin.admin',
  1130. 'admin@admin.admin'
  1131. )
  1132. )
  1133. res = self.testapp.get(
  1134. '/api/v2/workspaces/2/contents',
  1135. status=200,
  1136. params=params,
  1137. ).json_body # nopep8
  1138. assert len(res) == 3
  1139. content = res[0]
  1140. assert content['content_type'] == 'html-document'
  1141. assert content['content_id'] == 12
  1142. assert content['is_archived'] is False
  1143. assert content['is_deleted'] is False
  1144. assert content['label'] == 'New Fruit Salad'
  1145. assert content['parent_id'] == 10
  1146. assert content['show_in_ui'] is True
  1147. assert content['slug'] == 'new-fruit-salad'
  1148. assert content['status'] == 'open'
  1149. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1150. assert content['workspace_id'] == 2
  1151. content = res[1]
  1152. assert content['content_type'] == 'html-document'
  1153. assert content['content_id'] == 13
  1154. assert content['is_archived'] is True
  1155. assert content['is_deleted'] is False
  1156. assert content['label'].startswith('Fruit Salad')
  1157. assert content['parent_id'] == 10
  1158. assert content['show_in_ui'] is True
  1159. assert content['slug'].startswith('fruit-salad')
  1160. assert content['status'] == 'open'
  1161. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1162. assert content['workspace_id'] == 2
  1163. content = res[2]
  1164. assert content['content_type'] == 'html-document'
  1165. assert content['content_id'] == 14
  1166. assert content['is_archived'] is False
  1167. assert content['is_deleted'] is True
  1168. assert content['label'].startswith('Bad Fruit Salad')
  1169. assert content['parent_id'] == 10
  1170. assert content['show_in_ui'] is True
  1171. assert content['slug'].startswith('bad-fruit-salad')
  1172. assert content['status'] == 'open'
  1173. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1174. assert content['workspace_id'] == 2
  1175. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8
  1176. """
  1177. Check obtain workspace folder active contents
  1178. """
  1179. params = {
  1180. 'parent_id': 10,
  1181. 'show_archived': 0,
  1182. 'show_deleted': 0,
  1183. 'show_active': 1,
  1184. }
  1185. self.testapp.authorization = (
  1186. 'Basic',
  1187. (
  1188. 'admin@admin.admin',
  1189. 'admin@admin.admin'
  1190. )
  1191. )
  1192. res = self.testapp.get(
  1193. '/api/v2/workspaces/2/contents',
  1194. status=200,
  1195. params=params,
  1196. ).json_body # nopep8
  1197. assert len(res) == 1
  1198. content = res[0]
  1199. assert content['content_type']
  1200. assert content['content_id'] == 12
  1201. assert content['is_archived'] is False
  1202. assert content['is_deleted'] is False
  1203. assert content['label'] == 'New Fruit Salad'
  1204. assert content['parent_id'] == 10
  1205. assert content['show_in_ui'] is True
  1206. assert content['slug'] == 'new-fruit-salad'
  1207. assert content['status'] == 'open'
  1208. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1209. assert content['workspace_id'] == 2
  1210. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8
  1211. """
  1212. Check obtain workspace folder archived contents
  1213. """
  1214. params = {
  1215. 'parent_id': 10,
  1216. 'show_archived': 1,
  1217. 'show_deleted': 0,
  1218. 'show_active': 0,
  1219. }
  1220. self.testapp.authorization = (
  1221. 'Basic',
  1222. (
  1223. 'admin@admin.admin',
  1224. 'admin@admin.admin'
  1225. )
  1226. )
  1227. res = self.testapp.get(
  1228. '/api/v2/workspaces/2/contents',
  1229. status=200,
  1230. params=params,
  1231. ).json_body # nopep8
  1232. assert len(res) == 1
  1233. content = res[0]
  1234. assert content['content_type'] == 'html-document'
  1235. assert content['content_id'] == 13
  1236. assert content['is_archived'] is True
  1237. assert content['is_deleted'] is False
  1238. assert content['label'].startswith('Fruit Salad')
  1239. assert content['parent_id'] == 10
  1240. assert content['show_in_ui'] is True
  1241. assert content['slug'].startswith('fruit-salad')
  1242. assert content['status'] == 'open'
  1243. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1244. assert content['workspace_id'] == 2
  1245. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8
  1246. """
  1247. Check obtain workspace folder deleted contents
  1248. """
  1249. params = {
  1250. 'parent_id': 10,
  1251. 'show_archived': 0,
  1252. 'show_deleted': 1,
  1253. 'show_active': 0,
  1254. }
  1255. self.testapp.authorization = (
  1256. 'Basic',
  1257. (
  1258. 'admin@admin.admin',
  1259. 'admin@admin.admin'
  1260. )
  1261. )
  1262. res = self.testapp.get(
  1263. '/api/v2/workspaces/2/contents',
  1264. status=200,
  1265. params=params,
  1266. ).json_body # nopep8
  1267. assert len(res) == 1
  1268. content = res[0]
  1269. assert content['content_type'] == 'html-document'
  1270. assert content['content_id'] == 14
  1271. assert content['is_archived'] is False
  1272. assert content['is_deleted'] is True
  1273. assert content['label'].startswith('Bad Fruit Salad')
  1274. assert content['parent_id'] == 10
  1275. assert content['show_in_ui'] is True
  1276. assert content['slug'].startswith('bad-fruit-salad')
  1277. assert content['status'] == 'open'
  1278. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1279. assert content['workspace_id'] == 2
  1280. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8
  1281. """
  1282. Check obtain workspace folder content who does not match any type
  1283. (archived, deleted, active) result should be empty list.
  1284. """
  1285. params = {
  1286. 'parent_id': 10,
  1287. 'show_archived': 0,
  1288. 'show_deleted': 0,
  1289. 'show_active': 0,
  1290. }
  1291. self.testapp.authorization = (
  1292. 'Basic',
  1293. (
  1294. 'admin@admin.admin',
  1295. 'admin@admin.admin'
  1296. )
  1297. )
  1298. res = self.testapp.get(
  1299. '/api/v2/workspaces/2/contents',
  1300. status=200,
  1301. params=params,
  1302. ).json_body # nopep8
  1303. # TODO - G.M - 30-05-2018 - Check this test
  1304. assert res == []
  1305. # Error case
  1306. def test_api__get_workspace_content__err_400__unallowed_user(self):
  1307. """
  1308. Check obtain workspace content list with an unreachable workspace for
  1309. user
  1310. """
  1311. self.testapp.authorization = (
  1312. 'Basic',
  1313. (
  1314. 'lawrence-not-real-email@fsf.local',
  1315. 'foobarbaz'
  1316. )
  1317. )
  1318. res = self.testapp.get('/api/v2/workspaces/3/contents', status=400)
  1319. assert isinstance(res.json, dict)
  1320. assert 'code' in res.json.keys()
  1321. assert 'message' in res.json.keys()
  1322. assert 'details' in res.json.keys()
  1323. def test_api__get_workspace_content__err_401__unregistered_user(self):
  1324. """
  1325. Check obtain workspace content list with an unregistered user
  1326. """
  1327. self.testapp.authorization = (
  1328. 'Basic',
  1329. (
  1330. 'john@doe.doe',
  1331. 'lapin'
  1332. )
  1333. )
  1334. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  1335. assert isinstance(res.json, dict)
  1336. assert 'code' in res.json.keys()
  1337. assert 'message' in res.json.keys()
  1338. assert 'details' in res.json.keys()
  1339. def test_api__get_workspace_content__err_400__workspace_does_not_exist(self): # nopep8
  1340. """
  1341. Check obtain workspace contents list with an existing user but
  1342. an unexisting workspace
  1343. """
  1344. self.testapp.authorization = (
  1345. 'Basic',
  1346. (
  1347. 'admin@admin.admin',
  1348. 'admin@admin.admin'
  1349. )
  1350. )
  1351. res = self.testapp.get('/api/v2/workspaces/5/contents', status=400)
  1352. assert isinstance(res.json, dict)
  1353. assert 'code' in res.json.keys()
  1354. assert 'message' in res.json.keys()
  1355. assert 'details' in res.json.keys()
  1356. def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8
  1357. """
  1358. Create generic content
  1359. """
  1360. self.testapp.authorization = (
  1361. 'Basic',
  1362. (
  1363. 'admin@admin.admin',
  1364. 'admin@admin.admin'
  1365. )
  1366. )
  1367. params = {
  1368. 'parent_id': None,
  1369. 'label': 'GenericCreatedContent',
  1370. 'content_type': 'markdownpage',
  1371. }
  1372. res = self.testapp.post_json(
  1373. '/api/v2/workspaces/1/contents',
  1374. params=params,
  1375. status=200
  1376. )
  1377. assert res
  1378. assert res.json_body
  1379. assert res.json_body['status'] == 'open'
  1380. assert res.json_body['content_id']
  1381. assert res.json_body['content_type'] == 'markdownpage'
  1382. assert res.json_body['is_archived'] is False
  1383. assert res.json_body['is_deleted'] is False
  1384. assert res.json_body['workspace_id'] == 1
  1385. assert res.json_body['slug'] == 'genericcreatedcontent'
  1386. assert res.json_body['parent_id'] is None
  1387. assert res.json_body['show_in_ui'] is True
  1388. assert res.json_body['sub_content_types']
  1389. params_active = {
  1390. 'parent_id': 0,
  1391. 'show_archived': 0,
  1392. 'show_deleted': 0,
  1393. 'show_active': 1,
  1394. }
  1395. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1396. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1397. assert res.json_body in active_contents
  1398. def test_api__post_content_create_generic_content__ok_200__no_parent_id_param(self) -> None: # nopep8
  1399. """
  1400. Create generic content
  1401. """
  1402. self.testapp.authorization = (
  1403. 'Basic',
  1404. (
  1405. 'admin@admin.admin',
  1406. 'admin@admin.admin'
  1407. )
  1408. )
  1409. params = {
  1410. 'label': 'GenericCreatedContent',
  1411. 'content_type': 'markdownpage',
  1412. }
  1413. res = self.testapp.post_json(
  1414. '/api/v2/workspaces/1/contents',
  1415. params=params,
  1416. status=200
  1417. )
  1418. assert res
  1419. assert res.json_body
  1420. assert res.json_body['status'] == 'open'
  1421. assert res.json_body['content_id']
  1422. assert res.json_body['content_type'] == 'markdownpage'
  1423. assert res.json_body['is_archived'] is False
  1424. assert res.json_body['is_deleted'] is False
  1425. assert res.json_body['workspace_id'] == 1
  1426. assert res.json_body['slug'] == 'genericcreatedcontent'
  1427. assert res.json_body['parent_id'] is None
  1428. assert res.json_body['show_in_ui'] is True
  1429. assert res.json_body['sub_content_types']
  1430. params_active = {
  1431. 'parent_id': 0,
  1432. 'show_archived': 0,
  1433. 'show_deleted': 0,
  1434. 'show_active': 1,
  1435. }
  1436. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1437. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1438. assert res.json_body in active_contents
  1439. def test_api__post_content_create_generic_content__err_400__parent_id_0(self) -> None: # nopep8
  1440. """
  1441. Create generic content
  1442. """
  1443. self.testapp.authorization = (
  1444. 'Basic',
  1445. (
  1446. 'admin@admin.admin',
  1447. 'admin@admin.admin'
  1448. )
  1449. )
  1450. params = {
  1451. 'parent_id': 0,
  1452. 'label': 'GenericCreatedContent',
  1453. 'content_type': 'markdownpage',
  1454. }
  1455. res = self.testapp.post_json(
  1456. '/api/v2/workspaces/1/contents',
  1457. params=params,
  1458. status=400
  1459. )
  1460. def test_api__post_content_create_generic_content__ok_200__in_folder(self) -> None: # nopep8
  1461. """
  1462. Create generic content in folder
  1463. """
  1464. self.testapp.authorization = (
  1465. 'Basic',
  1466. (
  1467. 'admin@admin.admin',
  1468. 'admin@admin.admin'
  1469. )
  1470. )
  1471. params = {
  1472. 'label': 'GenericCreatedContent',
  1473. 'content_type': 'markdownpage',
  1474. 'parent_id': 10,
  1475. }
  1476. res = self.testapp.post_json(
  1477. '/api/v2/workspaces/1/contents',
  1478. params=params,
  1479. status=200
  1480. )
  1481. assert res
  1482. assert res.json_body
  1483. assert res.json_body['status'] == 'open'
  1484. assert res.json_body['content_id']
  1485. assert res.json_body['content_type'] == 'markdownpage'
  1486. assert res.json_body['is_archived'] is False
  1487. assert res.json_body['is_deleted'] is False
  1488. assert res.json_body['workspace_id'] == 1
  1489. assert res.json_body['slug'] == 'genericcreatedcontent'
  1490. assert res.json_body['parent_id'] == 10
  1491. assert res.json_body['show_in_ui'] is True
  1492. assert res.json_body['sub_content_types']
  1493. params_active = {
  1494. 'parent_id': 10,
  1495. 'show_archived': 0,
  1496. 'show_deleted': 0,
  1497. 'show_active': 1,
  1498. }
  1499. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1500. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1501. assert res.json_body in active_contents
  1502. def test_api__post_content_create_generic_content__err_400__empty_label(self) -> None: # nopep8
  1503. """
  1504. Create generic content
  1505. """
  1506. self.testapp.authorization = (
  1507. 'Basic',
  1508. (
  1509. 'admin@admin.admin',
  1510. 'admin@admin.admin'
  1511. )
  1512. )
  1513. params = {
  1514. 'label': '',
  1515. 'content_type': 'markdownpage',
  1516. }
  1517. res = self.testapp.post_json(
  1518. '/api/v2/workspaces/1/contents',
  1519. params=params,
  1520. status=400
  1521. )
  1522. def test_api__post_content_create_generic_content__err_400__wrong_content_type(self) -> None: # nopep8
  1523. """
  1524. Create generic content
  1525. """
  1526. self.testapp.authorization = (
  1527. 'Basic',
  1528. (
  1529. 'admin@admin.admin',
  1530. 'admin@admin.admin'
  1531. )
  1532. )
  1533. params = {
  1534. 'label': 'GenericCreatedContent',
  1535. 'content_type': 'unexistent-content-type',
  1536. }
  1537. res = self.testapp.post_json(
  1538. '/api/v2/workspaces/1/contents',
  1539. params=params,
  1540. status=400,
  1541. )
  1542. def test_api_put_move_content__ok_200__nominal_case(self):
  1543. """
  1544. Move content
  1545. move Apple_Pie (content_id: 8)
  1546. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1547. of workspace Recipes.
  1548. """
  1549. self.testapp.authorization = (
  1550. 'Basic',
  1551. (
  1552. 'admin@admin.admin',
  1553. 'admin@admin.admin'
  1554. )
  1555. )
  1556. params = {
  1557. 'new_parent_id': '4', # Salads
  1558. 'new_workspace_id': '2',
  1559. }
  1560. params_folder1 = {
  1561. 'parent_id': 3,
  1562. 'show_archived': 0,
  1563. 'show_deleted': 0,
  1564. 'show_active': 1,
  1565. }
  1566. params_folder2 = {
  1567. 'parent_id': 4,
  1568. 'show_archived': 0,
  1569. 'show_deleted': 0,
  1570. 'show_active': 1,
  1571. }
  1572. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1573. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1574. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1575. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1576. # TODO - G.M - 2018-06-163 - Check content
  1577. res = self.testapp.put_json(
  1578. '/api/v2/workspaces/2/contents/8/move',
  1579. params=params,
  1580. status=200
  1581. )
  1582. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1583. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1584. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1585. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1586. assert res.json_body
  1587. assert res.json_body['parent_id'] == 4
  1588. assert res.json_body['content_id'] == 8
  1589. assert res.json_body['workspace_id'] == 2
  1590. def test_api_put_move_content__ok_200__to_root(self):
  1591. """
  1592. Move content
  1593. move Apple_Pie (content_id: 8)
  1594. from Desserts folder(content_id: 3) to root (content_id: 0)
  1595. of workspace Recipes.
  1596. """
  1597. self.testapp.authorization = (
  1598. 'Basic',
  1599. (
  1600. 'admin@admin.admin',
  1601. 'admin@admin.admin'
  1602. )
  1603. )
  1604. params = {
  1605. 'new_parent_id': None, # root
  1606. 'new_workspace_id': 2,
  1607. }
  1608. params_folder1 = {
  1609. 'parent_id': 3,
  1610. 'show_archived': 0,
  1611. 'show_deleted': 0,
  1612. 'show_active': 1,
  1613. }
  1614. params_folder2 = {
  1615. 'parent_id': 0,
  1616. 'show_archived': 0,
  1617. 'show_deleted': 0,
  1618. 'show_active': 1,
  1619. }
  1620. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1621. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1622. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1623. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1624. # TODO - G.M - 2018-06-163 - Check content
  1625. res = self.testapp.put_json(
  1626. '/api/v2/workspaces/2/contents/8/move',
  1627. params=params,
  1628. status=200
  1629. )
  1630. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1631. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1632. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1633. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1634. assert res.json_body
  1635. assert res.json_body['parent_id'] is None
  1636. assert res.json_body['content_id'] == 8
  1637. assert res.json_body['workspace_id'] == 2
  1638. def test_api_put_move_content__ok_200__with_workspace_id(self):
  1639. """
  1640. Move content
  1641. move Apple_Pie (content_id: 8)
  1642. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1643. of workspace Recipes.
  1644. """
  1645. self.testapp.authorization = (
  1646. 'Basic',
  1647. (
  1648. 'admin@admin.admin',
  1649. 'admin@admin.admin'
  1650. )
  1651. )
  1652. params = {
  1653. 'new_parent_id': '4', # Salads
  1654. 'new_workspace_id': '2',
  1655. }
  1656. params_folder1 = {
  1657. 'parent_id': 3,
  1658. 'show_archived': 0,
  1659. 'show_deleted': 0,
  1660. 'show_active': 1,
  1661. }
  1662. params_folder2 = {
  1663. 'parent_id': 4,
  1664. 'show_archived': 0,
  1665. 'show_deleted': 0,
  1666. 'show_active': 1,
  1667. }
  1668. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1669. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1670. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1671. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1672. # TODO - G.M - 2018-06-163 - Check content
  1673. res = self.testapp.put_json(
  1674. '/api/v2/workspaces/2/contents/8/move',
  1675. params=params,
  1676. status=200
  1677. )
  1678. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1679. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1680. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1681. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1682. assert res.json_body
  1683. assert res.json_body['parent_id'] == 4
  1684. assert res.json_body['content_id'] == 8
  1685. assert res.json_body['workspace_id'] == 2
  1686. def test_api_put_move_content__ok_200__to_another_workspace(self):
  1687. """
  1688. Move content
  1689. move Apple_Pie (content_id: 8)
  1690. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  1691. of workspace Business.
  1692. """
  1693. self.testapp.authorization = (
  1694. 'Basic',
  1695. (
  1696. 'admin@admin.admin',
  1697. 'admin@admin.admin'
  1698. )
  1699. )
  1700. params = {
  1701. 'new_parent_id': '2', # Menus
  1702. 'new_workspace_id': '1',
  1703. }
  1704. params_folder1 = {
  1705. 'parent_id': 3,
  1706. 'show_archived': 0,
  1707. 'show_deleted': 0,
  1708. 'show_active': 1,
  1709. }
  1710. params_folder2 = {
  1711. 'parent_id': 2,
  1712. 'show_archived': 0,
  1713. 'show_deleted': 0,
  1714. 'show_active': 1,
  1715. }
  1716. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1717. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1718. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1719. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1720. # TODO - G.M - 2018-06-163 - Check content
  1721. res = self.testapp.put_json(
  1722. '/api/v2/workspaces/2/contents/8/move',
  1723. params=params,
  1724. status=200
  1725. )
  1726. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1727. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1728. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1729. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1730. assert res.json_body
  1731. assert res.json_body['parent_id'] == 2
  1732. assert res.json_body['content_id'] == 8
  1733. assert res.json_body['workspace_id'] == 1
  1734. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  1735. """
  1736. Move content
  1737. move Apple_Pie (content_id: 8)
  1738. from Desserts folder(content_id: 3) to root (content_id: 0)
  1739. of workspace Business.
  1740. """
  1741. self.testapp.authorization = (
  1742. 'Basic',
  1743. (
  1744. 'admin@admin.admin',
  1745. 'admin@admin.admin'
  1746. )
  1747. )
  1748. params = {
  1749. 'new_parent_id': None, # root
  1750. 'new_workspace_id': '1',
  1751. }
  1752. params_folder1 = {
  1753. 'parent_id': 3,
  1754. 'show_archived': 0,
  1755. 'show_deleted': 0,
  1756. 'show_active': 1,
  1757. }
  1758. params_folder2 = {
  1759. 'parent_id': 0,
  1760. 'show_archived': 0,
  1761. 'show_deleted': 0,
  1762. 'show_active': 1,
  1763. }
  1764. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1765. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1766. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1767. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1768. # TODO - G.M - 2018-06-163 - Check content
  1769. res = self.testapp.put_json(
  1770. '/api/v2/workspaces/2/contents/8/move',
  1771. params=params,
  1772. status=200
  1773. )
  1774. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1775. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1776. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1777. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1778. assert res.json_body
  1779. assert res.json_body['parent_id'] is None
  1780. assert res.json_body['content_id'] == 8
  1781. assert res.json_body['workspace_id'] == 1
  1782. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  1783. """
  1784. Move content
  1785. move Apple_Pie (content_id: 8)
  1786. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1787. of workspace Recipes.
  1788. Workspace_id of parent_id don't match with workspace_id of workspace
  1789. """
  1790. self.testapp.authorization = (
  1791. 'Basic',
  1792. (
  1793. 'admin@admin.admin',
  1794. 'admin@admin.admin'
  1795. )
  1796. )
  1797. params = {
  1798. 'new_parent_id': '4', # Salads
  1799. 'new_workspace_id': '1',
  1800. }
  1801. params_folder1 = {
  1802. 'parent_id': 3,
  1803. 'show_archived': 0,
  1804. 'show_deleted': 0,
  1805. 'show_active': 1,
  1806. }
  1807. params_folder2 = {
  1808. 'parent_id': 4,
  1809. 'show_archived': 0,
  1810. 'show_deleted': 0,
  1811. 'show_active': 1,
  1812. }
  1813. res = self.testapp.put_json(
  1814. '/api/v2/workspaces/2/contents/8/move',
  1815. params=params,
  1816. status=400,
  1817. )
  1818. def test_api_put_delete_content__ok_200__nominal_case(self):
  1819. """
  1820. delete content
  1821. delete Apple_pie ( content_id: 8, parent_id: 3)
  1822. """
  1823. self.testapp.authorization = (
  1824. 'Basic',
  1825. (
  1826. 'admin@admin.admin',
  1827. 'admin@admin.admin'
  1828. )
  1829. )
  1830. params_active = {
  1831. 'parent_id': 3,
  1832. 'show_archived': 0,
  1833. 'show_deleted': 0,
  1834. 'show_active': 1,
  1835. }
  1836. params_deleted = {
  1837. 'parent_id': 3,
  1838. 'show_archived': 0,
  1839. 'show_deleted': 1,
  1840. 'show_active': 0,
  1841. }
  1842. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1843. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1844. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1845. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1846. # TODO - G.M - 2018-06-163 - Check content
  1847. res = self.testapp.put_json(
  1848. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1849. '/api/v2/workspaces/2/contents/8/delete',
  1850. status=204
  1851. )
  1852. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1853. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1854. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1855. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1856. def test_api_put_archive_content__ok_200__nominal_case(self):
  1857. """
  1858. archive content
  1859. archive Apple_pie ( content_id: 8, parent_id: 3)
  1860. """
  1861. self.testapp.authorization = (
  1862. 'Basic',
  1863. (
  1864. 'admin@admin.admin',
  1865. 'admin@admin.admin'
  1866. )
  1867. )
  1868. params_active = {
  1869. 'parent_id': 3,
  1870. 'show_archived': 0,
  1871. 'show_deleted': 0,
  1872. 'show_active': 1,
  1873. }
  1874. params_archived = {
  1875. 'parent_id': 3,
  1876. 'show_archived': 1,
  1877. 'show_deleted': 0,
  1878. 'show_active': 0,
  1879. }
  1880. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1881. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1882. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1883. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1884. res = self.testapp.put_json(
  1885. '/api/v2/workspaces/2/contents/8/archive',
  1886. status=204
  1887. )
  1888. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1889. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1890. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1891. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1892. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1893. """
  1894. Undelete content
  1895. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1896. """
  1897. self.testapp.authorization = (
  1898. 'Basic',
  1899. (
  1900. 'bob@fsf.local',
  1901. 'foobarbaz'
  1902. )
  1903. )
  1904. params_active = {
  1905. 'parent_id': 10,
  1906. 'show_archived': 0,
  1907. 'show_deleted': 0,
  1908. 'show_active': 1,
  1909. }
  1910. params_deleted = {
  1911. 'parent_id': 10,
  1912. 'show_archived': 0,
  1913. 'show_deleted': 1,
  1914. 'show_active': 0,
  1915. }
  1916. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1917. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1918. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1919. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1920. res = self.testapp.put_json(
  1921. '/api/v2/workspaces/2/contents/14/undelete',
  1922. status=204
  1923. )
  1924. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1925. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1926. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1927. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1928. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1929. """
  1930. unarchive content,
  1931. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1932. """
  1933. self.testapp.authorization = (
  1934. 'Basic',
  1935. (
  1936. 'bob@fsf.local',
  1937. 'foobarbaz'
  1938. )
  1939. )
  1940. params_active = {
  1941. 'parent_id': 10,
  1942. 'show_archived': 0,
  1943. 'show_deleted': 0,
  1944. 'show_active': 1,
  1945. }
  1946. params_archived = {
  1947. 'parent_id': 10,
  1948. 'show_archived': 1,
  1949. 'show_deleted': 0,
  1950. 'show_active': 0,
  1951. }
  1952. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1953. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1954. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  1955. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  1956. res = self.testapp.put_json(
  1957. '/api/v2/workspaces/2/contents/13/unarchive',
  1958. status=204
  1959. )
  1960. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1961. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1962. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  1963. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8