test_workspaces.py 50KB

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