test_workspaces.py 78KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125
  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 workspace['is_deleted'] is False
  40. assert len(workspace['sidebar_entries']) == 5
  41. # TODO - G.M - 2018-08-02 - Better test for sidebar entry, make it
  42. # not fixed on active application/content-file
  43. sidebar_entry = workspace['sidebar_entries'][0]
  44. assert sidebar_entry['slug'] == 'dashboard'
  45. assert sidebar_entry['label'] == 'Dashboard'
  46. assert sidebar_entry['route'] == '/#/workspaces/1/dashboard' # nopep8
  47. assert sidebar_entry['hexcolor'] == "#252525"
  48. assert sidebar_entry['fa_icon'] == "signal"
  49. sidebar_entry = workspace['sidebar_entries'][1]
  50. assert sidebar_entry['slug'] == 'contents/all'
  51. assert sidebar_entry['label'] == 'All Contents'
  52. assert sidebar_entry['route'] == "/#/workspaces/1/contents" # nopep8
  53. assert sidebar_entry['hexcolor'] == "#fdfdfd"
  54. assert sidebar_entry['fa_icon'] == "th"
  55. sidebar_entry = workspace['sidebar_entries'][2]
  56. assert sidebar_entry['slug'] == 'contents/html-document'
  57. assert sidebar_entry['label'] == 'Text Documents'
  58. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=html-document' # nopep8
  59. assert sidebar_entry['hexcolor'] == "#3f52e3"
  60. assert sidebar_entry['fa_icon'] == "file-text-o"
  61. sidebar_entry = workspace['sidebar_entries'][3]
  62. assert sidebar_entry['slug'] == 'contents/file'
  63. assert sidebar_entry['label'] == 'Files'
  64. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file" # nopep8
  65. assert sidebar_entry['hexcolor'] == "#FF9900"
  66. assert sidebar_entry['fa_icon'] == "paperclip"
  67. sidebar_entry = workspace['sidebar_entries'][4]
  68. assert sidebar_entry['slug'] == 'contents/thread'
  69. assert sidebar_entry['label'] == 'Threads'
  70. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread" # nopep8
  71. assert sidebar_entry['hexcolor'] == "#ad4cf9"
  72. assert sidebar_entry['fa_icon'] == "comments-o"
  73. def test_api__update_workspace__ok_200__nominal_case(self) -> None:
  74. """
  75. Test update workspace
  76. """
  77. self.testapp.authorization = (
  78. 'Basic',
  79. (
  80. 'admin@admin.admin',
  81. 'admin@admin.admin'
  82. )
  83. )
  84. params = {
  85. 'label': 'superworkspace',
  86. 'description': 'mysuperdescription'
  87. }
  88. # Before
  89. res = self.testapp.get(
  90. '/api/v2/workspaces/1',
  91. status=200
  92. )
  93. assert res.json_body
  94. workspace = res.json_body
  95. assert workspace['workspace_id'] == 1
  96. assert workspace['slug'] == 'business'
  97. assert workspace['label'] == 'Business'
  98. assert workspace['description'] == 'All importants documents'
  99. assert workspace['is_deleted'] is False
  100. assert len(workspace['sidebar_entries']) == 5
  101. # modify workspace
  102. res = self.testapp.put_json(
  103. '/api/v2/workspaces/1',
  104. status=200,
  105. params=params,
  106. )
  107. assert res.json_body
  108. workspace = res.json_body
  109. assert workspace['workspace_id'] == 1
  110. assert workspace['slug'] == 'superworkspace'
  111. assert workspace['label'] == 'superworkspace'
  112. assert workspace['description'] == 'mysuperdescription'
  113. assert workspace['is_deleted'] is False
  114. assert len(workspace['sidebar_entries']) == 5
  115. # after
  116. res = self.testapp.get(
  117. '/api/v2/workspaces/1',
  118. status=200
  119. )
  120. assert res.json_body
  121. workspace = res.json_body
  122. assert workspace['workspace_id'] == 1
  123. assert workspace['slug'] == 'superworkspace'
  124. assert workspace['label'] == 'superworkspace'
  125. assert workspace['description'] == 'mysuperdescription'
  126. assert workspace['is_deleted'] is False
  127. assert len(workspace['sidebar_entries']) == 5
  128. def test_api__update_workspace__err_400__empty_label(self) -> None:
  129. """
  130. Test update workspace with empty label
  131. """
  132. self.testapp.authorization = (
  133. 'Basic',
  134. (
  135. 'admin@admin.admin',
  136. 'admin@admin.admin'
  137. )
  138. )
  139. params = {
  140. 'label': '',
  141. 'description': 'mysuperdescription'
  142. }
  143. res = self.testapp.put_json(
  144. '/api/v2/workspaces/1',
  145. status=400,
  146. params=params,
  147. )
  148. def test_api__create_workspace__ok_200__nominal_case(self) -> None:
  149. """
  150. Test create workspace
  151. """
  152. self.testapp.authorization = (
  153. 'Basic',
  154. (
  155. 'admin@admin.admin',
  156. 'admin@admin.admin'
  157. )
  158. )
  159. params = {
  160. 'label': 'superworkspace',
  161. 'description': 'mysuperdescription'
  162. }
  163. res = self.testapp.post_json(
  164. '/api/v2/workspaces',
  165. status=200,
  166. params=params,
  167. )
  168. assert res.json_body
  169. workspace = res.json_body
  170. workspace_id = res.json_body['workspace_id']
  171. res = self.testapp.get(
  172. '/api/v2/workspaces/{}'.format(workspace_id),
  173. status=200
  174. )
  175. workspace_2 = res.json_body
  176. assert workspace == workspace_2
  177. def test_api__create_workspace__err_400__empty_label(self) -> None:
  178. """
  179. Test create workspace with empty label
  180. """
  181. self.testapp.authorization = (
  182. 'Basic',
  183. (
  184. 'admin@admin.admin',
  185. 'admin@admin.admin'
  186. )
  187. )
  188. params = {
  189. 'label': '',
  190. 'description': 'mysuperdescription'
  191. }
  192. res = self.testapp.post_json(
  193. '/api/v2/workspaces',
  194. status=400,
  195. params=params,
  196. )
  197. def test_api__get_workspace__err_400__unallowed_user(self) -> None:
  198. """
  199. Check obtain workspace unreachable for user
  200. """
  201. self.testapp.authorization = (
  202. 'Basic',
  203. (
  204. 'lawrence-not-real-email@fsf.local',
  205. 'foobarbaz'
  206. )
  207. )
  208. res = self.testapp.get('/api/v2/workspaces/1', status=400)
  209. assert isinstance(res.json, dict)
  210. assert 'code' in res.json.keys()
  211. assert 'message' in res.json.keys()
  212. assert 'details' in res.json.keys()
  213. def test_api__get_workspace__err_401__unregistered_user(self) -> None:
  214. """
  215. Check obtain workspace without registered user.
  216. """
  217. self.testapp.authorization = (
  218. 'Basic',
  219. (
  220. 'john@doe.doe',
  221. 'lapin'
  222. )
  223. )
  224. res = self.testapp.get('/api/v2/workspaces/1', status=401)
  225. assert isinstance(res.json, dict)
  226. assert 'code' in res.json.keys()
  227. assert 'message' in res.json.keys()
  228. assert 'details' in res.json.keys()
  229. def test_api__get_workspace__err_400__workspace_does_not_exist(self) -> None: # nopep8
  230. """
  231. Check obtain workspace who does not exist with an existing user.
  232. """
  233. self.testapp.authorization = (
  234. 'Basic',
  235. (
  236. 'admin@admin.admin',
  237. 'admin@admin.admin'
  238. )
  239. )
  240. res = self.testapp.get('/api/v2/workspaces/5', status=400)
  241. assert isinstance(res.json, dict)
  242. assert 'code' in res.json.keys()
  243. assert 'message' in res.json.keys()
  244. assert 'details' in res.json.keys()
  245. class TestWorkspaceMembersEndpoint(FunctionalTest):
  246. """
  247. Tests for /api/v2/workspaces/{workspace_id}/members endpoint
  248. """
  249. fixtures = [BaseFixture, ContentFixtures]
  250. def test_api__get_workspace_members__ok_200__nominal_case(self):
  251. """
  252. Check obtain workspace members list with a reachable workspace for user
  253. """
  254. self.testapp.authorization = (
  255. 'Basic',
  256. (
  257. 'admin@admin.admin',
  258. 'admin@admin.admin'
  259. )
  260. )
  261. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  262. assert len(res) == 1
  263. user_role = res[0]
  264. assert user_role['role'] == 'workspace-manager'
  265. assert user_role['user_id'] == 1
  266. assert user_role['workspace_id'] == 1
  267. assert user_role['workspace']['workspace_id'] == 1
  268. assert user_role['workspace']['label'] == 'Business'
  269. assert user_role['workspace']['slug'] == 'business'
  270. assert user_role['user']['public_name'] == 'Global manager'
  271. assert user_role['user']['user_id'] == 1
  272. assert user_role['is_active'] is True
  273. # TODO - G.M - 24-05-2018 - [Avatar] Replace
  274. # by correct value when avatar feature will be enabled
  275. assert user_role['user']['avatar_url'] is None
  276. def test_api__get_workspace_members__err_400__unallowed_user(self):
  277. """
  278. Check obtain workspace members list with an unreachable workspace for
  279. user
  280. """
  281. self.testapp.authorization = (
  282. 'Basic',
  283. (
  284. 'lawrence-not-real-email@fsf.local',
  285. 'foobarbaz'
  286. )
  287. )
  288. res = self.testapp.get('/api/v2/workspaces/3/members', status=400)
  289. assert isinstance(res.json, dict)
  290. assert 'code' in res.json.keys()
  291. assert 'message' in res.json.keys()
  292. assert 'details' in res.json.keys()
  293. def test_api__get_workspace_members__err_401__unregistered_user(self):
  294. """
  295. Check obtain workspace members list with an unregistered user
  296. """
  297. self.testapp.authorization = (
  298. 'Basic',
  299. (
  300. 'john@doe.doe',
  301. 'lapin'
  302. )
  303. )
  304. res = self.testapp.get('/api/v2/workspaces/1/members', status=401)
  305. assert isinstance(res.json, dict)
  306. assert 'code' in res.json.keys()
  307. assert 'message' in res.json.keys()
  308. assert 'details' in res.json.keys()
  309. def test_api__get_workspace_members__err_400__workspace_does_not_exist(self): # nopep8
  310. """
  311. Check obtain workspace members list with an existing user but
  312. an unexisting workspace
  313. """
  314. self.testapp.authorization = (
  315. 'Basic',
  316. (
  317. 'admin@admin.admin',
  318. 'admin@admin.admin'
  319. )
  320. )
  321. res = self.testapp.get('/api/v2/workspaces/5/members', status=400)
  322. assert isinstance(res.json, dict)
  323. assert 'code' in res.json.keys()
  324. assert 'message' in res.json.keys()
  325. assert 'details' in res.json.keys()
  326. def test_api__create_workspace_member_role__ok_200__user_id(self):
  327. """
  328. Create workspace member role
  329. :return:
  330. """
  331. self.testapp.authorization = (
  332. 'Basic',
  333. (
  334. 'admin@admin.admin',
  335. 'admin@admin.admin'
  336. )
  337. )
  338. # create workspace role
  339. params = {
  340. 'user_id': 2,
  341. 'user_email_or_public_name': None,
  342. 'role': 'content-manager',
  343. }
  344. res = self.testapp.post_json(
  345. '/api/v2/workspaces/1/members',
  346. status=200,
  347. params=params,
  348. )
  349. user_role_found = res.json_body
  350. assert user_role_found['role'] == 'content-manager'
  351. assert user_role_found['user_id'] == 2
  352. assert user_role_found['workspace_id'] == 1
  353. assert user_role_found['newly_created'] is False
  354. assert user_role_found['email_sent'] is False
  355. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  356. assert len(res) == 2
  357. user_role = res[0]
  358. assert user_role['role'] == 'workspace-manager'
  359. assert user_role['user_id'] == 1
  360. assert user_role['workspace_id'] == 1
  361. user_role = res[1]
  362. assert user_role_found['role'] == user_role['role']
  363. assert user_role_found['user_id'] == user_role['user_id']
  364. assert user_role_found['workspace_id'] == user_role['workspace_id']
  365. def test_api__create_workspace_member_role__ok_200__user_email(self):
  366. """
  367. Create workspace member role
  368. :return:
  369. """
  370. self.testapp.authorization = (
  371. 'Basic',
  372. (
  373. 'admin@admin.admin',
  374. 'admin@admin.admin'
  375. )
  376. )
  377. # create workspace role
  378. params = {
  379. 'user_id': None,
  380. 'user_email_or_public_name': 'lawrence-not-real-email@fsf.local',
  381. 'role': 'content-manager',
  382. }
  383. res = self.testapp.post_json(
  384. '/api/v2/workspaces/1/members',
  385. status=200,
  386. params=params,
  387. )
  388. user_role_found = res.json_body
  389. assert user_role_found['role'] == 'content-manager'
  390. assert user_role_found['user_id'] == 2
  391. assert user_role_found['workspace_id'] == 1
  392. assert user_role_found['newly_created'] is False
  393. assert user_role_found['email_sent'] is False
  394. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  395. assert len(res) == 2
  396. user_role = res[0]
  397. assert user_role['role'] == 'workspace-manager'
  398. assert user_role['user_id'] == 1
  399. assert user_role['workspace_id'] == 1
  400. user_role = res[1]
  401. assert user_role_found['role'] == user_role['role']
  402. assert user_role_found['user_id'] == user_role['user_id']
  403. assert user_role_found['workspace_id'] == user_role['workspace_id']
  404. def test_api__create_workspace_member_role__ok_200__user_public_name(self):
  405. """
  406. Create workspace member role
  407. :return:
  408. """
  409. self.testapp.authorization = (
  410. 'Basic',
  411. (
  412. 'admin@admin.admin',
  413. 'admin@admin.admin'
  414. )
  415. )
  416. # create workspace role
  417. params = {
  418. 'user_id': None,
  419. 'user_email_or_public_name': 'Lawrence L.',
  420. 'role': 'content-manager',
  421. }
  422. res = self.testapp.post_json(
  423. '/api/v2/workspaces/1/members',
  424. status=200,
  425. params=params,
  426. )
  427. user_role_found = res.json_body
  428. assert user_role_found['role'] == 'content-manager'
  429. assert user_role_found['user_id'] == 2
  430. assert user_role_found['workspace_id'] == 1
  431. assert user_role_found['newly_created'] is False
  432. assert user_role_found['email_sent'] is False
  433. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  434. assert len(res) == 2
  435. user_role = res[0]
  436. assert user_role['role'] == 'workspace-manager'
  437. assert user_role['user_id'] == 1
  438. assert user_role['workspace_id'] == 1
  439. user_role = res[1]
  440. assert user_role_found['role'] == user_role['role']
  441. assert user_role_found['user_id'] == user_role['user_id']
  442. assert user_role_found['workspace_id'] == user_role['workspace_id']
  443. def test_api__create_workspace_member_role__err_400__nothing(self):
  444. """
  445. Create workspace member role
  446. :return:
  447. """
  448. self.testapp.authorization = (
  449. 'Basic',
  450. (
  451. 'admin@admin.admin',
  452. 'admin@admin.admin'
  453. )
  454. )
  455. # create workspace role
  456. params = {
  457. 'user_id': None,
  458. 'user_email_or_public_name': None,
  459. 'role': 'content-manager',
  460. }
  461. res = self.testapp.post_json(
  462. '/api/v2/workspaces/1/members',
  463. status=400,
  464. params=params,
  465. )
  466. def test_api__create_workspace_member_role__err_400__wrong_user_id(self):
  467. """
  468. Create workspace member role
  469. :return:
  470. """
  471. self.testapp.authorization = (
  472. 'Basic',
  473. (
  474. 'admin@admin.admin',
  475. 'admin@admin.admin'
  476. )
  477. )
  478. # create workspace role
  479. params = {
  480. 'user_id': 47,
  481. 'user_email_or_public_name': None,
  482. 'role': 'content-manager',
  483. }
  484. res = self.testapp.post_json(
  485. '/api/v2/workspaces/1/members',
  486. status=400,
  487. params=params,
  488. )
  489. def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8
  490. """
  491. Create workspace member role
  492. :return:
  493. """
  494. self.testapp.authorization = (
  495. 'Basic',
  496. (
  497. 'admin@admin.admin',
  498. 'admin@admin.admin'
  499. )
  500. )
  501. # create workspace role
  502. params = {
  503. 'user_id': None,
  504. 'user_email_or_public_name': 'nothing@nothing.nothing',
  505. 'role': 'content-manager',
  506. }
  507. res = self.testapp.post_json(
  508. '/api/v2/workspaces/1/members',
  509. status=200,
  510. params=params,
  511. )
  512. user_role_found = res.json_body
  513. assert user_role_found['role'] == 'content-manager'
  514. assert user_role_found['user_id']
  515. user_id = user_role_found['user_id']
  516. assert user_role_found['workspace_id'] == 1
  517. assert user_role_found['newly_created'] is True
  518. assert user_role_found['email_sent'] is False
  519. res = self.testapp.get('/api/v2/workspaces/1/members',
  520. status=200).json_body # nopep8
  521. assert len(res) == 2
  522. user_role = res[0]
  523. assert user_role['role'] == 'workspace-manager'
  524. assert user_role['user_id'] == 1
  525. assert user_role['workspace_id'] == 1
  526. user_role = res[1]
  527. assert user_role_found['role'] == user_role['role']
  528. assert user_role_found['user_id'] == user_role['user_id']
  529. assert user_role_found['workspace_id'] == user_role['workspace_id']
  530. def test_api__update_workspace_member_role__ok_200__nominal_case(self):
  531. """
  532. Update worskpace member role
  533. """
  534. # before
  535. self.testapp.authorization = (
  536. 'Basic',
  537. (
  538. 'admin@admin.admin',
  539. 'admin@admin.admin'
  540. )
  541. )
  542. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  543. assert len(res) == 1
  544. user_role = res[0]
  545. assert user_role['role'] == 'workspace-manager'
  546. assert user_role['user_id'] == 1
  547. assert user_role['workspace_id'] == 1
  548. # update workspace role
  549. params = {
  550. 'role': 'content-manager',
  551. }
  552. res = self.testapp.put_json(
  553. '/api/v2/workspaces/1/members/1',
  554. status=200,
  555. params=params,
  556. )
  557. user_role = res.json_body
  558. assert user_role['role'] == 'content-manager'
  559. assert user_role['user_id'] == 1
  560. assert user_role['workspace_id'] == 1
  561. # after
  562. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  563. assert len(res) == 1
  564. user_role = res[0]
  565. assert user_role['role'] == 'content-manager'
  566. assert user_role['user_id'] == 1
  567. assert user_role['workspace_id'] == 1
  568. class TestUserInvitationWithMailActivatedSync(FunctionalTest):
  569. fixtures = [BaseFixture, ContentFixtures]
  570. config_section = 'functional_test_with_mail_test_sync'
  571. def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8
  572. """
  573. Create workspace member role
  574. :return:
  575. """
  576. requests.delete('http://127.0.0.1:8025/api/v1/messages')
  577. self.testapp.authorization = (
  578. 'Basic',
  579. (
  580. 'admin@admin.admin',
  581. 'admin@admin.admin'
  582. )
  583. )
  584. # create workspace role
  585. params = {
  586. 'user_id': None,
  587. 'user_email_or_public_name': 'bob@bob.bob',
  588. 'role': 'content-manager',
  589. }
  590. res = self.testapp.post_json(
  591. '/api/v2/workspaces/1/members',
  592. status=200,
  593. params=params,
  594. )
  595. user_role_found = res.json_body
  596. assert user_role_found['role'] == 'content-manager'
  597. assert user_role_found['user_id']
  598. user_id = user_role_found['user_id']
  599. assert user_role_found['workspace_id'] == 1
  600. assert user_role_found['newly_created'] is True
  601. assert user_role_found['email_sent'] is True
  602. # check mail received
  603. response = requests.get('http://127.0.0.1:8025/api/v1/messages')
  604. response = response.json()
  605. assert len(response) == 1
  606. headers = response[0]['Content']['Headers']
  607. assert headers['From'][0] == 'Tracim Notifications <test_user_from+0@localhost>' # nopep8
  608. assert headers['To'][0] == 'bob <bob@bob.bob>'
  609. assert headers['Subject'][0] == '[TRACIM] Created account'
  610. # TODO - G.M - 2018-08-02 - Place cleanup outside of the test
  611. requests.delete('http://127.0.0.1:8025/api/v1/messages')
  612. class TestUserInvitationWithMailActivatedASync(FunctionalTest):
  613. fixtures = [BaseFixture, ContentFixtures]
  614. config_section = 'functional_test_with_mail_test_async'
  615. def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8
  616. """
  617. Create workspace member role
  618. :return:
  619. """
  620. self.testapp.authorization = (
  621. 'Basic',
  622. (
  623. 'admin@admin.admin',
  624. 'admin@admin.admin'
  625. )
  626. )
  627. # create workspace role
  628. params = {
  629. 'user_id': None,
  630. 'user_email_or_public_name': 'bob@bob.bob',
  631. 'role': 'content-manager',
  632. }
  633. res = self.testapp.post_json(
  634. '/api/v2/workspaces/1/members',
  635. status=200,
  636. params=params,
  637. )
  638. user_role_found = res.json_body
  639. assert user_role_found['newly_created'] is True
  640. assert user_role_found['email_sent'] is False
  641. class TestWorkspaceContents(FunctionalTest):
  642. """
  643. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  644. """
  645. fixtures = [BaseFixture, ContentFixtures]
  646. def test_api__get_workspace_content__ok_200__get_default(self):
  647. """
  648. Check obtain workspace contents with defaults filters
  649. """
  650. self.testapp.authorization = (
  651. 'Basic',
  652. (
  653. 'admin@admin.admin',
  654. 'admin@admin.admin'
  655. )
  656. )
  657. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  658. # TODO - G.M - 30-05-2018 - Check this test
  659. assert len(res) == 3
  660. content = res[0]
  661. assert content['content_id'] == 1
  662. assert content['content_type'] == 'folder'
  663. assert content['is_archived'] is False
  664. assert content['is_deleted'] is False
  665. assert content['label'] == 'Tools'
  666. assert content['parent_id'] is None
  667. assert content['show_in_ui'] is True
  668. assert content['slug'] == 'tools'
  669. assert content['status'] == 'open'
  670. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  671. assert content['workspace_id'] == 1
  672. content = res[1]
  673. assert content['content_id'] == 2
  674. assert content['content_type'] == 'folder'
  675. assert content['is_archived'] is False
  676. assert content['is_deleted'] is False
  677. assert content['label'] == 'Menus'
  678. assert content['parent_id'] is None
  679. assert content['show_in_ui'] is True
  680. assert content['slug'] == 'menus'
  681. assert content['status'] == 'open'
  682. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  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']) == {'thread', 'html-document', 'folder', 'file'} # 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']) == {'thread', 'html-document', 'folder', 'file'} # 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']) == {'thread', 'html-document', 'folder', 'file'} # 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']) == {'thread', 'html-document', 'folder', 'file'} # 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']) == {'thread', 'html-document', 'folder', 'file'} # 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']) == {'thread', 'html-document', 'folder', 'file'} # 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']) == {'thread', 'html-document', 'folder', 'file'} # 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']) == {'thread', 'html-document', 'folder', 'file'} # 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_put_move_content__ok_200__nominal_case(self):
  1611. """
  1612. Move content
  1613. move Apple_Pie (content_id: 8)
  1614. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1615. of workspace Recipes.
  1616. """
  1617. self.testapp.authorization = (
  1618. 'Basic',
  1619. (
  1620. 'admin@admin.admin',
  1621. 'admin@admin.admin'
  1622. )
  1623. )
  1624. params = {
  1625. 'new_parent_id': '4', # Salads
  1626. 'new_workspace_id': '2',
  1627. }
  1628. params_folder1 = {
  1629. 'parent_id': 3,
  1630. 'show_archived': 0,
  1631. 'show_deleted': 0,
  1632. 'show_active': 1,
  1633. }
  1634. params_folder2 = {
  1635. 'parent_id': 4,
  1636. 'show_archived': 0,
  1637. 'show_deleted': 0,
  1638. 'show_active': 1,
  1639. }
  1640. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1641. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1642. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1643. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1644. # TODO - G.M - 2018-06-163 - Check content
  1645. res = self.testapp.put_json(
  1646. '/api/v2/workspaces/2/contents/8/move',
  1647. params=params,
  1648. status=200
  1649. )
  1650. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1651. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1652. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1653. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1654. assert res.json_body
  1655. assert res.json_body['parent_id'] == 4
  1656. assert res.json_body['content_id'] == 8
  1657. assert res.json_body['workspace_id'] == 2
  1658. def test_api_put_move_content__ok_200__to_root(self):
  1659. """
  1660. Move content
  1661. move Apple_Pie (content_id: 8)
  1662. from Desserts folder(content_id: 3) to root (content_id: 0)
  1663. of workspace Recipes.
  1664. """
  1665. self.testapp.authorization = (
  1666. 'Basic',
  1667. (
  1668. 'admin@admin.admin',
  1669. 'admin@admin.admin'
  1670. )
  1671. )
  1672. params = {
  1673. 'new_parent_id': None, # root
  1674. 'new_workspace_id': 2,
  1675. }
  1676. params_folder1 = {
  1677. 'parent_id': 3,
  1678. 'show_archived': 0,
  1679. 'show_deleted': 0,
  1680. 'show_active': 1,
  1681. }
  1682. params_folder2 = {
  1683. 'parent_id': 0,
  1684. 'show_archived': 0,
  1685. 'show_deleted': 0,
  1686. 'show_active': 1,
  1687. }
  1688. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1689. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1690. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1691. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1692. # TODO - G.M - 2018-06-163 - Check content
  1693. res = self.testapp.put_json(
  1694. '/api/v2/workspaces/2/contents/8/move',
  1695. params=params,
  1696. status=200
  1697. )
  1698. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1699. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1700. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1701. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1702. assert res.json_body
  1703. assert res.json_body['parent_id'] is None
  1704. assert res.json_body['content_id'] == 8
  1705. assert res.json_body['workspace_id'] == 2
  1706. def test_api_put_move_content__ok_200__with_workspace_id(self):
  1707. """
  1708. Move content
  1709. move Apple_Pie (content_id: 8)
  1710. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1711. of workspace Recipes.
  1712. """
  1713. self.testapp.authorization = (
  1714. 'Basic',
  1715. (
  1716. 'admin@admin.admin',
  1717. 'admin@admin.admin'
  1718. )
  1719. )
  1720. params = {
  1721. 'new_parent_id': '4', # Salads
  1722. 'new_workspace_id': '2',
  1723. }
  1724. params_folder1 = {
  1725. 'parent_id': 3,
  1726. 'show_archived': 0,
  1727. 'show_deleted': 0,
  1728. 'show_active': 1,
  1729. }
  1730. params_folder2 = {
  1731. 'parent_id': 4,
  1732. 'show_archived': 0,
  1733. 'show_deleted': 0,
  1734. 'show_active': 1,
  1735. }
  1736. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1737. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1738. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1739. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1740. # TODO - G.M - 2018-06-163 - Check content
  1741. res = self.testapp.put_json(
  1742. '/api/v2/workspaces/2/contents/8/move',
  1743. params=params,
  1744. status=200
  1745. )
  1746. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1747. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1748. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1749. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1750. assert res.json_body
  1751. assert res.json_body['parent_id'] == 4
  1752. assert res.json_body['content_id'] == 8
  1753. assert res.json_body['workspace_id'] == 2
  1754. def test_api_put_move_content__ok_200__to_another_workspace(self):
  1755. """
  1756. Move content
  1757. move Apple_Pie (content_id: 8)
  1758. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  1759. of workspace Business.
  1760. """
  1761. self.testapp.authorization = (
  1762. 'Basic',
  1763. (
  1764. 'admin@admin.admin',
  1765. 'admin@admin.admin'
  1766. )
  1767. )
  1768. params = {
  1769. 'new_parent_id': '2', # Menus
  1770. 'new_workspace_id': '1',
  1771. }
  1772. params_folder1 = {
  1773. 'parent_id': 3,
  1774. 'show_archived': 0,
  1775. 'show_deleted': 0,
  1776. 'show_active': 1,
  1777. }
  1778. params_folder2 = {
  1779. 'parent_id': 2,
  1780. 'show_archived': 0,
  1781. 'show_deleted': 0,
  1782. 'show_active': 1,
  1783. }
  1784. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1785. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1786. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1787. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1788. # TODO - G.M - 2018-06-163 - Check content
  1789. res = self.testapp.put_json(
  1790. '/api/v2/workspaces/2/contents/8/move',
  1791. params=params,
  1792. status=200
  1793. )
  1794. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1795. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1796. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1797. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1798. assert res.json_body
  1799. assert res.json_body['parent_id'] == 2
  1800. assert res.json_body['content_id'] == 8
  1801. assert res.json_body['workspace_id'] == 1
  1802. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  1803. """
  1804. Move content
  1805. move Apple_Pie (content_id: 8)
  1806. from Desserts folder(content_id: 3) to root (content_id: 0)
  1807. of workspace Business.
  1808. """
  1809. self.testapp.authorization = (
  1810. 'Basic',
  1811. (
  1812. 'admin@admin.admin',
  1813. 'admin@admin.admin'
  1814. )
  1815. )
  1816. params = {
  1817. 'new_parent_id': None, # root
  1818. 'new_workspace_id': '1',
  1819. }
  1820. params_folder1 = {
  1821. 'parent_id': 3,
  1822. 'show_archived': 0,
  1823. 'show_deleted': 0,
  1824. 'show_active': 1,
  1825. }
  1826. params_folder2 = {
  1827. 'parent_id': 0,
  1828. 'show_archived': 0,
  1829. 'show_deleted': 0,
  1830. 'show_active': 1,
  1831. }
  1832. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1833. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1834. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1835. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1836. # TODO - G.M - 2018-06-163 - Check content
  1837. res = self.testapp.put_json(
  1838. '/api/v2/workspaces/2/contents/8/move',
  1839. params=params,
  1840. status=200
  1841. )
  1842. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1843. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1844. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1845. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1846. assert res.json_body
  1847. assert res.json_body['parent_id'] is None
  1848. assert res.json_body['content_id'] == 8
  1849. assert res.json_body['workspace_id'] == 1
  1850. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  1851. """
  1852. Move content
  1853. move Apple_Pie (content_id: 8)
  1854. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1855. of workspace Recipes.
  1856. Workspace_id of parent_id don't match with workspace_id of workspace
  1857. """
  1858. self.testapp.authorization = (
  1859. 'Basic',
  1860. (
  1861. 'admin@admin.admin',
  1862. 'admin@admin.admin'
  1863. )
  1864. )
  1865. params = {
  1866. 'new_parent_id': '4', # Salads
  1867. 'new_workspace_id': '1',
  1868. }
  1869. params_folder1 = {
  1870. 'parent_id': 3,
  1871. 'show_archived': 0,
  1872. 'show_deleted': 0,
  1873. 'show_active': 1,
  1874. }
  1875. params_folder2 = {
  1876. 'parent_id': 4,
  1877. 'show_archived': 0,
  1878. 'show_deleted': 0,
  1879. 'show_active': 1,
  1880. }
  1881. res = self.testapp.put_json(
  1882. '/api/v2/workspaces/2/contents/8/move',
  1883. params=params,
  1884. status=400,
  1885. )
  1886. def test_api_put_delete_content__ok_200__nominal_case(self):
  1887. """
  1888. delete content
  1889. delete Apple_pie ( content_id: 8, parent_id: 3)
  1890. """
  1891. self.testapp.authorization = (
  1892. 'Basic',
  1893. (
  1894. 'admin@admin.admin',
  1895. 'admin@admin.admin'
  1896. )
  1897. )
  1898. params_active = {
  1899. 'parent_id': 3,
  1900. 'show_archived': 0,
  1901. 'show_deleted': 0,
  1902. 'show_active': 1,
  1903. }
  1904. params_deleted = {
  1905. 'parent_id': 3,
  1906. 'show_archived': 0,
  1907. 'show_deleted': 1,
  1908. 'show_active': 0,
  1909. }
  1910. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1911. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1912. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1913. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1914. # TODO - G.M - 2018-06-163 - Check content
  1915. res = self.testapp.put_json(
  1916. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1917. '/api/v2/workspaces/2/contents/8/delete',
  1918. status=204
  1919. )
  1920. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1921. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1922. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1923. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1924. def test_api_put_archive_content__ok_200__nominal_case(self):
  1925. """
  1926. archive content
  1927. archive Apple_pie ( content_id: 8, parent_id: 3)
  1928. """
  1929. self.testapp.authorization = (
  1930. 'Basic',
  1931. (
  1932. 'admin@admin.admin',
  1933. 'admin@admin.admin'
  1934. )
  1935. )
  1936. params_active = {
  1937. 'parent_id': 3,
  1938. 'show_archived': 0,
  1939. 'show_deleted': 0,
  1940. 'show_active': 1,
  1941. }
  1942. params_archived = {
  1943. 'parent_id': 3,
  1944. 'show_archived': 1,
  1945. 'show_deleted': 0,
  1946. 'show_active': 0,
  1947. }
  1948. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1949. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1950. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1951. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1952. res = self.testapp.put_json(
  1953. '/api/v2/workspaces/2/contents/8/archive',
  1954. status=204
  1955. )
  1956. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1957. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1958. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1959. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1960. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1961. """
  1962. Undelete content
  1963. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1964. """
  1965. self.testapp.authorization = (
  1966. 'Basic',
  1967. (
  1968. 'bob@fsf.local',
  1969. 'foobarbaz'
  1970. )
  1971. )
  1972. params_active = {
  1973. 'parent_id': 10,
  1974. 'show_archived': 0,
  1975. 'show_deleted': 0,
  1976. 'show_active': 1,
  1977. }
  1978. params_deleted = {
  1979. 'parent_id': 10,
  1980. 'show_archived': 0,
  1981. 'show_deleted': 1,
  1982. 'show_active': 0,
  1983. }
  1984. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1985. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1986. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1987. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1988. res = self.testapp.put_json(
  1989. '/api/v2/workspaces/2/contents/14/undelete',
  1990. status=204
  1991. )
  1992. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1993. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1994. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1995. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1996. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1997. """
  1998. unarchive content,
  1999. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  2000. """
  2001. self.testapp.authorization = (
  2002. 'Basic',
  2003. (
  2004. 'bob@fsf.local',
  2005. 'foobarbaz'
  2006. )
  2007. )
  2008. params_active = {
  2009. 'parent_id': 10,
  2010. 'show_archived': 0,
  2011. 'show_deleted': 0,
  2012. 'show_active': 1,
  2013. }
  2014. params_archived = {
  2015. 'parent_id': 10,
  2016. 'show_archived': 1,
  2017. 'show_deleted': 0,
  2018. 'show_active': 0,
  2019. }
  2020. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  2021. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  2022. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  2023. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  2024. res = self.testapp.put_json(
  2025. '/api/v2/workspaces/2/contents/13/unarchive',
  2026. status=204
  2027. )
  2028. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  2029. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  2030. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  2031. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8