test_workspaces.py 73KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985
  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 import models
  8. from tracim.lib.core.content import ContentApi
  9. from tracim.lib.core.workspace import WorkspaceApi
  10. from tracim.models import get_tm_session
  11. from tracim.models.data import ContentType
  12. from tracim.tests import FunctionalTest
  13. from tracim.tests import set_html_document_slug_to_legacy
  14. from tracim.fixtures.content import Content as ContentFixtures
  15. from tracim.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-documents'
  53. assert sidebar_entry['label'] == 'Text Documents'
  54. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=html-documents' # 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/files'
  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/threads'
  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 set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  603. assert content['workspace_id'] == 1
  604. content = res[1]
  605. assert content['content_id'] == 2
  606. assert content['content_type'] == 'folder'
  607. assert content['is_archived'] is False
  608. assert content['is_deleted'] is False
  609. assert content['label'] == 'Menus'
  610. assert content['parent_id'] is None
  611. assert content['show_in_ui'] is True
  612. assert content['slug'] == 'menus'
  613. assert content['status'] == 'open'
  614. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  615. assert content['workspace_id'] == 1
  616. content = res[2]
  617. assert content['content_id'] == 11
  618. assert content['content_type'] == 'html-documents'
  619. assert content['is_archived'] is False
  620. assert content['is_deleted'] is False
  621. assert content['label'] == 'Current Menu'
  622. assert content['parent_id'] == 2
  623. assert content['show_in_ui'] is True
  624. assert content['slug'] == 'current-menu'
  625. assert content['status'] == 'open'
  626. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  627. assert content['workspace_id'] == 1
  628. def test_api__get_workspace_content__ok_200__get_default_html_documents(self):
  629. """
  630. Check obtain workspace contents with defaults filters + content_filter
  631. """
  632. self.testapp.authorization = (
  633. 'Basic',
  634. (
  635. 'admin@admin.admin',
  636. 'admin@admin.admin'
  637. )
  638. )
  639. params = {
  640. 'content_type': 'html-documents',
  641. }
  642. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200, params=params).json_body # nopep8
  643. assert len(res) == 1
  644. content = res[0]
  645. assert content
  646. assert content['content_id'] == 11
  647. assert content['content_type'] == 'html-documents'
  648. assert content['is_archived'] is False
  649. assert content['is_deleted'] is False
  650. assert content['label'] == 'Current Menu'
  651. assert content['parent_id'] == 2
  652. assert content['show_in_ui'] is True
  653. assert content['slug'] == 'current-menu'
  654. assert content['status'] == 'open'
  655. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  656. assert content['workspace_id'] == 1
  657. # Root related
  658. def test_api__get_workspace_content__ok_200__get_all_root_content__legacy_html_slug(self): # nopep8
  659. """
  660. Check obtain workspace all root contents
  661. """
  662. set_html_document_slug_to_legacy(self.session_factory)
  663. params = {
  664. 'parent_id': 0,
  665. 'show_archived': 1,
  666. 'show_deleted': 1,
  667. 'show_active': 1,
  668. }
  669. self.testapp.authorization = (
  670. 'Basic',
  671. (
  672. 'bob@fsf.local',
  673. 'foobarbaz'
  674. )
  675. )
  676. res = self.testapp.get(
  677. '/api/v2/workspaces/3/contents',
  678. status=200,
  679. params=params,
  680. ).json_body # nopep8
  681. # TODO - G.M - 30-05-2018 - Check this test
  682. assert len(res) == 4
  683. content = res[1]
  684. assert content['content_type'] == 'html-documents'
  685. assert content['content_id'] == 15
  686. assert content['is_archived'] is False
  687. assert content['is_deleted'] is False
  688. assert content['label'] == 'New Fruit Salad'
  689. assert content['parent_id'] is None
  690. assert content['show_in_ui'] is True
  691. assert content['slug'] == 'new-fruit-salad'
  692. assert content['status'] == 'open'
  693. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  694. assert content['workspace_id'] == 3
  695. content = res[2]
  696. assert content['content_type'] == 'html-documents'
  697. assert content['content_id'] == 16
  698. assert content['is_archived'] is True
  699. assert content['is_deleted'] is False
  700. assert content['label'].startswith('Fruit Salad')
  701. assert content['parent_id'] is None
  702. assert content['show_in_ui'] is True
  703. assert content['slug'].startswith('fruit-salad')
  704. assert content['status'] == 'open'
  705. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  706. assert content['workspace_id'] == 3
  707. content = res[3]
  708. assert content['content_type'] == 'html-documents'
  709. assert content['content_id'] == 17
  710. assert content['is_archived'] is False
  711. assert content['is_deleted'] is True
  712. assert content['label'].startswith('Bad Fruit Salad')
  713. assert content['parent_id'] is None
  714. assert content['show_in_ui'] is True
  715. assert content['slug'].startswith('bad-fruit-salad')
  716. assert content['status'] == 'open'
  717. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  718. assert content['workspace_id'] == 3
  719. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  720. """
  721. Check obtain workspace all root contents
  722. """
  723. params = {
  724. 'parent_id': 0,
  725. 'show_archived': 1,
  726. 'show_deleted': 1,
  727. 'show_active': 1,
  728. }
  729. self.testapp.authorization = (
  730. 'Basic',
  731. (
  732. 'bob@fsf.local',
  733. 'foobarbaz'
  734. )
  735. )
  736. res = self.testapp.get(
  737. '/api/v2/workspaces/3/contents',
  738. status=200,
  739. params=params,
  740. ).json_body # nopep8
  741. # TODO - G.M - 30-05-2018 - Check this test
  742. assert len(res) == 4
  743. content = res[1]
  744. assert content['content_type'] == 'html-documents'
  745. assert content['content_id'] == 15
  746. assert content['is_archived'] is False
  747. assert content['is_deleted'] is False
  748. assert content['label'] == 'New Fruit Salad'
  749. assert content['parent_id'] is None
  750. assert content['show_in_ui'] is True
  751. assert content['slug'] == 'new-fruit-salad'
  752. assert content['status'] == 'open'
  753. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  754. assert content['workspace_id'] == 3
  755. content = res[2]
  756. assert content['content_type'] == 'html-documents'
  757. assert content['content_id'] == 16
  758. assert content['is_archived'] is True
  759. assert content['is_deleted'] is False
  760. assert content['label'].startswith('Fruit Salad')
  761. assert content['parent_id'] is None
  762. assert content['show_in_ui'] is True
  763. assert content['slug'].startswith('fruit-salad')
  764. assert content['status'] == 'open'
  765. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  766. assert content['workspace_id'] == 3
  767. content = res[3]
  768. assert content['content_type'] == 'html-documents'
  769. assert content['content_id'] == 17
  770. assert content['is_archived'] is False
  771. assert content['is_deleted'] is True
  772. assert content['label'].startswith('Bad Fruit Salad')
  773. assert content['parent_id'] is None
  774. assert content['show_in_ui'] is True
  775. assert content['slug'].startswith('bad-fruit-salad')
  776. assert content['status'] == 'open'
  777. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  778. assert content['workspace_id'] == 3
  779. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8
  780. """
  781. Check obtain workspace root active contents
  782. """
  783. params = {
  784. 'parent_id': 0,
  785. 'show_archived': 0,
  786. 'show_deleted': 0,
  787. 'show_active': 1,
  788. }
  789. self.testapp.authorization = (
  790. 'Basic',
  791. (
  792. 'bob@fsf.local',
  793. 'foobarbaz'
  794. )
  795. )
  796. res = self.testapp.get(
  797. '/api/v2/workspaces/3/contents',
  798. status=200,
  799. params=params,
  800. ).json_body # nopep8
  801. # TODO - G.M - 30-05-2018 - Check this test
  802. assert len(res) == 2
  803. content = res[1]
  804. assert content['content_type'] == 'html-documents'
  805. assert content['content_id'] == 15
  806. assert content['is_archived'] is False
  807. assert content['is_deleted'] is False
  808. assert content['label'] == 'New Fruit Salad'
  809. assert content['parent_id'] is None
  810. assert content['show_in_ui'] is True
  811. assert content['slug'] == 'new-fruit-salad'
  812. assert content['status'] == 'open'
  813. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  814. assert content['workspace_id'] == 3
  815. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8
  816. """
  817. Check obtain workspace root archived contents
  818. """
  819. params = {
  820. 'parent_id': 0,
  821. 'show_archived': 1,
  822. 'show_deleted': 0,
  823. 'show_active': 0,
  824. }
  825. self.testapp.authorization = (
  826. 'Basic',
  827. (
  828. 'bob@fsf.local',
  829. 'foobarbaz'
  830. )
  831. )
  832. res = self.testapp.get(
  833. '/api/v2/workspaces/3/contents',
  834. status=200,
  835. params=params,
  836. ).json_body # nopep8
  837. assert len(res) == 1
  838. content = res[0]
  839. assert content['content_type'] == 'html-documents'
  840. assert content['content_id'] == 16
  841. assert content['is_archived'] is True
  842. assert content['is_deleted'] is False
  843. assert content['label'].startswith('Fruit Salad')
  844. assert content['parent_id'] is None
  845. assert content['show_in_ui'] is True
  846. assert content['slug'].startswith('fruit-salad')
  847. assert content['status'] == 'open'
  848. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  849. assert content['workspace_id'] == 3
  850. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8
  851. """
  852. Check obtain workspace root deleted contents
  853. """
  854. params = {
  855. 'parent_id': 0,
  856. 'show_archived': 0,
  857. 'show_deleted': 1,
  858. 'show_active': 0,
  859. }
  860. self.testapp.authorization = (
  861. 'Basic',
  862. (
  863. 'bob@fsf.local',
  864. 'foobarbaz'
  865. )
  866. )
  867. res = self.testapp.get(
  868. '/api/v2/workspaces/3/contents',
  869. status=200,
  870. params=params,
  871. ).json_body # nopep8
  872. # TODO - G.M - 30-05-2018 - Check this test
  873. assert len(res) == 1
  874. content = res[0]
  875. assert content['content_type'] == 'html-documents'
  876. assert content['content_id'] == 17
  877. assert content['is_archived'] is False
  878. assert content['is_deleted'] is True
  879. assert content['label'].startswith('Bad Fruit Salad')
  880. assert content['parent_id'] is None
  881. assert content['show_in_ui'] is True
  882. assert content['slug'].startswith('bad-fruit-salad')
  883. assert content['status'] == 'open'
  884. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  885. assert content['workspace_id'] == 3
  886. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  887. """
  888. Check obtain workspace root content who does not match any type
  889. (archived, deleted, active) result should be empty list.
  890. """
  891. params = {
  892. 'parent_id': 0,
  893. 'show_archived': 0,
  894. 'show_deleted': 0,
  895. 'show_active': 0,
  896. }
  897. self.testapp.authorization = (
  898. 'Basic',
  899. (
  900. 'bob@fsf.local',
  901. 'foobarbaz'
  902. )
  903. )
  904. res = self.testapp.get(
  905. '/api/v2/workspaces/3/contents',
  906. status=200,
  907. params=params,
  908. ).json_body # nopep8
  909. # TODO - G.M - 30-05-2018 - Check this test
  910. assert res == []
  911. # Folder related
  912. def test_api__get_workspace_content__ok_200__get_all_filter_content_thread(self):
  913. # prepare data
  914. dbsession = get_tm_session(self.session_factory, transaction.manager)
  915. admin = dbsession.query(models.User) \
  916. .filter(models.User.email == 'admin@admin.admin') \
  917. .one()
  918. workspace_api = WorkspaceApi(
  919. current_user=admin,
  920. session=dbsession,
  921. config=self.app_config
  922. )
  923. business_workspace = workspace_api.get_one(1)
  924. content_api = ContentApi(
  925. current_user=admin,
  926. session=dbsession,
  927. config=self.app_config
  928. )
  929. tool_folder = content_api.get_one(1, content_type=ContentType.Any)
  930. test_thread = content_api.create(
  931. content_type=ContentType.Thread,
  932. workspace=business_workspace,
  933. parent=tool_folder,
  934. label='Test Thread',
  935. do_save=False,
  936. do_notify=False,
  937. )
  938. test_thread.description = 'Thread description'
  939. dbsession.add(test_thread)
  940. test_file = content_api.create(
  941. content_type=ContentType.File,
  942. workspace=business_workspace,
  943. parent=tool_folder,
  944. label='Test file',
  945. do_save=False,
  946. do_notify=False,
  947. )
  948. test_file.file_extension = '.txt'
  949. test_file.depot_file = FileIntent(
  950. b'Test file',
  951. 'Test_file.txt',
  952. 'text/plain',
  953. )
  954. test_page_legacy = content_api.create(
  955. content_type=ContentType.Page,
  956. workspace=business_workspace,
  957. label='test_page',
  958. do_save=False,
  959. do_notify=False,
  960. )
  961. test_page_legacy.type = ContentType.PageLegacy
  962. content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
  963. test_html_document = content_api.create(
  964. content_type=ContentType.Page,
  965. workspace=business_workspace,
  966. label='test_html_page',
  967. do_save=False,
  968. do_notify=False,
  969. )
  970. content_api.update_content(test_html_document, 'test_page', '<p>HTML_DOCUMENT</p>') # nopep8
  971. dbsession.flush()
  972. transaction.commit()
  973. # test-itself
  974. params = {
  975. 'parent_id': 1,
  976. 'show_archived': 1,
  977. 'show_deleted': 1,
  978. 'show_active': 1,
  979. 'content_type': 'thread',
  980. }
  981. self.testapp.authorization = (
  982. 'Basic',
  983. (
  984. 'admin@admin.admin',
  985. 'admin@admin.admin'
  986. )
  987. )
  988. res = self.testapp.get(
  989. '/api/v2/workspaces/1/contents',
  990. status=200,
  991. params=params,
  992. ).json_body
  993. assert len(res) == 1
  994. content = res[0]
  995. assert content['content_type'] == 'thread'
  996. assert content['content_id']
  997. assert content['is_archived'] is False
  998. assert content['is_deleted'] is False
  999. assert content['label'] == 'Test Thread'
  1000. assert content['parent_id'] == 1
  1001. assert content['show_in_ui'] is True
  1002. assert content['slug'] == 'test-thread'
  1003. assert content['status'] == 'open'
  1004. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1005. assert content['workspace_id'] == 1
  1006. def test_api__get_workspace_content__ok_200__get_all_filter_content_html_and_legacy_page(self): # nopep8
  1007. # prepare data
  1008. dbsession = get_tm_session(self.session_factory, transaction.manager)
  1009. admin = dbsession.query(models.User) \
  1010. .filter(models.User.email == 'admin@admin.admin') \
  1011. .one()
  1012. workspace_api = WorkspaceApi(
  1013. current_user=admin,
  1014. session=dbsession,
  1015. config=self.app_config
  1016. )
  1017. business_workspace = workspace_api.get_one(1)
  1018. content_api = ContentApi(
  1019. current_user=admin,
  1020. session=dbsession,
  1021. config=self.app_config
  1022. )
  1023. tool_folder = content_api.get_one(1, content_type=ContentType.Any)
  1024. test_thread = content_api.create(
  1025. content_type=ContentType.Thread,
  1026. workspace=business_workspace,
  1027. parent=tool_folder,
  1028. label='Test Thread',
  1029. do_save=False,
  1030. do_notify=False,
  1031. )
  1032. test_thread.description = 'Thread description'
  1033. dbsession.add(test_thread)
  1034. test_file = content_api.create(
  1035. content_type=ContentType.File,
  1036. workspace=business_workspace,
  1037. parent=tool_folder,
  1038. label='Test file',
  1039. do_save=False,
  1040. do_notify=False,
  1041. )
  1042. test_file.file_extension = '.txt'
  1043. test_file.depot_file = FileIntent(
  1044. b'Test file',
  1045. 'Test_file.txt',
  1046. 'text/plain',
  1047. )
  1048. test_page_legacy = content_api.create(
  1049. content_type=ContentType.Page,
  1050. workspace=business_workspace,
  1051. parent=tool_folder,
  1052. label='test_page',
  1053. do_save=False,
  1054. do_notify=False,
  1055. )
  1056. test_page_legacy.type = ContentType.PageLegacy
  1057. content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
  1058. test_html_document = content_api.create(
  1059. content_type=ContentType.Page,
  1060. workspace=business_workspace,
  1061. parent=tool_folder,
  1062. label='test_html_page',
  1063. do_save=False,
  1064. do_notify=False,
  1065. )
  1066. content_api.update_content(test_html_document, 'test_html_page', '<p>HTML_DOCUMENT</p>') # nopep8
  1067. dbsession.flush()
  1068. transaction.commit()
  1069. # test-itself
  1070. params = {
  1071. 'parent_id': 1,
  1072. 'show_archived': 1,
  1073. 'show_deleted': 1,
  1074. 'show_active': 1,
  1075. 'content_type': 'html-documents',
  1076. }
  1077. self.testapp.authorization = (
  1078. 'Basic',
  1079. (
  1080. 'admin@admin.admin',
  1081. 'admin@admin.admin'
  1082. )
  1083. )
  1084. res = self.testapp.get(
  1085. '/api/v2/workspaces/1/contents',
  1086. status=200,
  1087. params=params,
  1088. ).json_body
  1089. assert len(res) == 2
  1090. content = res[0]
  1091. assert content['content_type'] == 'html-documents'
  1092. assert content['content_id']
  1093. assert content['is_archived'] is False
  1094. assert content['is_deleted'] is False
  1095. assert content['label'] == 'test_page'
  1096. assert content['parent_id'] == 1
  1097. assert content['show_in_ui'] is True
  1098. assert content['slug'] == 'test-page'
  1099. assert content['status'] == 'open'
  1100. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1101. assert content['workspace_id'] == 1
  1102. content = res[1]
  1103. assert content['content_type'] == 'html-documents'
  1104. assert content['content_id']
  1105. assert content['is_archived'] is False
  1106. assert content['is_deleted'] is False
  1107. assert content['label'] == 'test_html_page'
  1108. assert content['parent_id'] == 1
  1109. assert content['show_in_ui'] is True
  1110. assert content['slug'] == 'test-html-page'
  1111. assert content['status'] == 'open'
  1112. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1113. assert content['workspace_id'] == 1
  1114. assert res[0]['content_id'] != res[1]['content_id']
  1115. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  1116. """
  1117. Check obtain workspace folder all contents
  1118. """
  1119. params = {
  1120. 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id
  1121. 'show_archived': 1,
  1122. 'show_deleted': 1,
  1123. 'show_active': 1,
  1124. 'content_type': 'any'
  1125. }
  1126. self.testapp.authorization = (
  1127. 'Basic',
  1128. (
  1129. 'admin@admin.admin',
  1130. 'admin@admin.admin'
  1131. )
  1132. )
  1133. res = self.testapp.get(
  1134. '/api/v2/workspaces/2/contents',
  1135. status=200,
  1136. params=params,
  1137. ).json_body # nopep8
  1138. assert len(res) == 3
  1139. content = res[0]
  1140. assert content['content_type'] == 'html-documents'
  1141. assert content['content_id'] == 12
  1142. assert content['is_archived'] is False
  1143. assert content['is_deleted'] is False
  1144. assert content['label'] == 'New Fruit Salad'
  1145. assert content['parent_id'] == 10
  1146. assert content['show_in_ui'] is True
  1147. assert content['slug'] == 'new-fruit-salad'
  1148. assert content['status'] == 'open'
  1149. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1150. assert content['workspace_id'] == 2
  1151. content = res[1]
  1152. assert content['content_type'] == 'html-documents'
  1153. assert content['content_id'] == 13
  1154. assert content['is_archived'] is True
  1155. assert content['is_deleted'] is False
  1156. assert content['label'].startswith('Fruit Salad')
  1157. assert content['parent_id'] == 10
  1158. assert content['show_in_ui'] is True
  1159. assert content['slug'].startswith('fruit-salad')
  1160. assert content['status'] == 'open'
  1161. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1162. assert content['workspace_id'] == 2
  1163. content = res[2]
  1164. assert content['content_type'] == 'html-documents'
  1165. assert content['content_id'] == 14
  1166. assert content['is_archived'] is False
  1167. assert content['is_deleted'] is True
  1168. assert content['label'].startswith('Bad Fruit Salad')
  1169. assert content['parent_id'] == 10
  1170. assert content['show_in_ui'] is True
  1171. assert content['slug'].startswith('bad-fruit-salad')
  1172. assert content['status'] == 'open'
  1173. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1174. assert content['workspace_id'] == 2
  1175. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8
  1176. """
  1177. Check obtain workspace folder active contents
  1178. """
  1179. params = {
  1180. 'parent_id': 10,
  1181. 'show_archived': 0,
  1182. 'show_deleted': 0,
  1183. 'show_active': 1,
  1184. }
  1185. self.testapp.authorization = (
  1186. 'Basic',
  1187. (
  1188. 'admin@admin.admin',
  1189. 'admin@admin.admin'
  1190. )
  1191. )
  1192. res = self.testapp.get(
  1193. '/api/v2/workspaces/2/contents',
  1194. status=200,
  1195. params=params,
  1196. ).json_body # nopep8
  1197. assert len(res) == 1
  1198. content = res[0]
  1199. assert content['content_type']
  1200. assert content['content_id'] == 12
  1201. assert content['is_archived'] is False
  1202. assert content['is_deleted'] is False
  1203. assert content['label'] == 'New Fruit Salad'
  1204. assert content['parent_id'] == 10
  1205. assert content['show_in_ui'] is True
  1206. assert content['slug'] == 'new-fruit-salad'
  1207. assert content['status'] == 'open'
  1208. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1209. assert content['workspace_id'] == 2
  1210. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8
  1211. """
  1212. Check obtain workspace folder archived contents
  1213. """
  1214. params = {
  1215. 'parent_id': 10,
  1216. 'show_archived': 1,
  1217. 'show_deleted': 0,
  1218. 'show_active': 0,
  1219. }
  1220. self.testapp.authorization = (
  1221. 'Basic',
  1222. (
  1223. 'admin@admin.admin',
  1224. 'admin@admin.admin'
  1225. )
  1226. )
  1227. res = self.testapp.get(
  1228. '/api/v2/workspaces/2/contents',
  1229. status=200,
  1230. params=params,
  1231. ).json_body # nopep8
  1232. assert len(res) == 1
  1233. content = res[0]
  1234. assert content['content_type'] == 'html-documents'
  1235. assert content['content_id'] == 13
  1236. assert content['is_archived'] is True
  1237. assert content['is_deleted'] is False
  1238. assert content['label'].startswith('Fruit Salad')
  1239. assert content['parent_id'] == 10
  1240. assert content['show_in_ui'] is True
  1241. assert content['slug'].startswith('fruit-salad')
  1242. assert content['status'] == 'open'
  1243. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1244. assert content['workspace_id'] == 2
  1245. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8
  1246. """
  1247. Check obtain workspace folder deleted contents
  1248. """
  1249. params = {
  1250. 'parent_id': 10,
  1251. 'show_archived': 0,
  1252. 'show_deleted': 1,
  1253. 'show_active': 0,
  1254. }
  1255. self.testapp.authorization = (
  1256. 'Basic',
  1257. (
  1258. 'admin@admin.admin',
  1259. 'admin@admin.admin'
  1260. )
  1261. )
  1262. res = self.testapp.get(
  1263. '/api/v2/workspaces/2/contents',
  1264. status=200,
  1265. params=params,
  1266. ).json_body # nopep8
  1267. assert len(res) == 1
  1268. content = res[0]
  1269. assert content['content_type'] == 'html-documents'
  1270. assert content['content_id'] == 14
  1271. assert content['is_archived'] is False
  1272. assert content['is_deleted'] is True
  1273. assert content['label'].startswith('Bad Fruit Salad')
  1274. assert content['parent_id'] == 10
  1275. assert content['show_in_ui'] is True
  1276. assert content['slug'].startswith('bad-fruit-salad')
  1277. assert content['status'] == 'open'
  1278. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1279. assert content['workspace_id'] == 2
  1280. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8
  1281. """
  1282. Check obtain workspace folder content who does not match any type
  1283. (archived, deleted, active) result should be empty list.
  1284. """
  1285. params = {
  1286. 'parent_id': 10,
  1287. 'show_archived': 0,
  1288. 'show_deleted': 0,
  1289. 'show_active': 0,
  1290. }
  1291. self.testapp.authorization = (
  1292. 'Basic',
  1293. (
  1294. 'admin@admin.admin',
  1295. 'admin@admin.admin'
  1296. )
  1297. )
  1298. res = self.testapp.get(
  1299. '/api/v2/workspaces/2/contents',
  1300. status=200,
  1301. params=params,
  1302. ).json_body # nopep8
  1303. # TODO - G.M - 30-05-2018 - Check this test
  1304. assert res == []
  1305. # Error case
  1306. def test_api__get_workspace_content__err_400__unallowed_user(self):
  1307. """
  1308. Check obtain workspace content list with an unreachable workspace for
  1309. user
  1310. """
  1311. self.testapp.authorization = (
  1312. 'Basic',
  1313. (
  1314. 'lawrence-not-real-email@fsf.local',
  1315. 'foobarbaz'
  1316. )
  1317. )
  1318. res = self.testapp.get('/api/v2/workspaces/3/contents', status=400)
  1319. assert isinstance(res.json, dict)
  1320. assert 'code' in res.json.keys()
  1321. assert 'message' in res.json.keys()
  1322. assert 'details' in res.json.keys()
  1323. def test_api__get_workspace_content__err_401__unregistered_user(self):
  1324. """
  1325. Check obtain workspace content list with an unregistered user
  1326. """
  1327. self.testapp.authorization = (
  1328. 'Basic',
  1329. (
  1330. 'john@doe.doe',
  1331. 'lapin'
  1332. )
  1333. )
  1334. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  1335. assert isinstance(res.json, dict)
  1336. assert 'code' in res.json.keys()
  1337. assert 'message' in res.json.keys()
  1338. assert 'details' in res.json.keys()
  1339. def test_api__get_workspace_content__err_400__workspace_does_not_exist(self): # nopep8
  1340. """
  1341. Check obtain workspace contents list with an existing user but
  1342. an unexisting workspace
  1343. """
  1344. self.testapp.authorization = (
  1345. 'Basic',
  1346. (
  1347. 'admin@admin.admin',
  1348. 'admin@admin.admin'
  1349. )
  1350. )
  1351. res = self.testapp.get('/api/v2/workspaces/5/contents', status=400)
  1352. assert isinstance(res.json, dict)
  1353. assert 'code' in res.json.keys()
  1354. assert 'message' in res.json.keys()
  1355. assert 'details' in res.json.keys()
  1356. def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8
  1357. """
  1358. Create generic content
  1359. """
  1360. self.testapp.authorization = (
  1361. 'Basic',
  1362. (
  1363. 'admin@admin.admin',
  1364. 'admin@admin.admin'
  1365. )
  1366. )
  1367. params = {
  1368. 'label': 'GenericCreatedContent',
  1369. 'content_type': 'markdownpage',
  1370. }
  1371. res = self.testapp.post_json(
  1372. '/api/v2/workspaces/1/contents',
  1373. params=params,
  1374. status=200
  1375. )
  1376. assert res
  1377. assert res.json_body
  1378. assert res.json_body['status'] == 'open'
  1379. assert res.json_body['content_id']
  1380. assert res.json_body['content_type'] == 'markdownpage'
  1381. assert res.json_body['is_archived'] is False
  1382. assert res.json_body['is_deleted'] is False
  1383. assert res.json_body['workspace_id'] == 1
  1384. assert res.json_body['slug'] == 'genericcreatedcontent'
  1385. assert res.json_body['parent_id'] is None
  1386. assert res.json_body['show_in_ui'] is True
  1387. assert res.json_body['sub_content_types']
  1388. params_active = {
  1389. 'parent_id': 0,
  1390. 'show_archived': 0,
  1391. 'show_deleted': 0,
  1392. 'show_active': 1,
  1393. }
  1394. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1395. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1396. assert res.json_body in active_contents
  1397. def test_api__post_content_create_generic_content__ok_200__in_folder(self) -> None: # nopep8
  1398. """
  1399. Create generic content in folder
  1400. """
  1401. self.testapp.authorization = (
  1402. 'Basic',
  1403. (
  1404. 'admin@admin.admin',
  1405. 'admin@admin.admin'
  1406. )
  1407. )
  1408. params = {
  1409. 'label': 'GenericCreatedContent',
  1410. 'content_type': 'markdownpage',
  1411. 'parent_id': 10,
  1412. }
  1413. res = self.testapp.post_json(
  1414. '/api/v2/workspaces/1/contents',
  1415. params=params,
  1416. status=200
  1417. )
  1418. assert res
  1419. assert res.json_body
  1420. assert res.json_body['status'] == 'open'
  1421. assert res.json_body['content_id']
  1422. assert res.json_body['content_type'] == 'markdownpage'
  1423. assert res.json_body['is_archived'] is False
  1424. assert res.json_body['is_deleted'] is False
  1425. assert res.json_body['workspace_id'] == 1
  1426. assert res.json_body['slug'] == 'genericcreatedcontent'
  1427. assert res.json_body['parent_id'] == 10
  1428. assert res.json_body['show_in_ui'] is True
  1429. assert res.json_body['sub_content_types']
  1430. params_active = {
  1431. 'parent_id': 10,
  1432. 'show_archived': 0,
  1433. 'show_deleted': 0,
  1434. 'show_active': 1,
  1435. }
  1436. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1437. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1438. assert res.json_body in active_contents
  1439. def test_api__post_content_create_generic_content__err_400__empty_label(self) -> None: # nopep8
  1440. """
  1441. Create generic content
  1442. """
  1443. self.testapp.authorization = (
  1444. 'Basic',
  1445. (
  1446. 'admin@admin.admin',
  1447. 'admin@admin.admin'
  1448. )
  1449. )
  1450. params = {
  1451. 'label': '',
  1452. 'content_type': 'markdownpage',
  1453. }
  1454. res = self.testapp.post_json(
  1455. '/api/v2/workspaces/1/contents',
  1456. params=params,
  1457. status=400
  1458. )
  1459. def test_api__post_content_create_generic_content__err_400__wrong_content_type(self) -> None: # nopep8
  1460. """
  1461. Create generic content
  1462. """
  1463. self.testapp.authorization = (
  1464. 'Basic',
  1465. (
  1466. 'admin@admin.admin',
  1467. 'admin@admin.admin'
  1468. )
  1469. )
  1470. params = {
  1471. 'label': 'GenericCreatedContent',
  1472. 'content_type': 'unexistent-content-type',
  1473. }
  1474. res = self.testapp.post_json(
  1475. '/api/v2/workspaces/1/contents',
  1476. params=params,
  1477. status=400,
  1478. )
  1479. def test_api_put_move_content__ok_200__nominal_case(self):
  1480. """
  1481. Move content
  1482. move Apple_Pie (content_id: 8)
  1483. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1484. of workspace Recipes.
  1485. """
  1486. self.testapp.authorization = (
  1487. 'Basic',
  1488. (
  1489. 'admin@admin.admin',
  1490. 'admin@admin.admin'
  1491. )
  1492. )
  1493. params = {
  1494. 'new_parent_id': '4', # Salads
  1495. 'new_workspace_id': '2',
  1496. }
  1497. params_folder1 = {
  1498. 'parent_id': 3,
  1499. 'show_archived': 0,
  1500. 'show_deleted': 0,
  1501. 'show_active': 1,
  1502. }
  1503. params_folder2 = {
  1504. 'parent_id': 4,
  1505. 'show_archived': 0,
  1506. 'show_deleted': 0,
  1507. 'show_active': 1,
  1508. }
  1509. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1510. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1511. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1512. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1513. # TODO - G.M - 2018-06-163 - Check content
  1514. res = self.testapp.put_json(
  1515. '/api/v2/workspaces/2/contents/8/move',
  1516. params=params,
  1517. status=200
  1518. )
  1519. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1520. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1521. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1522. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1523. assert res.json_body
  1524. assert res.json_body['parent_id'] == 4
  1525. assert res.json_body['content_id'] == 8
  1526. assert res.json_body['workspace_id'] == 2
  1527. def test_api_put_move_content__ok_200__to_root(self):
  1528. """
  1529. Move content
  1530. move Apple_Pie (content_id: 8)
  1531. from Desserts folder(content_id: 3) to root (content_id: 0)
  1532. of workspace Recipes.
  1533. """
  1534. self.testapp.authorization = (
  1535. 'Basic',
  1536. (
  1537. 'admin@admin.admin',
  1538. 'admin@admin.admin'
  1539. )
  1540. )
  1541. params = {
  1542. 'new_parent_id': None, # root
  1543. 'new_workspace_id': 2,
  1544. }
  1545. params_folder1 = {
  1546. 'parent_id': 3,
  1547. 'show_archived': 0,
  1548. 'show_deleted': 0,
  1549. 'show_active': 1,
  1550. }
  1551. params_folder2 = {
  1552. 'parent_id': 0,
  1553. 'show_archived': 0,
  1554. 'show_deleted': 0,
  1555. 'show_active': 1,
  1556. }
  1557. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1558. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1559. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1560. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1561. # TODO - G.M - 2018-06-163 - Check content
  1562. res = self.testapp.put_json(
  1563. '/api/v2/workspaces/2/contents/8/move',
  1564. params=params,
  1565. status=200
  1566. )
  1567. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1568. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1569. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1570. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1571. assert res.json_body
  1572. assert res.json_body['parent_id'] is None
  1573. assert res.json_body['content_id'] == 8
  1574. assert res.json_body['workspace_id'] == 2
  1575. def test_api_put_move_content__ok_200__with_workspace_id(self):
  1576. """
  1577. Move content
  1578. move Apple_Pie (content_id: 8)
  1579. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1580. of workspace Recipes.
  1581. """
  1582. self.testapp.authorization = (
  1583. 'Basic',
  1584. (
  1585. 'admin@admin.admin',
  1586. 'admin@admin.admin'
  1587. )
  1588. )
  1589. params = {
  1590. 'new_parent_id': '4', # Salads
  1591. 'new_workspace_id': '2',
  1592. }
  1593. params_folder1 = {
  1594. 'parent_id': 3,
  1595. 'show_archived': 0,
  1596. 'show_deleted': 0,
  1597. 'show_active': 1,
  1598. }
  1599. params_folder2 = {
  1600. 'parent_id': 4,
  1601. 'show_archived': 0,
  1602. 'show_deleted': 0,
  1603. 'show_active': 1,
  1604. }
  1605. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1606. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1607. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1608. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1609. # TODO - G.M - 2018-06-163 - Check content
  1610. res = self.testapp.put_json(
  1611. '/api/v2/workspaces/2/contents/8/move',
  1612. params=params,
  1613. status=200
  1614. )
  1615. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1616. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1617. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1618. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1619. assert res.json_body
  1620. assert res.json_body['parent_id'] == 4
  1621. assert res.json_body['content_id'] == 8
  1622. assert res.json_body['workspace_id'] == 2
  1623. def test_api_put_move_content__ok_200__to_another_workspace(self):
  1624. """
  1625. Move content
  1626. move Apple_Pie (content_id: 8)
  1627. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  1628. of workspace Business.
  1629. """
  1630. self.testapp.authorization = (
  1631. 'Basic',
  1632. (
  1633. 'admin@admin.admin',
  1634. 'admin@admin.admin'
  1635. )
  1636. )
  1637. params = {
  1638. 'new_parent_id': '2', # Menus
  1639. 'new_workspace_id': '1',
  1640. }
  1641. params_folder1 = {
  1642. 'parent_id': 3,
  1643. 'show_archived': 0,
  1644. 'show_deleted': 0,
  1645. 'show_active': 1,
  1646. }
  1647. params_folder2 = {
  1648. 'parent_id': 2,
  1649. 'show_archived': 0,
  1650. 'show_deleted': 0,
  1651. 'show_active': 1,
  1652. }
  1653. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1654. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1655. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1656. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1657. # TODO - G.M - 2018-06-163 - Check content
  1658. res = self.testapp.put_json(
  1659. '/api/v2/workspaces/2/contents/8/move',
  1660. params=params,
  1661. status=200
  1662. )
  1663. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1664. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1665. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1666. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1667. assert res.json_body
  1668. assert res.json_body['parent_id'] == 2
  1669. assert res.json_body['content_id'] == 8
  1670. assert res.json_body['workspace_id'] == 1
  1671. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  1672. """
  1673. Move content
  1674. move Apple_Pie (content_id: 8)
  1675. from Desserts folder(content_id: 3) to root (content_id: 0)
  1676. of workspace Business.
  1677. """
  1678. self.testapp.authorization = (
  1679. 'Basic',
  1680. (
  1681. 'admin@admin.admin',
  1682. 'admin@admin.admin'
  1683. )
  1684. )
  1685. params = {
  1686. 'new_parent_id': None, # root
  1687. 'new_workspace_id': '1',
  1688. }
  1689. params_folder1 = {
  1690. 'parent_id': 3,
  1691. 'show_archived': 0,
  1692. 'show_deleted': 0,
  1693. 'show_active': 1,
  1694. }
  1695. params_folder2 = {
  1696. 'parent_id': 0,
  1697. 'show_archived': 0,
  1698. 'show_deleted': 0,
  1699. 'show_active': 1,
  1700. }
  1701. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1702. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1703. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1704. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1705. # TODO - G.M - 2018-06-163 - Check content
  1706. res = self.testapp.put_json(
  1707. '/api/v2/workspaces/2/contents/8/move',
  1708. params=params,
  1709. status=200
  1710. )
  1711. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1712. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1713. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1714. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1715. assert res.json_body
  1716. assert res.json_body['parent_id'] is None
  1717. assert res.json_body['content_id'] == 8
  1718. assert res.json_body['workspace_id'] == 1
  1719. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  1720. """
  1721. Move content
  1722. move Apple_Pie (content_id: 8)
  1723. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1724. of workspace Recipes.
  1725. Workspace_id of parent_id don't match with workspace_id of workspace
  1726. """
  1727. self.testapp.authorization = (
  1728. 'Basic',
  1729. (
  1730. 'admin@admin.admin',
  1731. 'admin@admin.admin'
  1732. )
  1733. )
  1734. params = {
  1735. 'new_parent_id': '4', # Salads
  1736. 'new_workspace_id': '1',
  1737. }
  1738. params_folder1 = {
  1739. 'parent_id': 3,
  1740. 'show_archived': 0,
  1741. 'show_deleted': 0,
  1742. 'show_active': 1,
  1743. }
  1744. params_folder2 = {
  1745. 'parent_id': 4,
  1746. 'show_archived': 0,
  1747. 'show_deleted': 0,
  1748. 'show_active': 1,
  1749. }
  1750. res = self.testapp.put_json(
  1751. '/api/v2/workspaces/2/contents/8/move',
  1752. params=params,
  1753. status=400,
  1754. )
  1755. def test_api_put_delete_content__ok_200__nominal_case(self):
  1756. """
  1757. delete content
  1758. delete Apple_pie ( content_id: 8, parent_id: 3)
  1759. """
  1760. self.testapp.authorization = (
  1761. 'Basic',
  1762. (
  1763. 'admin@admin.admin',
  1764. 'admin@admin.admin'
  1765. )
  1766. )
  1767. params_active = {
  1768. 'parent_id': 3,
  1769. 'show_archived': 0,
  1770. 'show_deleted': 0,
  1771. 'show_active': 1,
  1772. }
  1773. params_deleted = {
  1774. 'parent_id': 3,
  1775. 'show_archived': 0,
  1776. 'show_deleted': 1,
  1777. 'show_active': 0,
  1778. }
  1779. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1780. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1781. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1782. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1783. # TODO - G.M - 2018-06-163 - Check content
  1784. res = self.testapp.put_json(
  1785. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1786. '/api/v2/workspaces/2/contents/8/delete',
  1787. status=204
  1788. )
  1789. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1790. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1791. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1792. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1793. def test_api_put_archive_content__ok_200__nominal_case(self):
  1794. """
  1795. archive content
  1796. archive Apple_pie ( content_id: 8, parent_id: 3)
  1797. """
  1798. self.testapp.authorization = (
  1799. 'Basic',
  1800. (
  1801. 'admin@admin.admin',
  1802. 'admin@admin.admin'
  1803. )
  1804. )
  1805. params_active = {
  1806. 'parent_id': 3,
  1807. 'show_archived': 0,
  1808. 'show_deleted': 0,
  1809. 'show_active': 1,
  1810. }
  1811. params_archived = {
  1812. 'parent_id': 3,
  1813. 'show_archived': 1,
  1814. 'show_deleted': 0,
  1815. 'show_active': 0,
  1816. }
  1817. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1818. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1819. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1820. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1821. res = self.testapp.put_json(
  1822. '/api/v2/workspaces/2/contents/8/archive',
  1823. status=204
  1824. )
  1825. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1826. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1827. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1828. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1829. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1830. """
  1831. Undelete content
  1832. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1833. """
  1834. self.testapp.authorization = (
  1835. 'Basic',
  1836. (
  1837. 'bob@fsf.local',
  1838. 'foobarbaz'
  1839. )
  1840. )
  1841. params_active = {
  1842. 'parent_id': 10,
  1843. 'show_archived': 0,
  1844. 'show_deleted': 0,
  1845. 'show_active': 1,
  1846. }
  1847. params_deleted = {
  1848. 'parent_id': 10,
  1849. 'show_archived': 0,
  1850. 'show_deleted': 1,
  1851. 'show_active': 0,
  1852. }
  1853. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1854. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1855. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1856. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1857. res = self.testapp.put_json(
  1858. '/api/v2/workspaces/2/contents/14/undelete',
  1859. status=204
  1860. )
  1861. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1862. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1863. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1864. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1865. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1866. """
  1867. unarchive content,
  1868. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1869. """
  1870. self.testapp.authorization = (
  1871. 'Basic',
  1872. (
  1873. 'bob@fsf.local',
  1874. 'foobarbaz'
  1875. )
  1876. )
  1877. params_active = {
  1878. 'parent_id': 10,
  1879. 'show_archived': 0,
  1880. 'show_deleted': 0,
  1881. 'show_active': 1,
  1882. }
  1883. params_archived = {
  1884. 'parent_id': 10,
  1885. 'show_archived': 1,
  1886. 'show_deleted': 0,
  1887. 'show_active': 0,
  1888. }
  1889. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1890. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1891. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  1892. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  1893. res = self.testapp.put_json(
  1894. '/api/v2/workspaces/2/contents/13/unarchive',
  1895. status=204
  1896. )
  1897. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1898. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1899. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  1900. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8