test_workspaces.py 77KB

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