test_workspaces.py 79KB

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