test_workspaces.py 64KB

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