test_workspaces.py 52KB

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