test_workspaces.py 60KB

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