test_workspaces.py 61KB

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