test_workspaces.py 49KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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_put_move_content__ok_200__nominal_case(self):
  787. """
  788. Move content
  789. move Apple_Pie (content_id: 8)
  790. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  791. of workspace Recipes.
  792. """
  793. self.testapp.authorization = (
  794. 'Basic',
  795. (
  796. 'admin@admin.admin',
  797. 'admin@admin.admin'
  798. )
  799. )
  800. params = {
  801. 'new_parent_id': '4', # Salads
  802. 'new_workspace_id': '2',
  803. }
  804. params_folder1 = {
  805. 'parent_id': 3,
  806. 'show_archived': 0,
  807. 'show_deleted': 0,
  808. 'show_active': 1,
  809. }
  810. params_folder2 = {
  811. 'parent_id': 4,
  812. 'show_archived': 0,
  813. 'show_deleted': 0,
  814. 'show_active': 1,
  815. }
  816. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  817. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  818. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  819. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  820. # TODO - G.M - 2018-06-163 - Check content
  821. res = self.testapp.put_json(
  822. '/api/v2/workspaces/2/contents/8/move',
  823. params=params,
  824. status=200
  825. )
  826. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  827. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  828. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  829. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  830. assert res.json_body
  831. assert res.json_body['parent_id'] == 4
  832. assert res.json_body['content_id'] == 8
  833. assert res.json_body['workspace_id'] == 2
  834. def test_api_put_move_content__ok_200__to_root(self):
  835. """
  836. Move content
  837. move Apple_Pie (content_id: 8)
  838. from Desserts folder(content_id: 3) to root (content_id: 0)
  839. of workspace Recipes.
  840. """
  841. self.testapp.authorization = (
  842. 'Basic',
  843. (
  844. 'admin@admin.admin',
  845. 'admin@admin.admin'
  846. )
  847. )
  848. params = {
  849. 'new_parent_id': None, # root
  850. 'new_workspace_id': 2,
  851. }
  852. params_folder1 = {
  853. 'parent_id': 3,
  854. 'show_archived': 0,
  855. 'show_deleted': 0,
  856. 'show_active': 1,
  857. }
  858. params_folder2 = {
  859. 'parent_id': 0,
  860. 'show_archived': 0,
  861. 'show_deleted': 0,
  862. 'show_active': 1,
  863. }
  864. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  865. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  866. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  867. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  868. # TODO - G.M - 2018-06-163 - Check content
  869. res = self.testapp.put_json(
  870. '/api/v2/workspaces/2/contents/8/move',
  871. params=params,
  872. status=200
  873. )
  874. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  875. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  876. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  877. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  878. assert res.json_body
  879. assert res.json_body['parent_id'] is None
  880. assert res.json_body['content_id'] == 8
  881. assert res.json_body['workspace_id'] == 2
  882. def test_api_put_move_content__ok_200__with_workspace_id(self):
  883. """
  884. Move content
  885. move Apple_Pie (content_id: 8)
  886. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  887. of workspace Recipes.
  888. """
  889. self.testapp.authorization = (
  890. 'Basic',
  891. (
  892. 'admin@admin.admin',
  893. 'admin@admin.admin'
  894. )
  895. )
  896. params = {
  897. 'new_parent_id': '4', # Salads
  898. 'new_workspace_id': '2',
  899. }
  900. params_folder1 = {
  901. 'parent_id': 3,
  902. 'show_archived': 0,
  903. 'show_deleted': 0,
  904. 'show_active': 1,
  905. }
  906. params_folder2 = {
  907. 'parent_id': 4,
  908. 'show_archived': 0,
  909. 'show_deleted': 0,
  910. 'show_active': 1,
  911. }
  912. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  913. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  914. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  915. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  916. # TODO - G.M - 2018-06-163 - Check content
  917. res = self.testapp.put_json(
  918. '/api/v2/workspaces/2/contents/8/move',
  919. params=params,
  920. status=200
  921. )
  922. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  923. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  924. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  925. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  926. assert res.json_body
  927. assert res.json_body['parent_id'] == 4
  928. assert res.json_body['content_id'] == 8
  929. assert res.json_body['workspace_id'] == 2
  930. def test_api_put_move_content__ok_200__to_another_workspace(self):
  931. """
  932. Move content
  933. move Apple_Pie (content_id: 8)
  934. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  935. of workspace Business.
  936. """
  937. self.testapp.authorization = (
  938. 'Basic',
  939. (
  940. 'admin@admin.admin',
  941. 'admin@admin.admin'
  942. )
  943. )
  944. params = {
  945. 'new_parent_id': '2', # Menus
  946. 'new_workspace_id': '1',
  947. }
  948. params_folder1 = {
  949. 'parent_id': 3,
  950. 'show_archived': 0,
  951. 'show_deleted': 0,
  952. 'show_active': 1,
  953. }
  954. params_folder2 = {
  955. 'parent_id': 2,
  956. 'show_archived': 0,
  957. 'show_deleted': 0,
  958. 'show_active': 1,
  959. }
  960. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  961. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  962. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  963. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  964. # TODO - G.M - 2018-06-163 - Check content
  965. res = self.testapp.put_json(
  966. '/api/v2/workspaces/2/contents/8/move',
  967. params=params,
  968. status=200
  969. )
  970. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  971. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  972. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  973. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  974. assert res.json_body
  975. assert res.json_body['parent_id'] == 2
  976. assert res.json_body['content_id'] == 8
  977. assert res.json_body['workspace_id'] == 1
  978. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  979. """
  980. Move content
  981. move Apple_Pie (content_id: 8)
  982. from Desserts folder(content_id: 3) to root (content_id: 0)
  983. of workspace Business.
  984. """
  985. self.testapp.authorization = (
  986. 'Basic',
  987. (
  988. 'admin@admin.admin',
  989. 'admin@admin.admin'
  990. )
  991. )
  992. params = {
  993. 'new_parent_id': None, # root
  994. 'new_workspace_id': '1',
  995. }
  996. params_folder1 = {
  997. 'parent_id': 3,
  998. 'show_archived': 0,
  999. 'show_deleted': 0,
  1000. 'show_active': 1,
  1001. }
  1002. params_folder2 = {
  1003. 'parent_id': 0,
  1004. 'show_archived': 0,
  1005. 'show_deleted': 0,
  1006. 'show_active': 1,
  1007. }
  1008. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1009. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1010. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1011. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1012. # TODO - G.M - 2018-06-163 - Check content
  1013. res = self.testapp.put_json(
  1014. '/api/v2/workspaces/2/contents/8/move',
  1015. params=params,
  1016. status=200
  1017. )
  1018. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1019. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1020. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1021. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1022. assert res.json_body
  1023. assert res.json_body['parent_id'] is None
  1024. assert res.json_body['content_id'] == 8
  1025. assert res.json_body['workspace_id'] == 1
  1026. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  1027. """
  1028. Move content
  1029. move Apple_Pie (content_id: 8)
  1030. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1031. of workspace Recipes.
  1032. Workspace_id of parent_id don't match with workspace_id of workspace
  1033. """
  1034. self.testapp.authorization = (
  1035. 'Basic',
  1036. (
  1037. 'admin@admin.admin',
  1038. 'admin@admin.admin'
  1039. )
  1040. )
  1041. params = {
  1042. 'new_parent_id': '4', # Salads
  1043. 'new_workspace_id': '1',
  1044. }
  1045. params_folder1 = {
  1046. 'parent_id': 3,
  1047. 'show_archived': 0,
  1048. 'show_deleted': 0,
  1049. 'show_active': 1,
  1050. }
  1051. params_folder2 = {
  1052. 'parent_id': 4,
  1053. 'show_archived': 0,
  1054. 'show_deleted': 0,
  1055. 'show_active': 1,
  1056. }
  1057. res = self.testapp.put_json(
  1058. '/api/v2/workspaces/2/contents/8/move',
  1059. params=params,
  1060. status=400,
  1061. )
  1062. def test_api_put_delete_content__ok_200__nominal_case(self):
  1063. """
  1064. delete content
  1065. delete Apple_pie ( content_id: 8, parent_id: 3)
  1066. """
  1067. self.testapp.authorization = (
  1068. 'Basic',
  1069. (
  1070. 'admin@admin.admin',
  1071. 'admin@admin.admin'
  1072. )
  1073. )
  1074. params_active = {
  1075. 'parent_id': 3,
  1076. 'show_archived': 0,
  1077. 'show_deleted': 0,
  1078. 'show_active': 1,
  1079. }
  1080. params_deleted = {
  1081. 'parent_id': 3,
  1082. 'show_archived': 0,
  1083. 'show_deleted': 1,
  1084. 'show_active': 0,
  1085. }
  1086. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1087. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1088. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1089. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1090. # TODO - G.M - 2018-06-163 - Check content
  1091. res = self.testapp.put_json(
  1092. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1093. '/api/v2/workspaces/2/contents/8/delete',
  1094. status=204
  1095. )
  1096. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1097. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1098. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1099. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1100. def test_api_put_archive_content__ok_200__nominal_case(self):
  1101. """
  1102. archive content
  1103. archive Apple_pie ( content_id: 8, parent_id: 3)
  1104. """
  1105. self.testapp.authorization = (
  1106. 'Basic',
  1107. (
  1108. 'admin@admin.admin',
  1109. 'admin@admin.admin'
  1110. )
  1111. )
  1112. params_active = {
  1113. 'parent_id': 3,
  1114. 'show_archived': 0,
  1115. 'show_deleted': 0,
  1116. 'show_active': 1,
  1117. }
  1118. params_archived = {
  1119. 'parent_id': 3,
  1120. 'show_archived': 1,
  1121. 'show_deleted': 0,
  1122. 'show_active': 0,
  1123. }
  1124. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1125. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1126. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1127. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1128. res = self.testapp.put_json(
  1129. '/api/v2/workspaces/2/contents/8/archive',
  1130. status=204
  1131. )
  1132. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1133. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1134. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1135. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1136. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1137. """
  1138. Undelete content
  1139. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1140. """
  1141. self.testapp.authorization = (
  1142. 'Basic',
  1143. (
  1144. 'bob@fsf.local',
  1145. 'foobarbaz'
  1146. )
  1147. )
  1148. params_active = {
  1149. 'parent_id': 10,
  1150. 'show_archived': 0,
  1151. 'show_deleted': 0,
  1152. 'show_active': 1,
  1153. }
  1154. params_deleted = {
  1155. 'parent_id': 10,
  1156. 'show_archived': 0,
  1157. 'show_deleted': 1,
  1158. 'show_active': 0,
  1159. }
  1160. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1161. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1162. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1163. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1164. res = self.testapp.put_json(
  1165. '/api/v2/workspaces/2/contents/14/undelete',
  1166. status=204
  1167. )
  1168. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1169. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1170. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1171. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1172. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1173. """
  1174. unarchive content,
  1175. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1176. """
  1177. self.testapp.authorization = (
  1178. 'Basic',
  1179. (
  1180. 'bob@fsf.local',
  1181. 'foobarbaz'
  1182. )
  1183. )
  1184. params_active = {
  1185. 'parent_id': 10,
  1186. 'show_archived': 0,
  1187. 'show_deleted': 0,
  1188. 'show_active': 1,
  1189. }
  1190. params_archived = {
  1191. 'parent_id': 10,
  1192. 'show_archived': 1,
  1193. 'show_deleted': 0,
  1194. 'show_active': 0,
  1195. }
  1196. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1197. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1198. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  1199. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  1200. res = self.testapp.put_json(
  1201. '/api/v2/workspaces/2/contents/13/unarchive',
  1202. status=204
  1203. )
  1204. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1205. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1206. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  1207. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8