test_workspaces.py 50KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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__get_workspace__err_400__unallowed_user(self) -> None:
  75. """
  76. Check obtain workspace unreachable for user
  77. """
  78. self.testapp.authorization = (
  79. 'Basic',
  80. (
  81. 'lawrence-not-real-email@fsf.local',
  82. 'foobarbaz'
  83. )
  84. )
  85. res = self.testapp.get('/api/v2/workspaces/1', status=400)
  86. assert isinstance(res.json, dict)
  87. assert 'code' in res.json.keys()
  88. assert 'message' in res.json.keys()
  89. assert 'details' in res.json.keys()
  90. def test_api__get_workspace__err_401__unregistered_user(self) -> None:
  91. """
  92. Check obtain workspace without registered user.
  93. """
  94. self.testapp.authorization = (
  95. 'Basic',
  96. (
  97. 'john@doe.doe',
  98. 'lapin'
  99. )
  100. )
  101. res = self.testapp.get('/api/v2/workspaces/1', status=401)
  102. assert isinstance(res.json, dict)
  103. assert 'code' in res.json.keys()
  104. assert 'message' in res.json.keys()
  105. assert 'details' in res.json.keys()
  106. def test_api__get_workspace__err_400__workspace_does_not_exist(self) -> None: # nopep8
  107. """
  108. Check obtain workspace who does not exist with an existing user.
  109. """
  110. self.testapp.authorization = (
  111. 'Basic',
  112. (
  113. 'admin@admin.admin',
  114. 'admin@admin.admin'
  115. )
  116. )
  117. res = self.testapp.get('/api/v2/workspaces/5', status=400)
  118. assert isinstance(res.json, dict)
  119. assert 'code' in res.json.keys()
  120. assert 'message' in res.json.keys()
  121. assert 'details' in res.json.keys()
  122. class TestWorkspaceMembersEndpoint(FunctionalTest):
  123. """
  124. Tests for /api/v2/workspaces/{workspace_id}/members endpoint
  125. """
  126. fixtures = [BaseFixture, ContentFixtures]
  127. def test_api__get_workspace_members__ok_200__nominal_case(self):
  128. """
  129. Check obtain workspace members list with a reachable workspace for user
  130. """
  131. self.testapp.authorization = (
  132. 'Basic',
  133. (
  134. 'admin@admin.admin',
  135. 'admin@admin.admin'
  136. )
  137. )
  138. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  139. assert len(res) == 1
  140. user_role = res[0]
  141. assert user_role['role'] == 'workspace-manager'
  142. assert user_role['user_id'] == 1
  143. assert user_role['workspace_id'] == 1
  144. assert user_role['user']['public_name'] == 'Global manager'
  145. # TODO - G.M - 24-05-2018 - [Avatar] Replace
  146. # by correct value when avatar feature will be enabled
  147. assert user_role['user']['avatar_url'] is None
  148. def test_api__get_workspace_members__err_400__unallowed_user(self):
  149. """
  150. Check obtain workspace members list with an unreachable workspace for
  151. user
  152. """
  153. self.testapp.authorization = (
  154. 'Basic',
  155. (
  156. 'lawrence-not-real-email@fsf.local',
  157. 'foobarbaz'
  158. )
  159. )
  160. res = self.testapp.get('/api/v2/workspaces/3/members', status=400)
  161. assert isinstance(res.json, dict)
  162. assert 'code' in res.json.keys()
  163. assert 'message' in res.json.keys()
  164. assert 'details' in res.json.keys()
  165. def test_api__get_workspace_members__err_401__unregistered_user(self):
  166. """
  167. Check obtain workspace members list with an unregistered user
  168. """
  169. self.testapp.authorization = (
  170. 'Basic',
  171. (
  172. 'john@doe.doe',
  173. 'lapin'
  174. )
  175. )
  176. res = self.testapp.get('/api/v2/workspaces/1/members', status=401)
  177. assert isinstance(res.json, dict)
  178. assert 'code' in res.json.keys()
  179. assert 'message' in res.json.keys()
  180. assert 'details' in res.json.keys()
  181. def test_api__get_workspace_members__err_400__workspace_does_not_exist(self): # nopep8
  182. """
  183. Check obtain workspace members list with an existing user but
  184. an unexisting workspace
  185. """
  186. self.testapp.authorization = (
  187. 'Basic',
  188. (
  189. 'admin@admin.admin',
  190. 'admin@admin.admin'
  191. )
  192. )
  193. res = self.testapp.get('/api/v2/workspaces/5/members', status=400)
  194. assert isinstance(res.json, dict)
  195. assert 'code' in res.json.keys()
  196. assert 'message' in res.json.keys()
  197. assert 'details' in res.json.keys()
  198. class TestWorkspaceContents(FunctionalTest):
  199. """
  200. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  201. """
  202. fixtures = [BaseFixture, ContentFixtures]
  203. def test_api__get_workspace_content__ok_200__get_default(self):
  204. """
  205. Check obtain workspace contents with defaults filters
  206. """
  207. self.testapp.authorization = (
  208. 'Basic',
  209. (
  210. 'admin@admin.admin',
  211. 'admin@admin.admin'
  212. )
  213. )
  214. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  215. # TODO - G.M - 30-05-2018 - Check this test
  216. assert len(res) == 3
  217. content = res[0]
  218. assert content['content_id'] == 1
  219. assert content['is_archived'] is False
  220. assert content['is_deleted'] is False
  221. assert content['label'] == 'Tools'
  222. assert content['parent_id'] is None
  223. assert content['show_in_ui'] is True
  224. assert content['slug'] == 'tools'
  225. assert content['status'] == 'open'
  226. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  227. assert content['workspace_id'] == 1
  228. content = res[1]
  229. assert content['content_id'] == 2
  230. assert content['is_archived'] is False
  231. assert content['is_deleted'] is False
  232. assert content['label'] == 'Menus'
  233. assert content['parent_id'] is None
  234. assert content['show_in_ui'] is True
  235. assert content['slug'] == 'menus'
  236. assert content['status'] == 'open'
  237. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  238. assert content['workspace_id'] == 1
  239. content = res[2]
  240. assert content['content_id'] == 11
  241. assert content['is_archived'] is False
  242. assert content['is_deleted'] is False
  243. assert content['label'] == 'Current Menu'
  244. assert content['parent_id'] == 2
  245. assert content['show_in_ui'] is True
  246. assert content['slug'] == 'current-menu'
  247. assert content['status'] == 'open'
  248. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  249. assert content['workspace_id'] == 1
  250. # Root related
  251. def test_api__get_workspace_content__ok_200__get_all_root_content__legacy_html_slug(self):
  252. """
  253. Check obtain workspace all root contents
  254. """
  255. set_html_document_slug_to_legacy(self.session_factory)
  256. params = {
  257. 'parent_id': 0,
  258. 'show_archived': 1,
  259. 'show_deleted': 1,
  260. 'show_active': 1,
  261. }
  262. self.testapp.authorization = (
  263. 'Basic',
  264. (
  265. 'bob@fsf.local',
  266. 'foobarbaz'
  267. )
  268. )
  269. res = self.testapp.get(
  270. '/api/v2/workspaces/3/contents',
  271. status=200,
  272. params=params,
  273. ).json_body # nopep8
  274. # TODO - G.M - 30-05-2018 - Check this test
  275. assert len(res) == 4
  276. content = res[1]
  277. assert content['content_type'] == 'html-documents'
  278. assert content['content_id'] == 15
  279. assert content['is_archived'] is False
  280. assert content['is_deleted'] is False
  281. assert content['label'] == 'New Fruit Salad'
  282. assert content['parent_id'] is None
  283. assert content['show_in_ui'] is True
  284. assert content['slug'] == 'new-fruit-salad'
  285. assert content['status'] == 'open'
  286. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  287. assert content['workspace_id'] == 3
  288. content = res[2]
  289. assert content['content_type'] == 'html-documents'
  290. assert content['content_id'] == 16
  291. assert content['is_archived'] is True
  292. assert content['is_deleted'] is False
  293. assert content['label'].startswith('Fruit Salad')
  294. assert content['parent_id'] is None
  295. assert content['show_in_ui'] is True
  296. assert content['slug'].startswith('fruit-salad')
  297. assert content['status'] == 'open'
  298. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  299. assert content['workspace_id'] == 3
  300. content = res[3]
  301. assert content['content_type'] == 'html-documents'
  302. assert content['content_id'] == 17
  303. assert content['is_archived'] is False
  304. assert content['is_deleted'] is True
  305. assert content['label'].startswith('Bad Fruit Salad')
  306. assert content['parent_id'] is None
  307. assert content['show_in_ui'] is True
  308. assert content['slug'].startswith('bad-fruit-salad')
  309. assert content['status'] == 'open'
  310. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  311. assert content['workspace_id'] == 3
  312. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  313. """
  314. Check obtain workspace all root contents
  315. """
  316. params = {
  317. 'parent_id': 0,
  318. 'show_archived': 1,
  319. 'show_deleted': 1,
  320. 'show_active': 1,
  321. }
  322. self.testapp.authorization = (
  323. 'Basic',
  324. (
  325. 'bob@fsf.local',
  326. 'foobarbaz'
  327. )
  328. )
  329. res = self.testapp.get(
  330. '/api/v2/workspaces/3/contents',
  331. status=200,
  332. params=params,
  333. ).json_body # nopep8
  334. # TODO - G.M - 30-05-2018 - Check this test
  335. assert len(res) == 4
  336. content = res[1]
  337. assert content['content_type'] == 'html-documents'
  338. assert content['content_id'] == 15
  339. assert content['is_archived'] is False
  340. assert content['is_deleted'] is False
  341. assert content['label'] == 'New Fruit Salad'
  342. assert content['parent_id'] is None
  343. assert content['show_in_ui'] is True
  344. assert content['slug'] == 'new-fruit-salad'
  345. assert content['status'] == 'open'
  346. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  347. assert content['workspace_id'] == 3
  348. content = res[2]
  349. assert content['content_type'] == 'html-documents'
  350. assert content['content_id'] == 16
  351. assert content['is_archived'] is True
  352. assert content['is_deleted'] is False
  353. assert content['label'].startswith('Fruit Salad')
  354. assert content['parent_id'] is None
  355. assert content['show_in_ui'] is True
  356. assert content['slug'].startswith('fruit-salad')
  357. assert content['status'] == 'open'
  358. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  359. assert content['workspace_id'] == 3
  360. content = res[3]
  361. assert content['content_type'] == 'html-documents'
  362. assert content['content_id'] == 17
  363. assert content['is_archived'] is False
  364. assert content['is_deleted'] is True
  365. assert content['label'].startswith('Bad Fruit Salad')
  366. assert content['parent_id'] is None
  367. assert content['show_in_ui'] is True
  368. assert content['slug'].startswith('bad-fruit-salad')
  369. assert content['status'] == 'open'
  370. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  371. assert content['workspace_id'] == 3
  372. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8
  373. """
  374. Check obtain workspace root active contents
  375. """
  376. params = {
  377. 'parent_id': 0,
  378. 'show_archived': 0,
  379. 'show_deleted': 0,
  380. 'show_active': 1,
  381. }
  382. self.testapp.authorization = (
  383. 'Basic',
  384. (
  385. 'bob@fsf.local',
  386. 'foobarbaz'
  387. )
  388. )
  389. res = self.testapp.get(
  390. '/api/v2/workspaces/3/contents',
  391. status=200,
  392. params=params,
  393. ).json_body # nopep8
  394. # TODO - G.M - 30-05-2018 - Check this test
  395. assert len(res) == 2
  396. content = res[1]
  397. assert content['content_type'] == 'html-documents'
  398. assert content['content_id'] == 15
  399. assert content['is_archived'] is False
  400. assert content['is_deleted'] is False
  401. assert content['label'] == 'New Fruit Salad'
  402. assert content['parent_id'] is None
  403. assert content['show_in_ui'] is True
  404. assert content['slug'] == 'new-fruit-salad'
  405. assert content['status'] == 'open'
  406. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  407. assert content['workspace_id'] == 3
  408. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8
  409. """
  410. Check obtain workspace root archived contents
  411. """
  412. params = {
  413. 'parent_id': 0,
  414. 'show_archived': 1,
  415. 'show_deleted': 0,
  416. 'show_active': 0,
  417. }
  418. self.testapp.authorization = (
  419. 'Basic',
  420. (
  421. 'bob@fsf.local',
  422. 'foobarbaz'
  423. )
  424. )
  425. res = self.testapp.get(
  426. '/api/v2/workspaces/3/contents',
  427. status=200,
  428. params=params,
  429. ).json_body # nopep8
  430. assert len(res) == 1
  431. content = res[0]
  432. assert content['content_type'] == 'html-documents'
  433. assert content['content_id'] == 16
  434. assert content['is_archived'] is True
  435. assert content['is_deleted'] is False
  436. assert content['label'].startswith('Fruit Salad')
  437. assert content['parent_id'] is None
  438. assert content['show_in_ui'] is True
  439. assert content['slug'].startswith('fruit-salad')
  440. assert content['status'] == 'open'
  441. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  442. assert content['workspace_id'] == 3
  443. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8
  444. """
  445. Check obtain workspace root deleted contents
  446. """
  447. params = {
  448. 'parent_id': 0,
  449. 'show_archived': 0,
  450. 'show_deleted': 1,
  451. 'show_active': 0,
  452. }
  453. self.testapp.authorization = (
  454. 'Basic',
  455. (
  456. 'bob@fsf.local',
  457. 'foobarbaz'
  458. )
  459. )
  460. res = self.testapp.get(
  461. '/api/v2/workspaces/3/contents',
  462. status=200,
  463. params=params,
  464. ).json_body # nopep8
  465. # TODO - G.M - 30-05-2018 - Check this test
  466. assert len(res) == 1
  467. content = res[0]
  468. assert content['content_type'] == 'html-documents'
  469. assert content['content_id'] == 17
  470. assert content['is_archived'] is False
  471. assert content['is_deleted'] is True
  472. assert content['label'].startswith('Bad Fruit Salad')
  473. assert content['parent_id'] is None
  474. assert content['show_in_ui'] is True
  475. assert content['slug'].startswith('bad-fruit-salad')
  476. assert content['status'] == 'open'
  477. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  478. assert content['workspace_id'] == 3
  479. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  480. """
  481. Check obtain workspace root content who does not match any type
  482. (archived, deleted, active) result should be empty list.
  483. """
  484. params = {
  485. 'parent_id': 0,
  486. 'show_archived': 0,
  487. 'show_deleted': 0,
  488. 'show_active': 0,
  489. }
  490. self.testapp.authorization = (
  491. 'Basic',
  492. (
  493. 'bob@fsf.local',
  494. 'foobarbaz'
  495. )
  496. )
  497. res = self.testapp.get(
  498. '/api/v2/workspaces/3/contents',
  499. status=200,
  500. params=params,
  501. ).json_body # nopep8
  502. # TODO - G.M - 30-05-2018 - Check this test
  503. assert res == []
  504. # Folder related
  505. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  506. """
  507. Check obtain workspace folder all contents
  508. """
  509. params = {
  510. 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id
  511. 'show_archived': 1,
  512. 'show_deleted': 1,
  513. 'show_active': 1,
  514. }
  515. self.testapp.authorization = (
  516. 'Basic',
  517. (
  518. 'admin@admin.admin',
  519. 'admin@admin.admin'
  520. )
  521. )
  522. res = self.testapp.get(
  523. '/api/v2/workspaces/2/contents',
  524. status=200,
  525. params=params,
  526. ).json_body # nopep8
  527. assert len(res) == 3
  528. content = res[0]
  529. assert content['content_type'] == 'html-documents'
  530. assert content['content_id'] == 12
  531. assert content['is_archived'] is False
  532. assert content['is_deleted'] is False
  533. assert content['label'] == 'New Fruit Salad'
  534. assert content['parent_id'] == 10
  535. assert content['show_in_ui'] is True
  536. assert content['slug'] == 'new-fruit-salad'
  537. assert content['status'] == 'open'
  538. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  539. assert content['workspace_id'] == 2
  540. content = res[1]
  541. assert content['content_type'] == 'html-documents'
  542. assert content['content_id'] == 13
  543. assert content['is_archived'] is True
  544. assert content['is_deleted'] is False
  545. assert content['label'].startswith('Fruit Salad')
  546. assert content['parent_id'] == 10
  547. assert content['show_in_ui'] is True
  548. assert content['slug'].startswith('fruit-salad')
  549. assert content['status'] == 'open'
  550. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  551. assert content['workspace_id'] == 2
  552. content = res[2]
  553. assert content['content_type'] == 'html-documents'
  554. assert content['content_id'] == 14
  555. assert content['is_archived'] is False
  556. assert content['is_deleted'] is True
  557. assert content['label'].startswith('Bad Fruit Salad')
  558. assert content['parent_id'] == 10
  559. assert content['show_in_ui'] is True
  560. assert content['slug'].startswith('bad-fruit-salad')
  561. assert content['status'] == 'open'
  562. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  563. assert content['workspace_id'] == 2
  564. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8
  565. """
  566. Check obtain workspace folder active contents
  567. """
  568. params = {
  569. 'parent_id': 10,
  570. 'show_archived': 0,
  571. 'show_deleted': 0,
  572. 'show_active': 1,
  573. }
  574. self.testapp.authorization = (
  575. 'Basic',
  576. (
  577. 'admin@admin.admin',
  578. 'admin@admin.admin'
  579. )
  580. )
  581. res = self.testapp.get(
  582. '/api/v2/workspaces/2/contents',
  583. status=200,
  584. params=params,
  585. ).json_body # nopep8
  586. assert len(res) == 1
  587. content = res[0]
  588. assert content['content_type']
  589. assert content['content_id'] == 12
  590. assert content['is_archived'] is False
  591. assert content['is_deleted'] is False
  592. assert content['label'] == 'New Fruit Salad'
  593. assert content['parent_id'] == 10
  594. assert content['show_in_ui'] is True
  595. assert content['slug'] == 'new-fruit-salad'
  596. assert content['status'] == 'open'
  597. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  598. assert content['workspace_id'] == 2
  599. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8
  600. """
  601. Check obtain workspace folder archived contents
  602. """
  603. params = {
  604. 'parent_id': 10,
  605. 'show_archived': 1,
  606. 'show_deleted': 0,
  607. 'show_active': 0,
  608. }
  609. self.testapp.authorization = (
  610. 'Basic',
  611. (
  612. 'admin@admin.admin',
  613. 'admin@admin.admin'
  614. )
  615. )
  616. res = self.testapp.get(
  617. '/api/v2/workspaces/2/contents',
  618. status=200,
  619. params=params,
  620. ).json_body # nopep8
  621. assert len(res) == 1
  622. content = res[0]
  623. assert content['content_type'] == 'html-documents'
  624. assert content['content_id'] == 13
  625. assert content['is_archived'] is True
  626. assert content['is_deleted'] is False
  627. assert content['label'].startswith('Fruit Salad')
  628. assert content['parent_id'] == 10
  629. assert content['show_in_ui'] is True
  630. assert content['slug'].startswith('fruit-salad')
  631. assert content['status'] == 'open'
  632. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  633. assert content['workspace_id'] == 2
  634. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8
  635. """
  636. Check obtain workspace folder deleted contents
  637. """
  638. params = {
  639. 'parent_id': 10,
  640. 'show_archived': 0,
  641. 'show_deleted': 1,
  642. 'show_active': 0,
  643. }
  644. self.testapp.authorization = (
  645. 'Basic',
  646. (
  647. 'admin@admin.admin',
  648. 'admin@admin.admin'
  649. )
  650. )
  651. res = self.testapp.get(
  652. '/api/v2/workspaces/2/contents',
  653. status=200,
  654. params=params,
  655. ).json_body # nopep8
  656. assert len(res) == 1
  657. content = res[0]
  658. assert content['content_type'] == 'html-documents'
  659. assert content['content_id'] == 14
  660. assert content['is_archived'] is False
  661. assert content['is_deleted'] is True
  662. assert content['label'].startswith('Bad Fruit Salad')
  663. assert content['parent_id'] == 10
  664. assert content['show_in_ui'] is True
  665. assert content['slug'].startswith('bad-fruit-salad')
  666. assert content['status'] == 'open'
  667. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  668. assert content['workspace_id'] == 2
  669. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8
  670. """
  671. Check obtain workspace folder content who does not match any type
  672. (archived, deleted, active) result should be empty list.
  673. """
  674. params = {
  675. 'parent_id': 10,
  676. 'show_archived': 0,
  677. 'show_deleted': 0,
  678. 'show_active': 0,
  679. }
  680. self.testapp.authorization = (
  681. 'Basic',
  682. (
  683. 'admin@admin.admin',
  684. 'admin@admin.admin'
  685. )
  686. )
  687. res = self.testapp.get(
  688. '/api/v2/workspaces/2/contents',
  689. status=200,
  690. params=params,
  691. ).json_body # nopep8
  692. # TODO - G.M - 30-05-2018 - Check this test
  693. assert res == []
  694. # Error case
  695. def test_api__get_workspace_content__err_400__unallowed_user(self):
  696. """
  697. Check obtain workspace content list with an unreachable workspace for
  698. user
  699. """
  700. self.testapp.authorization = (
  701. 'Basic',
  702. (
  703. 'lawrence-not-real-email@fsf.local',
  704. 'foobarbaz'
  705. )
  706. )
  707. res = self.testapp.get('/api/v2/workspaces/3/contents', status=400)
  708. assert isinstance(res.json, dict)
  709. assert 'code' in res.json.keys()
  710. assert 'message' in res.json.keys()
  711. assert 'details' in res.json.keys()
  712. def test_api__get_workspace_content__err_401__unregistered_user(self):
  713. """
  714. Check obtain workspace content list with an unregistered user
  715. """
  716. self.testapp.authorization = (
  717. 'Basic',
  718. (
  719. 'john@doe.doe',
  720. 'lapin'
  721. )
  722. )
  723. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  724. assert isinstance(res.json, dict)
  725. assert 'code' in res.json.keys()
  726. assert 'message' in res.json.keys()
  727. assert 'details' in res.json.keys()
  728. def test_api__get_workspace_content__err_400__workspace_does_not_exist(self): # nopep8
  729. """
  730. Check obtain workspace contents list with an existing user but
  731. an unexisting workspace
  732. """
  733. self.testapp.authorization = (
  734. 'Basic',
  735. (
  736. 'admin@admin.admin',
  737. 'admin@admin.admin'
  738. )
  739. )
  740. res = self.testapp.get('/api/v2/workspaces/5/contents', status=400)
  741. assert isinstance(res.json, dict)
  742. assert 'code' in res.json.keys()
  743. assert 'message' in res.json.keys()
  744. assert 'details' in res.json.keys()
  745. def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8
  746. """
  747. Create generic content
  748. """
  749. self.testapp.authorization = (
  750. 'Basic',
  751. (
  752. 'admin@admin.admin',
  753. 'admin@admin.admin'
  754. )
  755. )
  756. params = {
  757. 'label': 'GenericCreatedContent',
  758. 'content_type': 'markdownpage',
  759. }
  760. res = self.testapp.post_json(
  761. '/api/v2/workspaces/1/contents',
  762. params=params,
  763. status=200
  764. )
  765. assert res
  766. assert res.json_body
  767. assert res.json_body['status'] == 'open'
  768. assert res.json_body['content_id']
  769. assert res.json_body['content_type'] == 'markdownpage'
  770. assert res.json_body['is_archived'] is False
  771. assert res.json_body['is_deleted'] is False
  772. assert res.json_body['workspace_id'] == 1
  773. assert res.json_body['slug'] == 'genericcreatedcontent'
  774. assert res.json_body['parent_id'] is None
  775. assert res.json_body['show_in_ui'] is True
  776. assert res.json_body['sub_content_types']
  777. params_active = {
  778. 'parent_id': 0,
  779. 'show_archived': 0,
  780. 'show_deleted': 0,
  781. 'show_active': 1,
  782. }
  783. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  784. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  785. assert res.json_body in active_contents
  786. def test_api__post_content_create_generic_content__err_400__empty_label(self) -> None: # nopep8
  787. """
  788. Create generic content
  789. """
  790. self.testapp.authorization = (
  791. 'Basic',
  792. (
  793. 'admin@admin.admin',
  794. 'admin@admin.admin'
  795. )
  796. )
  797. params = {
  798. 'label': '',
  799. 'content_type': 'markdownpage',
  800. }
  801. res = self.testapp.post_json(
  802. '/api/v2/workspaces/1/contents',
  803. params=params,
  804. status=400
  805. )
  806. def test_api__post_content_create_generic_content__err_400__wrong_content_type(self) -> None: # nopep8
  807. """
  808. Create generic content
  809. """
  810. self.testapp.authorization = (
  811. 'Basic',
  812. (
  813. 'admin@admin.admin',
  814. 'admin@admin.admin'
  815. )
  816. )
  817. params = {
  818. 'label': 'GenericCreatedContent',
  819. 'content_type': 'unexistent-content-type',
  820. }
  821. res = self.testapp.post_json(
  822. '/api/v2/workspaces/1/contents',
  823. params=params,
  824. status=400,
  825. )
  826. def test_api_put_move_content__ok_200__nominal_case(self):
  827. """
  828. Move content
  829. move Apple_Pie (content_id: 8)
  830. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  831. of workspace Recipes.
  832. """
  833. self.testapp.authorization = (
  834. 'Basic',
  835. (
  836. 'admin@admin.admin',
  837. 'admin@admin.admin'
  838. )
  839. )
  840. params = {
  841. 'new_parent_id': '4', # Salads
  842. 'new_workspace_id': '2',
  843. }
  844. params_folder1 = {
  845. 'parent_id': 3,
  846. 'show_archived': 0,
  847. 'show_deleted': 0,
  848. 'show_active': 1,
  849. }
  850. params_folder2 = {
  851. 'parent_id': 4,
  852. 'show_archived': 0,
  853. 'show_deleted': 0,
  854. 'show_active': 1,
  855. }
  856. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  857. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  858. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  859. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  860. # TODO - G.M - 2018-06-163 - Check content
  861. res = self.testapp.put_json(
  862. '/api/v2/workspaces/2/contents/8/move',
  863. params=params,
  864. status=200
  865. )
  866. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  867. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  868. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  869. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  870. assert res.json_body
  871. assert res.json_body['parent_id'] == 4
  872. assert res.json_body['content_id'] == 8
  873. assert res.json_body['workspace_id'] == 2
  874. def test_api_put_move_content__ok_200__to_root(self):
  875. """
  876. Move content
  877. move Apple_Pie (content_id: 8)
  878. from Desserts folder(content_id: 3) to root (content_id: 0)
  879. of workspace Recipes.
  880. """
  881. self.testapp.authorization = (
  882. 'Basic',
  883. (
  884. 'admin@admin.admin',
  885. 'admin@admin.admin'
  886. )
  887. )
  888. params = {
  889. 'new_parent_id': None, # root
  890. 'new_workspace_id': 2,
  891. }
  892. params_folder1 = {
  893. 'parent_id': 3,
  894. 'show_archived': 0,
  895. 'show_deleted': 0,
  896. 'show_active': 1,
  897. }
  898. params_folder2 = {
  899. 'parent_id': 0,
  900. 'show_archived': 0,
  901. 'show_deleted': 0,
  902. 'show_active': 1,
  903. }
  904. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  905. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  906. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  907. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  908. # TODO - G.M - 2018-06-163 - Check content
  909. res = self.testapp.put_json(
  910. '/api/v2/workspaces/2/contents/8/move',
  911. params=params,
  912. status=200
  913. )
  914. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  915. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  916. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  917. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  918. assert res.json_body
  919. assert res.json_body['parent_id'] is None
  920. assert res.json_body['content_id'] == 8
  921. assert res.json_body['workspace_id'] == 2
  922. def test_api_put_move_content__ok_200__with_workspace_id(self):
  923. """
  924. Move content
  925. move Apple_Pie (content_id: 8)
  926. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  927. of workspace Recipes.
  928. """
  929. self.testapp.authorization = (
  930. 'Basic',
  931. (
  932. 'admin@admin.admin',
  933. 'admin@admin.admin'
  934. )
  935. )
  936. params = {
  937. 'new_parent_id': '4', # Salads
  938. 'new_workspace_id': '2',
  939. }
  940. params_folder1 = {
  941. 'parent_id': 3,
  942. 'show_archived': 0,
  943. 'show_deleted': 0,
  944. 'show_active': 1,
  945. }
  946. params_folder2 = {
  947. 'parent_id': 4,
  948. 'show_archived': 0,
  949. 'show_deleted': 0,
  950. 'show_active': 1,
  951. }
  952. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  953. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  954. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  955. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  956. # TODO - G.M - 2018-06-163 - Check content
  957. res = self.testapp.put_json(
  958. '/api/v2/workspaces/2/contents/8/move',
  959. params=params,
  960. status=200
  961. )
  962. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  963. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  964. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  965. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  966. assert res.json_body
  967. assert res.json_body['parent_id'] == 4
  968. assert res.json_body['content_id'] == 8
  969. assert res.json_body['workspace_id'] == 2
  970. def test_api_put_move_content__ok_200__to_another_workspace(self):
  971. """
  972. Move content
  973. move Apple_Pie (content_id: 8)
  974. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  975. of workspace Business.
  976. """
  977. self.testapp.authorization = (
  978. 'Basic',
  979. (
  980. 'admin@admin.admin',
  981. 'admin@admin.admin'
  982. )
  983. )
  984. params = {
  985. 'new_parent_id': '2', # Menus
  986. 'new_workspace_id': '1',
  987. }
  988. params_folder1 = {
  989. 'parent_id': 3,
  990. 'show_archived': 0,
  991. 'show_deleted': 0,
  992. 'show_active': 1,
  993. }
  994. params_folder2 = {
  995. 'parent_id': 2,
  996. 'show_archived': 0,
  997. 'show_deleted': 0,
  998. 'show_active': 1,
  999. }
  1000. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1001. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1002. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1003. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1004. # TODO - G.M - 2018-06-163 - Check content
  1005. res = self.testapp.put_json(
  1006. '/api/v2/workspaces/2/contents/8/move',
  1007. params=params,
  1008. status=200
  1009. )
  1010. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1011. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1012. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1013. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1014. assert res.json_body
  1015. assert res.json_body['parent_id'] == 2
  1016. assert res.json_body['content_id'] == 8
  1017. assert res.json_body['workspace_id'] == 1
  1018. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  1019. """
  1020. Move content
  1021. move Apple_Pie (content_id: 8)
  1022. from Desserts folder(content_id: 3) to root (content_id: 0)
  1023. of workspace Business.
  1024. """
  1025. self.testapp.authorization = (
  1026. 'Basic',
  1027. (
  1028. 'admin@admin.admin',
  1029. 'admin@admin.admin'
  1030. )
  1031. )
  1032. params = {
  1033. 'new_parent_id': None, # root
  1034. 'new_workspace_id': '1',
  1035. }
  1036. params_folder1 = {
  1037. 'parent_id': 3,
  1038. 'show_archived': 0,
  1039. 'show_deleted': 0,
  1040. 'show_active': 1,
  1041. }
  1042. params_folder2 = {
  1043. 'parent_id': 0,
  1044. 'show_archived': 0,
  1045. 'show_deleted': 0,
  1046. 'show_active': 1,
  1047. }
  1048. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1049. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1050. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1051. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1052. # TODO - G.M - 2018-06-163 - Check content
  1053. res = self.testapp.put_json(
  1054. '/api/v2/workspaces/2/contents/8/move',
  1055. params=params,
  1056. status=200
  1057. )
  1058. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1059. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1060. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1061. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1062. assert res.json_body
  1063. assert res.json_body['parent_id'] is None
  1064. assert res.json_body['content_id'] == 8
  1065. assert res.json_body['workspace_id'] == 1
  1066. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  1067. """
  1068. Move content
  1069. move Apple_Pie (content_id: 8)
  1070. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1071. of workspace Recipes.
  1072. Workspace_id of parent_id don't match with workspace_id of workspace
  1073. """
  1074. self.testapp.authorization = (
  1075. 'Basic',
  1076. (
  1077. 'admin@admin.admin',
  1078. 'admin@admin.admin'
  1079. )
  1080. )
  1081. params = {
  1082. 'new_parent_id': '4', # Salads
  1083. 'new_workspace_id': '1',
  1084. }
  1085. params_folder1 = {
  1086. 'parent_id': 3,
  1087. 'show_archived': 0,
  1088. 'show_deleted': 0,
  1089. 'show_active': 1,
  1090. }
  1091. params_folder2 = {
  1092. 'parent_id': 4,
  1093. 'show_archived': 0,
  1094. 'show_deleted': 0,
  1095. 'show_active': 1,
  1096. }
  1097. res = self.testapp.put_json(
  1098. '/api/v2/workspaces/2/contents/8/move',
  1099. params=params,
  1100. status=400,
  1101. )
  1102. def test_api_put_delete_content__ok_200__nominal_case(self):
  1103. """
  1104. delete content
  1105. delete Apple_pie ( content_id: 8, parent_id: 3)
  1106. """
  1107. self.testapp.authorization = (
  1108. 'Basic',
  1109. (
  1110. 'admin@admin.admin',
  1111. 'admin@admin.admin'
  1112. )
  1113. )
  1114. params_active = {
  1115. 'parent_id': 3,
  1116. 'show_archived': 0,
  1117. 'show_deleted': 0,
  1118. 'show_active': 1,
  1119. }
  1120. params_deleted = {
  1121. 'parent_id': 3,
  1122. 'show_archived': 0,
  1123. 'show_deleted': 1,
  1124. 'show_active': 0,
  1125. }
  1126. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1127. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1128. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1129. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1130. # TODO - G.M - 2018-06-163 - Check content
  1131. res = self.testapp.put_json(
  1132. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1133. '/api/v2/workspaces/2/contents/8/delete',
  1134. status=204
  1135. )
  1136. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1137. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1138. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1139. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1140. def test_api_put_archive_content__ok_200__nominal_case(self):
  1141. """
  1142. archive content
  1143. archive Apple_pie ( content_id: 8, parent_id: 3)
  1144. """
  1145. self.testapp.authorization = (
  1146. 'Basic',
  1147. (
  1148. 'admin@admin.admin',
  1149. 'admin@admin.admin'
  1150. )
  1151. )
  1152. params_active = {
  1153. 'parent_id': 3,
  1154. 'show_archived': 0,
  1155. 'show_deleted': 0,
  1156. 'show_active': 1,
  1157. }
  1158. params_archived = {
  1159. 'parent_id': 3,
  1160. 'show_archived': 1,
  1161. 'show_deleted': 0,
  1162. 'show_active': 0,
  1163. }
  1164. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1165. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1166. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1167. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1168. res = self.testapp.put_json(
  1169. '/api/v2/workspaces/2/contents/8/archive',
  1170. status=204
  1171. )
  1172. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1173. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1174. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1175. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1176. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1177. """
  1178. Undelete content
  1179. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1180. """
  1181. self.testapp.authorization = (
  1182. 'Basic',
  1183. (
  1184. 'bob@fsf.local',
  1185. 'foobarbaz'
  1186. )
  1187. )
  1188. params_active = {
  1189. 'parent_id': 10,
  1190. 'show_archived': 0,
  1191. 'show_deleted': 0,
  1192. 'show_active': 1,
  1193. }
  1194. params_deleted = {
  1195. 'parent_id': 10,
  1196. 'show_archived': 0,
  1197. 'show_deleted': 1,
  1198. 'show_active': 0,
  1199. }
  1200. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1201. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1202. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1203. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1204. res = self.testapp.put_json(
  1205. '/api/v2/workspaces/2/contents/14/undelete',
  1206. status=204
  1207. )
  1208. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1209. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1210. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1211. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1212. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1213. """
  1214. unarchive content,
  1215. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1216. """
  1217. self.testapp.authorization = (
  1218. 'Basic',
  1219. (
  1220. 'bob@fsf.local',
  1221. 'foobarbaz'
  1222. )
  1223. )
  1224. params_active = {
  1225. 'parent_id': 10,
  1226. 'show_archived': 0,
  1227. 'show_deleted': 0,
  1228. 'show_active': 1,
  1229. }
  1230. params_archived = {
  1231. 'parent_id': 10,
  1232. 'show_archived': 1,
  1233. 'show_deleted': 0,
  1234. 'show_active': 0,
  1235. }
  1236. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1237. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1238. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  1239. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  1240. res = self.testapp.put_json(
  1241. '/api/v2/workspaces/2/contents/13/unarchive',
  1242. status=204
  1243. )
  1244. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1245. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1246. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  1247. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8