test_workspaces.py 52KB

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