test_workspaces.py 53KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  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. class TestWorkspaceContents(FunctionalTest):
  285. """
  286. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  287. """
  288. fixtures = [BaseFixture, ContentFixtures]
  289. def test_api__get_workspace_content__ok_200__get_default(self):
  290. """
  291. Check obtain workspace contents with defaults filters
  292. """
  293. self.testapp.authorization = (
  294. 'Basic',
  295. (
  296. 'admin@admin.admin',
  297. 'admin@admin.admin'
  298. )
  299. )
  300. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  301. # TODO - G.M - 30-05-2018 - Check this test
  302. assert len(res) == 3
  303. content = res[0]
  304. assert content['content_id'] == 1
  305. assert content['is_archived'] is False
  306. assert content['is_deleted'] is False
  307. assert content['label'] == 'Tools'
  308. assert content['parent_id'] is None
  309. assert content['show_in_ui'] is True
  310. assert content['slug'] == 'tools'
  311. assert content['status'] == 'open'
  312. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  313. assert content['workspace_id'] == 1
  314. content = res[1]
  315. assert content['content_id'] == 2
  316. assert content['is_archived'] is False
  317. assert content['is_deleted'] is False
  318. assert content['label'] == 'Menus'
  319. assert content['parent_id'] is None
  320. assert content['show_in_ui'] is True
  321. assert content['slug'] == 'menus'
  322. assert content['status'] == 'open'
  323. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  324. assert content['workspace_id'] == 1
  325. content = res[2]
  326. assert content['content_id'] == 11
  327. assert content['is_archived'] is False
  328. assert content['is_deleted'] is False
  329. assert content['label'] == 'Current Menu'
  330. assert content['parent_id'] == 2
  331. assert content['show_in_ui'] is True
  332. assert content['slug'] == 'current-menu'
  333. assert content['status'] == 'open'
  334. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  335. assert content['workspace_id'] == 1
  336. # Root related
  337. def test_api__get_workspace_content__ok_200__get_all_root_content__legacy_html_slug(self):
  338. """
  339. Check obtain workspace all root contents
  340. """
  341. set_html_document_slug_to_legacy(self.session_factory)
  342. params = {
  343. 'parent_id': 0,
  344. 'show_archived': 1,
  345. 'show_deleted': 1,
  346. 'show_active': 1,
  347. }
  348. self.testapp.authorization = (
  349. 'Basic',
  350. (
  351. 'bob@fsf.local',
  352. 'foobarbaz'
  353. )
  354. )
  355. res = self.testapp.get(
  356. '/api/v2/workspaces/3/contents',
  357. status=200,
  358. params=params,
  359. ).json_body # nopep8
  360. # TODO - G.M - 30-05-2018 - Check this test
  361. assert len(res) == 4
  362. content = res[1]
  363. assert content['content_type'] == 'html-documents'
  364. assert content['content_id'] == 15
  365. assert content['is_archived'] is False
  366. assert content['is_deleted'] is False
  367. assert content['label'] == 'New Fruit Salad'
  368. assert content['parent_id'] is None
  369. assert content['show_in_ui'] is True
  370. assert content['slug'] == 'new-fruit-salad'
  371. assert content['status'] == 'open'
  372. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  373. assert content['workspace_id'] == 3
  374. content = res[2]
  375. assert content['content_type'] == 'html-documents'
  376. assert content['content_id'] == 16
  377. assert content['is_archived'] is True
  378. assert content['is_deleted'] is False
  379. assert content['label'].startswith('Fruit Salad')
  380. assert content['parent_id'] is None
  381. assert content['show_in_ui'] is True
  382. assert content['slug'].startswith('fruit-salad')
  383. assert content['status'] == 'open'
  384. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  385. assert content['workspace_id'] == 3
  386. content = res[3]
  387. assert content['content_type'] == 'html-documents'
  388. assert content['content_id'] == 17
  389. assert content['is_archived'] is False
  390. assert content['is_deleted'] is True
  391. assert content['label'].startswith('Bad Fruit Salad')
  392. assert content['parent_id'] is None
  393. assert content['show_in_ui'] is True
  394. assert content['slug'].startswith('bad-fruit-salad')
  395. assert content['status'] == 'open'
  396. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  397. assert content['workspace_id'] == 3
  398. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  399. """
  400. Check obtain workspace all root contents
  401. """
  402. params = {
  403. 'parent_id': 0,
  404. 'show_archived': 1,
  405. 'show_deleted': 1,
  406. 'show_active': 1,
  407. }
  408. self.testapp.authorization = (
  409. 'Basic',
  410. (
  411. 'bob@fsf.local',
  412. 'foobarbaz'
  413. )
  414. )
  415. res = self.testapp.get(
  416. '/api/v2/workspaces/3/contents',
  417. status=200,
  418. params=params,
  419. ).json_body # nopep8
  420. # TODO - G.M - 30-05-2018 - Check this test
  421. assert len(res) == 4
  422. content = res[1]
  423. assert content['content_type'] == 'html-documents'
  424. assert content['content_id'] == 15
  425. assert content['is_archived'] is False
  426. assert content['is_deleted'] is False
  427. assert content['label'] == 'New Fruit Salad'
  428. assert content['parent_id'] is None
  429. assert content['show_in_ui'] is True
  430. assert content['slug'] == 'new-fruit-salad'
  431. assert content['status'] == 'open'
  432. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  433. assert content['workspace_id'] == 3
  434. content = res[2]
  435. assert content['content_type'] == 'html-documents'
  436. assert content['content_id'] == 16
  437. assert content['is_archived'] is True
  438. assert content['is_deleted'] is False
  439. assert content['label'].startswith('Fruit Salad')
  440. assert content['parent_id'] is None
  441. assert content['show_in_ui'] is True
  442. assert content['slug'].startswith('fruit-salad')
  443. assert content['status'] == 'open'
  444. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  445. assert content['workspace_id'] == 3
  446. content = res[3]
  447. assert content['content_type'] == 'html-documents'
  448. assert content['content_id'] == 17
  449. assert content['is_archived'] is False
  450. assert content['is_deleted'] is True
  451. assert content['label'].startswith('Bad Fruit Salad')
  452. assert content['parent_id'] is None
  453. assert content['show_in_ui'] is True
  454. assert content['slug'].startswith('bad-fruit-salad')
  455. assert content['status'] == 'open'
  456. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  457. assert content['workspace_id'] == 3
  458. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8
  459. """
  460. Check obtain workspace root active contents
  461. """
  462. params = {
  463. 'parent_id': 0,
  464. 'show_archived': 0,
  465. 'show_deleted': 0,
  466. 'show_active': 1,
  467. }
  468. self.testapp.authorization = (
  469. 'Basic',
  470. (
  471. 'bob@fsf.local',
  472. 'foobarbaz'
  473. )
  474. )
  475. res = self.testapp.get(
  476. '/api/v2/workspaces/3/contents',
  477. status=200,
  478. params=params,
  479. ).json_body # nopep8
  480. # TODO - G.M - 30-05-2018 - Check this test
  481. assert len(res) == 2
  482. content = res[1]
  483. assert content['content_type'] == 'html-documents'
  484. assert content['content_id'] == 15
  485. assert content['is_archived'] is False
  486. assert content['is_deleted'] is False
  487. assert content['label'] == 'New Fruit Salad'
  488. assert content['parent_id'] is None
  489. assert content['show_in_ui'] is True
  490. assert content['slug'] == 'new-fruit-salad'
  491. assert content['status'] == 'open'
  492. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  493. assert content['workspace_id'] == 3
  494. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8
  495. """
  496. Check obtain workspace root archived contents
  497. """
  498. params = {
  499. 'parent_id': 0,
  500. 'show_archived': 1,
  501. 'show_deleted': 0,
  502. 'show_active': 0,
  503. }
  504. self.testapp.authorization = (
  505. 'Basic',
  506. (
  507. 'bob@fsf.local',
  508. 'foobarbaz'
  509. )
  510. )
  511. res = self.testapp.get(
  512. '/api/v2/workspaces/3/contents',
  513. status=200,
  514. params=params,
  515. ).json_body # nopep8
  516. assert len(res) == 1
  517. content = res[0]
  518. assert content['content_type'] == 'html-documents'
  519. assert content['content_id'] == 16
  520. assert content['is_archived'] is True
  521. assert content['is_deleted'] is False
  522. assert content['label'].startswith('Fruit Salad')
  523. assert content['parent_id'] is None
  524. assert content['show_in_ui'] is True
  525. assert content['slug'].startswith('fruit-salad')
  526. assert content['status'] == 'open'
  527. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  528. assert content['workspace_id'] == 3
  529. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8
  530. """
  531. Check obtain workspace root deleted contents
  532. """
  533. params = {
  534. 'parent_id': 0,
  535. 'show_archived': 0,
  536. 'show_deleted': 1,
  537. 'show_active': 0,
  538. }
  539. self.testapp.authorization = (
  540. 'Basic',
  541. (
  542. 'bob@fsf.local',
  543. 'foobarbaz'
  544. )
  545. )
  546. res = self.testapp.get(
  547. '/api/v2/workspaces/3/contents',
  548. status=200,
  549. params=params,
  550. ).json_body # nopep8
  551. # TODO - G.M - 30-05-2018 - Check this test
  552. assert len(res) == 1
  553. content = res[0]
  554. assert content['content_type'] == 'html-documents'
  555. assert content['content_id'] == 17
  556. assert content['is_archived'] is False
  557. assert content['is_deleted'] is True
  558. assert content['label'].startswith('Bad Fruit Salad')
  559. assert content['parent_id'] is None
  560. assert content['show_in_ui'] is True
  561. assert content['slug'].startswith('bad-fruit-salad')
  562. assert content['status'] == 'open'
  563. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  564. assert content['workspace_id'] == 3
  565. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  566. """
  567. Check obtain workspace root content who does not match any type
  568. (archived, deleted, active) result should be empty list.
  569. """
  570. params = {
  571. 'parent_id': 0,
  572. 'show_archived': 0,
  573. 'show_deleted': 0,
  574. 'show_active': 0,
  575. }
  576. self.testapp.authorization = (
  577. 'Basic',
  578. (
  579. 'bob@fsf.local',
  580. 'foobarbaz'
  581. )
  582. )
  583. res = self.testapp.get(
  584. '/api/v2/workspaces/3/contents',
  585. status=200,
  586. params=params,
  587. ).json_body # nopep8
  588. # TODO - G.M - 30-05-2018 - Check this test
  589. assert res == []
  590. # Folder related
  591. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  592. """
  593. Check obtain workspace folder all contents
  594. """
  595. params = {
  596. 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id
  597. 'show_archived': 1,
  598. 'show_deleted': 1,
  599. 'show_active': 1,
  600. }
  601. self.testapp.authorization = (
  602. 'Basic',
  603. (
  604. 'admin@admin.admin',
  605. 'admin@admin.admin'
  606. )
  607. )
  608. res = self.testapp.get(
  609. '/api/v2/workspaces/2/contents',
  610. status=200,
  611. params=params,
  612. ).json_body # nopep8
  613. assert len(res) == 3
  614. content = res[0]
  615. assert content['content_type'] == 'html-documents'
  616. assert content['content_id'] == 12
  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'] == 10
  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'] == 2
  626. content = res[1]
  627. assert content['content_type'] == 'html-documents'
  628. assert content['content_id'] == 13
  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'] == 10
  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'] == 2
  638. content = res[2]
  639. assert content['content_type'] == 'html-documents'
  640. assert content['content_id'] == 14
  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'] == 10
  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'] == 2
  650. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8
  651. """
  652. Check obtain workspace folder active contents
  653. """
  654. params = {
  655. 'parent_id': 10,
  656. 'show_archived': 0,
  657. 'show_deleted': 0,
  658. 'show_active': 1,
  659. }
  660. self.testapp.authorization = (
  661. 'Basic',
  662. (
  663. 'admin@admin.admin',
  664. 'admin@admin.admin'
  665. )
  666. )
  667. res = self.testapp.get(
  668. '/api/v2/workspaces/2/contents',
  669. status=200,
  670. params=params,
  671. ).json_body # nopep8
  672. assert len(res) == 1
  673. content = res[0]
  674. assert content['content_type']
  675. assert content['content_id'] == 12
  676. assert content['is_archived'] is False
  677. assert content['is_deleted'] is False
  678. assert content['label'] == 'New Fruit Salad'
  679. assert content['parent_id'] == 10
  680. assert content['show_in_ui'] is True
  681. assert content['slug'] == 'new-fruit-salad'
  682. assert content['status'] == 'open'
  683. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  684. assert content['workspace_id'] == 2
  685. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8
  686. """
  687. Check obtain workspace folder archived contents
  688. """
  689. params = {
  690. 'parent_id': 10,
  691. 'show_archived': 1,
  692. 'show_deleted': 0,
  693. 'show_active': 0,
  694. }
  695. self.testapp.authorization = (
  696. 'Basic',
  697. (
  698. 'admin@admin.admin',
  699. 'admin@admin.admin'
  700. )
  701. )
  702. res = self.testapp.get(
  703. '/api/v2/workspaces/2/contents',
  704. status=200,
  705. params=params,
  706. ).json_body # nopep8
  707. assert len(res) == 1
  708. content = res[0]
  709. assert content['content_type'] == 'html-documents'
  710. assert content['content_id'] == 13
  711. assert content['is_archived'] is True
  712. assert content['is_deleted'] is False
  713. assert content['label'].startswith('Fruit Salad')
  714. assert content['parent_id'] == 10
  715. assert content['show_in_ui'] is True
  716. assert content['slug'].startswith('fruit-salad')
  717. assert content['status'] == 'open'
  718. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  719. assert content['workspace_id'] == 2
  720. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8
  721. """
  722. Check obtain workspace folder deleted contents
  723. """
  724. params = {
  725. 'parent_id': 10,
  726. 'show_archived': 0,
  727. 'show_deleted': 1,
  728. 'show_active': 0,
  729. }
  730. self.testapp.authorization = (
  731. 'Basic',
  732. (
  733. 'admin@admin.admin',
  734. 'admin@admin.admin'
  735. )
  736. )
  737. res = self.testapp.get(
  738. '/api/v2/workspaces/2/contents',
  739. status=200,
  740. params=params,
  741. ).json_body # nopep8
  742. assert len(res) == 1
  743. content = res[0]
  744. assert content['content_type'] == 'html-documents'
  745. assert content['content_id'] == 14
  746. assert content['is_archived'] is False
  747. assert content['is_deleted'] is True
  748. assert content['label'].startswith('Bad Fruit Salad')
  749. assert content['parent_id'] == 10
  750. assert content['show_in_ui'] is True
  751. assert content['slug'].startswith('bad-fruit-salad')
  752. assert content['status'] == 'open'
  753. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  754. assert content['workspace_id'] == 2
  755. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8
  756. """
  757. Check obtain workspace folder content who does not match any type
  758. (archived, deleted, active) result should be empty list.
  759. """
  760. params = {
  761. 'parent_id': 10,
  762. 'show_archived': 0,
  763. 'show_deleted': 0,
  764. 'show_active': 0,
  765. }
  766. self.testapp.authorization = (
  767. 'Basic',
  768. (
  769. 'admin@admin.admin',
  770. 'admin@admin.admin'
  771. )
  772. )
  773. res = self.testapp.get(
  774. '/api/v2/workspaces/2/contents',
  775. status=200,
  776. params=params,
  777. ).json_body # nopep8
  778. # TODO - G.M - 30-05-2018 - Check this test
  779. assert res == []
  780. # Error case
  781. def test_api__get_workspace_content__err_400__unallowed_user(self):
  782. """
  783. Check obtain workspace content list with an unreachable workspace for
  784. user
  785. """
  786. self.testapp.authorization = (
  787. 'Basic',
  788. (
  789. 'lawrence-not-real-email@fsf.local',
  790. 'foobarbaz'
  791. )
  792. )
  793. res = self.testapp.get('/api/v2/workspaces/3/contents', status=400)
  794. assert isinstance(res.json, dict)
  795. assert 'code' in res.json.keys()
  796. assert 'message' in res.json.keys()
  797. assert 'details' in res.json.keys()
  798. def test_api__get_workspace_content__err_401__unregistered_user(self):
  799. """
  800. Check obtain workspace content list with an unregistered user
  801. """
  802. self.testapp.authorization = (
  803. 'Basic',
  804. (
  805. 'john@doe.doe',
  806. 'lapin'
  807. )
  808. )
  809. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  810. assert isinstance(res.json, dict)
  811. assert 'code' in res.json.keys()
  812. assert 'message' in res.json.keys()
  813. assert 'details' in res.json.keys()
  814. def test_api__get_workspace_content__err_400__workspace_does_not_exist(self): # nopep8
  815. """
  816. Check obtain workspace contents list with an existing user but
  817. an unexisting workspace
  818. """
  819. self.testapp.authorization = (
  820. 'Basic',
  821. (
  822. 'admin@admin.admin',
  823. 'admin@admin.admin'
  824. )
  825. )
  826. res = self.testapp.get('/api/v2/workspaces/5/contents', status=400)
  827. assert isinstance(res.json, dict)
  828. assert 'code' in res.json.keys()
  829. assert 'message' in res.json.keys()
  830. assert 'details' in res.json.keys()
  831. def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8
  832. """
  833. Create generic content
  834. """
  835. self.testapp.authorization = (
  836. 'Basic',
  837. (
  838. 'admin@admin.admin',
  839. 'admin@admin.admin'
  840. )
  841. )
  842. params = {
  843. 'label': 'GenericCreatedContent',
  844. 'content_type': 'markdownpage',
  845. }
  846. res = self.testapp.post_json(
  847. '/api/v2/workspaces/1/contents',
  848. params=params,
  849. status=200
  850. )
  851. assert res
  852. assert res.json_body
  853. assert res.json_body['status'] == 'open'
  854. assert res.json_body['content_id']
  855. assert res.json_body['content_type'] == 'markdownpage'
  856. assert res.json_body['is_archived'] is False
  857. assert res.json_body['is_deleted'] is False
  858. assert res.json_body['workspace_id'] == 1
  859. assert res.json_body['slug'] == 'genericcreatedcontent'
  860. assert res.json_body['parent_id'] is None
  861. assert res.json_body['show_in_ui'] is True
  862. assert res.json_body['sub_content_types']
  863. params_active = {
  864. 'parent_id': 0,
  865. 'show_archived': 0,
  866. 'show_deleted': 0,
  867. 'show_active': 1,
  868. }
  869. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  870. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  871. assert res.json_body in active_contents
  872. def test_api__post_content_create_generic_content__err_400__empty_label(self) -> None: # nopep8
  873. """
  874. Create generic content
  875. """
  876. self.testapp.authorization = (
  877. 'Basic',
  878. (
  879. 'admin@admin.admin',
  880. 'admin@admin.admin'
  881. )
  882. )
  883. params = {
  884. 'label': '',
  885. 'content_type': 'markdownpage',
  886. }
  887. res = self.testapp.post_json(
  888. '/api/v2/workspaces/1/contents',
  889. params=params,
  890. status=400
  891. )
  892. def test_api__post_content_create_generic_content__err_400__wrong_content_type(self) -> None: # nopep8
  893. """
  894. Create generic content
  895. """
  896. self.testapp.authorization = (
  897. 'Basic',
  898. (
  899. 'admin@admin.admin',
  900. 'admin@admin.admin'
  901. )
  902. )
  903. params = {
  904. 'label': 'GenericCreatedContent',
  905. 'content_type': 'unexistent-content-type',
  906. }
  907. res = self.testapp.post_json(
  908. '/api/v2/workspaces/1/contents',
  909. params=params,
  910. status=400,
  911. )
  912. def test_api_put_move_content__ok_200__nominal_case(self):
  913. """
  914. Move content
  915. move Apple_Pie (content_id: 8)
  916. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  917. of workspace Recipes.
  918. """
  919. self.testapp.authorization = (
  920. 'Basic',
  921. (
  922. 'admin@admin.admin',
  923. 'admin@admin.admin'
  924. )
  925. )
  926. params = {
  927. 'new_parent_id': '4', # Salads
  928. 'new_workspace_id': '2',
  929. }
  930. params_folder1 = {
  931. 'parent_id': 3,
  932. 'show_archived': 0,
  933. 'show_deleted': 0,
  934. 'show_active': 1,
  935. }
  936. params_folder2 = {
  937. 'parent_id': 4,
  938. 'show_archived': 0,
  939. 'show_deleted': 0,
  940. 'show_active': 1,
  941. }
  942. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  943. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  944. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  945. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  946. # TODO - G.M - 2018-06-163 - Check content
  947. res = self.testapp.put_json(
  948. '/api/v2/workspaces/2/contents/8/move',
  949. params=params,
  950. status=200
  951. )
  952. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  953. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  954. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  955. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  956. assert res.json_body
  957. assert res.json_body['parent_id'] == 4
  958. assert res.json_body['content_id'] == 8
  959. assert res.json_body['workspace_id'] == 2
  960. def test_api_put_move_content__ok_200__to_root(self):
  961. """
  962. Move content
  963. move Apple_Pie (content_id: 8)
  964. from Desserts folder(content_id: 3) to root (content_id: 0)
  965. of workspace Recipes.
  966. """
  967. self.testapp.authorization = (
  968. 'Basic',
  969. (
  970. 'admin@admin.admin',
  971. 'admin@admin.admin'
  972. )
  973. )
  974. params = {
  975. 'new_parent_id': None, # root
  976. 'new_workspace_id': 2,
  977. }
  978. params_folder1 = {
  979. 'parent_id': 3,
  980. 'show_archived': 0,
  981. 'show_deleted': 0,
  982. 'show_active': 1,
  983. }
  984. params_folder2 = {
  985. 'parent_id': 0,
  986. 'show_archived': 0,
  987. 'show_deleted': 0,
  988. 'show_active': 1,
  989. }
  990. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  991. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  992. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  993. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  994. # TODO - G.M - 2018-06-163 - Check content
  995. res = self.testapp.put_json(
  996. '/api/v2/workspaces/2/contents/8/move',
  997. params=params,
  998. status=200
  999. )
  1000. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1001. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1002. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1003. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1004. assert res.json_body
  1005. assert res.json_body['parent_id'] is None
  1006. assert res.json_body['content_id'] == 8
  1007. assert res.json_body['workspace_id'] == 2
  1008. def test_api_put_move_content__ok_200__with_workspace_id(self):
  1009. """
  1010. Move content
  1011. move Apple_Pie (content_id: 8)
  1012. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1013. of workspace Recipes.
  1014. """
  1015. self.testapp.authorization = (
  1016. 'Basic',
  1017. (
  1018. 'admin@admin.admin',
  1019. 'admin@admin.admin'
  1020. )
  1021. )
  1022. params = {
  1023. 'new_parent_id': '4', # Salads
  1024. 'new_workspace_id': '2',
  1025. }
  1026. params_folder1 = {
  1027. 'parent_id': 3,
  1028. 'show_archived': 0,
  1029. 'show_deleted': 0,
  1030. 'show_active': 1,
  1031. }
  1032. params_folder2 = {
  1033. 'parent_id': 4,
  1034. 'show_archived': 0,
  1035. 'show_deleted': 0,
  1036. 'show_active': 1,
  1037. }
  1038. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1039. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1040. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1041. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1042. # TODO - G.M - 2018-06-163 - Check content
  1043. res = self.testapp.put_json(
  1044. '/api/v2/workspaces/2/contents/8/move',
  1045. params=params,
  1046. status=200
  1047. )
  1048. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1049. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1050. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1051. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1052. assert res.json_body
  1053. assert res.json_body['parent_id'] == 4
  1054. assert res.json_body['content_id'] == 8
  1055. assert res.json_body['workspace_id'] == 2
  1056. def test_api_put_move_content__ok_200__to_another_workspace(self):
  1057. """
  1058. Move content
  1059. move Apple_Pie (content_id: 8)
  1060. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  1061. of workspace Business.
  1062. """
  1063. self.testapp.authorization = (
  1064. 'Basic',
  1065. (
  1066. 'admin@admin.admin',
  1067. 'admin@admin.admin'
  1068. )
  1069. )
  1070. params = {
  1071. 'new_parent_id': '2', # Menus
  1072. 'new_workspace_id': '1',
  1073. }
  1074. params_folder1 = {
  1075. 'parent_id': 3,
  1076. 'show_archived': 0,
  1077. 'show_deleted': 0,
  1078. 'show_active': 1,
  1079. }
  1080. params_folder2 = {
  1081. 'parent_id': 2,
  1082. 'show_archived': 0,
  1083. 'show_deleted': 0,
  1084. 'show_active': 1,
  1085. }
  1086. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1087. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1088. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1089. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1090. # TODO - G.M - 2018-06-163 - Check content
  1091. res = self.testapp.put_json(
  1092. '/api/v2/workspaces/2/contents/8/move',
  1093. params=params,
  1094. status=200
  1095. )
  1096. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1097. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1098. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1099. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1100. assert res.json_body
  1101. assert res.json_body['parent_id'] == 2
  1102. assert res.json_body['content_id'] == 8
  1103. assert res.json_body['workspace_id'] == 1
  1104. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  1105. """
  1106. Move content
  1107. move Apple_Pie (content_id: 8)
  1108. from Desserts folder(content_id: 3) to root (content_id: 0)
  1109. of workspace Business.
  1110. """
  1111. self.testapp.authorization = (
  1112. 'Basic',
  1113. (
  1114. 'admin@admin.admin',
  1115. 'admin@admin.admin'
  1116. )
  1117. )
  1118. params = {
  1119. 'new_parent_id': None, # root
  1120. 'new_workspace_id': '1',
  1121. }
  1122. params_folder1 = {
  1123. 'parent_id': 3,
  1124. 'show_archived': 0,
  1125. 'show_deleted': 0,
  1126. 'show_active': 1,
  1127. }
  1128. params_folder2 = {
  1129. 'parent_id': 0,
  1130. 'show_archived': 0,
  1131. 'show_deleted': 0,
  1132. 'show_active': 1,
  1133. }
  1134. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1135. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1136. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1137. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1138. # TODO - G.M - 2018-06-163 - Check content
  1139. res = self.testapp.put_json(
  1140. '/api/v2/workspaces/2/contents/8/move',
  1141. params=params,
  1142. status=200
  1143. )
  1144. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1145. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1146. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1147. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1148. assert res.json_body
  1149. assert res.json_body['parent_id'] is None
  1150. assert res.json_body['content_id'] == 8
  1151. assert res.json_body['workspace_id'] == 1
  1152. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  1153. """
  1154. Move content
  1155. move Apple_Pie (content_id: 8)
  1156. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1157. of workspace Recipes.
  1158. Workspace_id of parent_id don't match with workspace_id of workspace
  1159. """
  1160. self.testapp.authorization = (
  1161. 'Basic',
  1162. (
  1163. 'admin@admin.admin',
  1164. 'admin@admin.admin'
  1165. )
  1166. )
  1167. params = {
  1168. 'new_parent_id': '4', # Salads
  1169. 'new_workspace_id': '1',
  1170. }
  1171. params_folder1 = {
  1172. 'parent_id': 3,
  1173. 'show_archived': 0,
  1174. 'show_deleted': 0,
  1175. 'show_active': 1,
  1176. }
  1177. params_folder2 = {
  1178. 'parent_id': 4,
  1179. 'show_archived': 0,
  1180. 'show_deleted': 0,
  1181. 'show_active': 1,
  1182. }
  1183. res = self.testapp.put_json(
  1184. '/api/v2/workspaces/2/contents/8/move',
  1185. params=params,
  1186. status=400,
  1187. )
  1188. def test_api_put_delete_content__ok_200__nominal_case(self):
  1189. """
  1190. delete content
  1191. delete Apple_pie ( content_id: 8, parent_id: 3)
  1192. """
  1193. self.testapp.authorization = (
  1194. 'Basic',
  1195. (
  1196. 'admin@admin.admin',
  1197. 'admin@admin.admin'
  1198. )
  1199. )
  1200. params_active = {
  1201. 'parent_id': 3,
  1202. 'show_archived': 0,
  1203. 'show_deleted': 0,
  1204. 'show_active': 1,
  1205. }
  1206. params_deleted = {
  1207. 'parent_id': 3,
  1208. 'show_archived': 0,
  1209. 'show_deleted': 1,
  1210. 'show_active': 0,
  1211. }
  1212. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1213. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1214. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1215. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1216. # TODO - G.M - 2018-06-163 - Check content
  1217. res = self.testapp.put_json(
  1218. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1219. '/api/v2/workspaces/2/contents/8/delete',
  1220. status=204
  1221. )
  1222. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1223. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1224. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1225. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1226. def test_api_put_archive_content__ok_200__nominal_case(self):
  1227. """
  1228. archive content
  1229. archive Apple_pie ( content_id: 8, parent_id: 3)
  1230. """
  1231. self.testapp.authorization = (
  1232. 'Basic',
  1233. (
  1234. 'admin@admin.admin',
  1235. 'admin@admin.admin'
  1236. )
  1237. )
  1238. params_active = {
  1239. 'parent_id': 3,
  1240. 'show_archived': 0,
  1241. 'show_deleted': 0,
  1242. 'show_active': 1,
  1243. }
  1244. params_archived = {
  1245. 'parent_id': 3,
  1246. 'show_archived': 1,
  1247. 'show_deleted': 0,
  1248. 'show_active': 0,
  1249. }
  1250. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1251. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1252. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1253. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1254. res = self.testapp.put_json(
  1255. '/api/v2/workspaces/2/contents/8/archive',
  1256. status=204
  1257. )
  1258. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1259. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1260. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1261. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1262. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1263. """
  1264. Undelete content
  1265. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1266. """
  1267. self.testapp.authorization = (
  1268. 'Basic',
  1269. (
  1270. 'bob@fsf.local',
  1271. 'foobarbaz'
  1272. )
  1273. )
  1274. params_active = {
  1275. 'parent_id': 10,
  1276. 'show_archived': 0,
  1277. 'show_deleted': 0,
  1278. 'show_active': 1,
  1279. }
  1280. params_deleted = {
  1281. 'parent_id': 10,
  1282. 'show_archived': 0,
  1283. 'show_deleted': 1,
  1284. 'show_active': 0,
  1285. }
  1286. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1287. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1288. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1289. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1290. res = self.testapp.put_json(
  1291. '/api/v2/workspaces/2/contents/14/undelete',
  1292. status=204
  1293. )
  1294. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1295. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1296. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1297. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1298. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1299. """
  1300. unarchive content,
  1301. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1302. """
  1303. self.testapp.authorization = (
  1304. 'Basic',
  1305. (
  1306. 'bob@fsf.local',
  1307. 'foobarbaz'
  1308. )
  1309. )
  1310. params_active = {
  1311. 'parent_id': 10,
  1312. 'show_archived': 0,
  1313. 'show_deleted': 0,
  1314. 'show_active': 1,
  1315. }
  1316. params_archived = {
  1317. 'parent_id': 10,
  1318. 'show_archived': 1,
  1319. 'show_deleted': 0,
  1320. 'show_active': 0,
  1321. }
  1322. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1323. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1324. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  1325. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  1326. res = self.testapp.put_json(
  1327. '/api/v2/workspaces/2/contents/13/unarchive',
  1328. status=204
  1329. )
  1330. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1331. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1332. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  1333. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8