test_workspaces.py 75KB

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