test_workspaces.py 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for /api/v2/workspaces subpath endpoints.
  4. """
  5. from tracim.tests import FunctionalTest
  6. from tracim.fixtures.content import Content as ContentFixtures
  7. from tracim.fixtures.users_and_groups import Base as BaseFixture
  8. class TestWorkspaceEndpoint(FunctionalTest):
  9. """
  10. Tests for /api/v2/workspaces/{workspace_id} endpoint
  11. """
  12. fixtures = [BaseFixture, ContentFixtures]
  13. def test_api__get_workspace__ok_200__nominal_case(self) -> None:
  14. """
  15. Check obtain workspace reachable for user.
  16. """
  17. self.testapp.authorization = (
  18. 'Basic',
  19. (
  20. 'admin@admin.admin',
  21. 'admin@admin.admin'
  22. )
  23. )
  24. res = self.testapp.get('/api/v2/workspaces/1', status=200)
  25. workspace = res.json_body
  26. assert workspace['workspace_id'] == 1
  27. assert workspace['slug'] == 'business'
  28. assert workspace['label'] == 'Business'
  29. assert workspace['description'] == 'All importants documents'
  30. assert len(workspace['sidebar_entries']) == 7
  31. sidebar_entry = workspace['sidebar_entries'][0]
  32. assert sidebar_entry['slug'] == 'dashboard'
  33. assert sidebar_entry['label'] == 'Dashboard'
  34. assert sidebar_entry['route'] == '/#/workspaces/1/dashboard' # nopep8
  35. assert sidebar_entry['hexcolor'] == "#252525"
  36. assert sidebar_entry['fa_icon'] == ""
  37. sidebar_entry = workspace['sidebar_entries'][1]
  38. assert sidebar_entry['slug'] == 'contents/all'
  39. assert sidebar_entry['label'] == 'All Contents'
  40. assert sidebar_entry['route'] == "/#/workspaces/1/contents" # nopep8
  41. assert sidebar_entry['hexcolor'] == "#fdfdfd"
  42. assert sidebar_entry['fa_icon'] == ""
  43. sidebar_entry = workspace['sidebar_entries'][2]
  44. assert sidebar_entry['slug'] == 'contents/htmlpage'
  45. assert sidebar_entry['label'] == 'Text Documents'
  46. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=htmlpage' # nopep8
  47. assert sidebar_entry['hexcolor'] == "#3f52e3"
  48. assert sidebar_entry['fa_icon'] == "file-text-o"
  49. sidebar_entry = workspace['sidebar_entries'][3]
  50. assert sidebar_entry['slug'] == 'contents/markdownpluspage'
  51. assert sidebar_entry['label'] == 'Markdown Plus Documents'
  52. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=markdownpluspage" # nopep8
  53. assert sidebar_entry['hexcolor'] == "#f12d2d"
  54. assert sidebar_entry['fa_icon'] == "file-code"
  55. sidebar_entry = workspace['sidebar_entries'][4]
  56. assert sidebar_entry['slug'] == 'contents/files'
  57. assert sidebar_entry['label'] == 'Files'
  58. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file" # nopep8
  59. assert sidebar_entry['hexcolor'] == "#FF9900"
  60. assert sidebar_entry['fa_icon'] == "paperclip"
  61. sidebar_entry = workspace['sidebar_entries'][5]
  62. assert sidebar_entry['slug'] == 'contents/threads'
  63. assert sidebar_entry['label'] == 'Threads'
  64. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread" # nopep8
  65. assert sidebar_entry['hexcolor'] == "#ad4cf9"
  66. assert sidebar_entry['fa_icon'] == "comments-o"
  67. sidebar_entry = workspace['sidebar_entries'][6]
  68. assert sidebar_entry['slug'] == 'calendar'
  69. assert sidebar_entry['label'] == 'Calendar'
  70. assert sidebar_entry['route'] == "/#/workspaces/1/calendar" # nopep8
  71. assert sidebar_entry['hexcolor'] == "#757575"
  72. assert sidebar_entry['fa_icon'] == "calendar-alt"
  73. def test_api__get_workspace__err_403__unallowed_user(self) -> None:
  74. """
  75. Check obtain workspace unreachable for user
  76. """
  77. self.testapp.authorization = (
  78. 'Basic',
  79. (
  80. 'lawrence-not-real-email@fsf.local',
  81. 'foobarbaz'
  82. )
  83. )
  84. res = self.testapp.get('/api/v2/workspaces/1', status=403)
  85. assert isinstance(res.json, dict)
  86. assert 'code' in res.json.keys()
  87. assert 'message' in res.json.keys()
  88. assert 'details' in res.json.keys()
  89. def test_api__get_workspace__err_401__unregistered_user(self) -> None:
  90. """
  91. Check obtain workspace without registered user.
  92. """
  93. self.testapp.authorization = (
  94. 'Basic',
  95. (
  96. 'john@doe.doe',
  97. 'lapin'
  98. )
  99. )
  100. res = self.testapp.get('/api/v2/workspaces/1', status=401)
  101. assert isinstance(res.json, dict)
  102. assert 'code' in res.json.keys()
  103. assert 'message' in res.json.keys()
  104. assert 'details' in res.json.keys()
  105. def test_api__get_workspace__err_403__workspace_does_not_exist(self) -> None: # nopep8
  106. """
  107. Check obtain workspace who does not exist with an existing user.
  108. """
  109. self.testapp.authorization = (
  110. 'Basic',
  111. (
  112. 'admin@admin.admin',
  113. 'admin@admin.admin'
  114. )
  115. )
  116. res = self.testapp.get('/api/v2/workspaces/5', status=403)
  117. assert isinstance(res.json, dict)
  118. assert 'code' in res.json.keys()
  119. assert 'message' in res.json.keys()
  120. assert 'details' in res.json.keys()
  121. class TestWorkspaceMembersEndpoint(FunctionalTest):
  122. """
  123. Tests for /api/v2/workspaces/{workspace_id}/members endpoint
  124. """
  125. fixtures = [BaseFixture, ContentFixtures]
  126. def test_api__get_workspace_members__ok_200__nominal_case(self):
  127. """
  128. Check obtain workspace members list with a reachable workspace for user
  129. """
  130. self.testapp.authorization = (
  131. 'Basic',
  132. (
  133. 'admin@admin.admin',
  134. 'admin@admin.admin'
  135. )
  136. )
  137. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  138. assert len(res) == 1
  139. user_role = res[0]
  140. assert user_role['role'] == 'workspace-manager'
  141. assert user_role['user_id'] == 1
  142. assert user_role['workspace_id'] == 1
  143. assert user_role['user']['public_name'] == 'Global manager'
  144. # TODO - G.M - 24-05-2018 - [Avatar] Replace
  145. # by correct value when avatar feature will be enabled
  146. assert user_role['user']['avatar_url'] is None
  147. def test_api__get_workspace_members__err_403__unallowed_user(self):
  148. """
  149. Check obtain workspace members list with an unreachable workspace for
  150. user
  151. """
  152. self.testapp.authorization = (
  153. 'Basic',
  154. (
  155. 'lawrence-not-real-email@fsf.local',
  156. 'foobarbaz'
  157. )
  158. )
  159. res = self.testapp.get('/api/v2/workspaces/3/members', status=403)
  160. assert isinstance(res.json, dict)
  161. assert 'code' in res.json.keys()
  162. assert 'message' in res.json.keys()
  163. assert 'details' in res.json.keys()
  164. def test_api__get_workspace_members__err_401__unregistered_user(self):
  165. """
  166. Check obtain workspace members list with an unregistered user
  167. """
  168. self.testapp.authorization = (
  169. 'Basic',
  170. (
  171. 'john@doe.doe',
  172. 'lapin'
  173. )
  174. )
  175. res = self.testapp.get('/api/v2/workspaces/1/members', status=401)
  176. assert isinstance(res.json, dict)
  177. assert 'code' in res.json.keys()
  178. assert 'message' in res.json.keys()
  179. assert 'details' in res.json.keys()
  180. def test_api__get_workspace_members__err_403__workspace_does_not_exist(self): # nopep8
  181. """
  182. Check obtain workspace members list with an existing user but
  183. an unexisting workspace
  184. """
  185. self.testapp.authorization = (
  186. 'Basic',
  187. (
  188. 'admin@admin.admin',
  189. 'admin@admin.admin'
  190. )
  191. )
  192. res = self.testapp.get('/api/v2/workspaces/5/members', status=403)
  193. assert isinstance(res.json, dict)
  194. assert 'code' in res.json.keys()
  195. assert 'message' in res.json.keys()
  196. assert 'details' in res.json.keys()
  197. class TestWorkspaceContents(FunctionalTest):
  198. """
  199. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  200. """
  201. fixtures = [BaseFixture, ContentFixtures]
  202. def test_api__get_workspace_content__ok_200__get_default(self):
  203. """
  204. Check obtain workspace contents with defaults filters
  205. """
  206. self.testapp.authorization = (
  207. 'Basic',
  208. (
  209. 'admin@admin.admin',
  210. 'admin@admin.admin'
  211. )
  212. )
  213. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  214. # TODO - G.M - 30-05-2018 - Check this test
  215. assert len(res) == 3
  216. content = res[0]
  217. assert content['content_id'] == 1
  218. assert content['is_archived'] is False
  219. assert content['is_deleted'] is False
  220. assert content['label'] == 'Tools'
  221. assert content['parent_id'] is None
  222. assert content['show_in_ui'] is True
  223. assert content['slug'] == 'tools'
  224. assert content['status'] == 'open'
  225. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  226. assert content['workspace_id'] == 1
  227. content = res[1]
  228. assert content['content_id'] == 2
  229. assert content['is_archived'] is False
  230. assert content['is_deleted'] is False
  231. assert content['label'] == 'Menus'
  232. assert content['parent_id'] is None
  233. assert content['show_in_ui'] is True
  234. assert content['slug'] == 'menus'
  235. assert content['status'] == 'open'
  236. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  237. assert content['workspace_id'] == 1
  238. content = res[2]
  239. assert content['content_id'] == 11
  240. assert content['is_archived'] is False
  241. assert content['is_deleted'] is False
  242. assert content['label'] == 'Current Menu'
  243. assert content['parent_id'] == 2
  244. assert content['show_in_ui'] is True
  245. assert content['slug'] == 'current-menu'
  246. assert content['status'] == 'open'
  247. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  248. assert content['workspace_id'] == 1
  249. # Root related
  250. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  251. """
  252. Check obtain workspace all root contents
  253. """
  254. params = {
  255. 'parent_id': 0,
  256. 'show_archived': 1,
  257. 'show_deleted': 1,
  258. 'show_active': 1,
  259. }
  260. self.testapp.authorization = (
  261. 'Basic',
  262. (
  263. 'bob@fsf.local',
  264. 'foobarbaz'
  265. )
  266. )
  267. res = self.testapp.get(
  268. '/api/v2/workspaces/3/contents',
  269. status=200,
  270. params=params,
  271. ).json_body # nopep8
  272. # TODO - G.M - 30-05-2018 - Check this test
  273. assert len(res) == 4
  274. content = res[1]
  275. assert content['content_type'] == 'page'
  276. assert content['content_id'] == 15
  277. assert content['is_archived'] is False
  278. assert content['is_deleted'] is False
  279. assert content['label'] == 'New Fruit Salad'
  280. assert content['parent_id'] is None
  281. assert content['show_in_ui'] is True
  282. assert content['slug'] == 'new-fruit-salad'
  283. assert content['status'] == 'open'
  284. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  285. assert content['workspace_id'] == 3
  286. content = res[2]
  287. assert content['content_type'] == 'page'
  288. assert content['content_id'] == 16
  289. assert content['is_archived'] is True
  290. assert content['is_deleted'] is False
  291. assert content['label'].startswith('Fruit Salad')
  292. assert content['parent_id'] is None
  293. assert content['show_in_ui'] is True
  294. assert content['slug'].startswith('fruit-salad')
  295. assert content['status'] == 'open'
  296. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  297. assert content['workspace_id'] == 3
  298. content = res[3]
  299. assert content['content_type'] == 'page'
  300. assert content['content_id'] == 17
  301. assert content['is_archived'] is False
  302. assert content['is_deleted'] is True
  303. assert content['label'].startswith('Bad Fruit Salad')
  304. assert content['parent_id'] is None
  305. assert content['show_in_ui'] is True
  306. assert content['slug'].startswith('bad-fruit-salad')
  307. assert content['status'] == 'open'
  308. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  309. assert content['workspace_id'] == 3
  310. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8
  311. """
  312. Check obtain workspace root active contents
  313. """
  314. params = {
  315. 'parent_id': 0,
  316. 'show_archived': 0,
  317. 'show_deleted': 0,
  318. 'show_active': 1,
  319. }
  320. self.testapp.authorization = (
  321. 'Basic',
  322. (
  323. 'bob@fsf.local',
  324. 'foobarbaz'
  325. )
  326. )
  327. res = self.testapp.get(
  328. '/api/v2/workspaces/3/contents',
  329. status=200,
  330. params=params,
  331. ).json_body # nopep8
  332. # TODO - G.M - 30-05-2018 - Check this test
  333. assert len(res) == 2
  334. content = res[1]
  335. assert content['content_type'] == 'page'
  336. assert content['content_id'] == 15
  337. assert content['is_archived'] is False
  338. assert content['is_deleted'] is False
  339. assert content['label'] == 'New Fruit Salad'
  340. assert content['parent_id'] is None
  341. assert content['show_in_ui'] is True
  342. assert content['slug'] == 'new-fruit-salad'
  343. assert content['status'] == 'open'
  344. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  345. assert content['workspace_id'] == 3
  346. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8
  347. """
  348. Check obtain workspace root archived contents
  349. """
  350. params = {
  351. 'parent_id': 0,
  352. 'show_archived': 1,
  353. 'show_deleted': 0,
  354. 'show_active': 0,
  355. }
  356. self.testapp.authorization = (
  357. 'Basic',
  358. (
  359. 'bob@fsf.local',
  360. 'foobarbaz'
  361. )
  362. )
  363. res = self.testapp.get(
  364. '/api/v2/workspaces/3/contents',
  365. status=200,
  366. params=params,
  367. ).json_body # nopep8
  368. assert len(res) == 1
  369. content = res[0]
  370. assert content['content_type'] == 'page'
  371. assert content['content_id'] == 16
  372. assert content['is_archived'] is True
  373. assert content['is_deleted'] is False
  374. assert content['label'].startswith('Fruit Salad')
  375. assert content['parent_id'] is None
  376. assert content['show_in_ui'] is True
  377. assert content['slug'].startswith('fruit-salad')
  378. assert content['status'] == 'open'
  379. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  380. assert content['workspace_id'] == 3
  381. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8
  382. """
  383. Check obtain workspace root deleted contents
  384. """
  385. params = {
  386. 'parent_id': 0,
  387. 'show_archived': 0,
  388. 'show_deleted': 1,
  389. 'show_active': 0,
  390. }
  391. self.testapp.authorization = (
  392. 'Basic',
  393. (
  394. 'bob@fsf.local',
  395. 'foobarbaz'
  396. )
  397. )
  398. res = self.testapp.get(
  399. '/api/v2/workspaces/3/contents',
  400. status=200,
  401. params=params,
  402. ).json_body # nopep8
  403. # TODO - G.M - 30-05-2018 - Check this test
  404. assert len(res) == 1
  405. content = res[0]
  406. assert content['content_type'] == 'page'
  407. assert content['content_id'] == 17
  408. assert content['is_archived'] is False
  409. assert content['is_deleted'] is True
  410. assert content['label'].startswith('Bad Fruit Salad')
  411. assert content['parent_id'] is None
  412. assert content['show_in_ui'] is True
  413. assert content['slug'].startswith('bad-fruit-salad')
  414. assert content['status'] == 'open'
  415. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  416. assert content['workspace_id'] == 3
  417. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  418. """
  419. Check obtain workspace root content who does not match any type
  420. (archived, deleted, active) result should be empty list.
  421. """
  422. params = {
  423. 'parent_id': 0,
  424. 'show_archived': 0,
  425. 'show_deleted': 0,
  426. 'show_active': 0,
  427. }
  428. self.testapp.authorization = (
  429. 'Basic',
  430. (
  431. 'bob@fsf.local',
  432. 'foobarbaz'
  433. )
  434. )
  435. res = self.testapp.get(
  436. '/api/v2/workspaces/3/contents',
  437. status=200,
  438. params=params,
  439. ).json_body # nopep8
  440. # TODO - G.M - 30-05-2018 - Check this test
  441. assert res == []
  442. # Folder related
  443. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  444. """
  445. Check obtain workspace folder all contents
  446. """
  447. params = {
  448. 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id
  449. 'show_archived': 1,
  450. 'show_deleted': 1,
  451. 'show_active': 1,
  452. }
  453. self.testapp.authorization = (
  454. 'Basic',
  455. (
  456. 'admin@admin.admin',
  457. 'admin@admin.admin'
  458. )
  459. )
  460. res = self.testapp.get(
  461. '/api/v2/workspaces/2/contents',
  462. status=200,
  463. params=params,
  464. ).json_body # nopep8
  465. assert len(res) == 3
  466. content = res[0]
  467. assert content['content_type'] == 'page'
  468. assert content['content_id'] == 12
  469. assert content['is_archived'] is False
  470. assert content['is_deleted'] is False
  471. assert content['label'] == 'New Fruit Salad'
  472. assert content['parent_id'] == 10
  473. assert content['show_in_ui'] is True
  474. assert content['slug'] == 'new-fruit-salad'
  475. assert content['status'] == 'open'
  476. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  477. assert content['workspace_id'] == 2
  478. content = res[1]
  479. assert content['content_type'] == 'page'
  480. assert content['content_id'] == 13
  481. assert content['is_archived'] is True
  482. assert content['is_deleted'] is False
  483. assert content['label'].startswith('Fruit Salad')
  484. assert content['parent_id'] == 10
  485. assert content['show_in_ui'] is True
  486. assert content['slug'].startswith('fruit-salad')
  487. assert content['status'] == 'open'
  488. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  489. assert content['workspace_id'] == 2
  490. content = res[2]
  491. assert content['content_type'] == 'page'
  492. assert content['content_id'] == 14
  493. assert content['is_archived'] is False
  494. assert content['is_deleted'] is True
  495. assert content['label'].startswith('Bad Fruit Salad')
  496. assert content['parent_id'] == 10
  497. assert content['show_in_ui'] is True
  498. assert content['slug'].startswith('bad-fruit-salad')
  499. assert content['status'] == 'open'
  500. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  501. assert content['workspace_id'] == 2
  502. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8
  503. """
  504. Check obtain workspace folder active contents
  505. """
  506. params = {
  507. 'parent_id': 10,
  508. 'show_archived': 0,
  509. 'show_deleted': 0,
  510. 'show_active': 1,
  511. }
  512. self.testapp.authorization = (
  513. 'Basic',
  514. (
  515. 'admin@admin.admin',
  516. 'admin@admin.admin'
  517. )
  518. )
  519. res = self.testapp.get(
  520. '/api/v2/workspaces/2/contents',
  521. status=200,
  522. params=params,
  523. ).json_body # nopep8
  524. assert len(res) == 1
  525. content = res[0]
  526. assert content['content_type']
  527. assert content['content_id'] == 12
  528. assert content['is_archived'] is False
  529. assert content['is_deleted'] is False
  530. assert content['label'] == 'New Fruit Salad'
  531. assert content['parent_id'] == 10
  532. assert content['show_in_ui'] is True
  533. assert content['slug'] == 'new-fruit-salad'
  534. assert content['status'] == 'open'
  535. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  536. assert content['workspace_id'] == 2
  537. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8
  538. """
  539. Check obtain workspace folder archived contents
  540. """
  541. params = {
  542. 'parent_id': 10,
  543. 'show_archived': 1,
  544. 'show_deleted': 0,
  545. 'show_active': 0,
  546. }
  547. self.testapp.authorization = (
  548. 'Basic',
  549. (
  550. 'admin@admin.admin',
  551. 'admin@admin.admin'
  552. )
  553. )
  554. res = self.testapp.get(
  555. '/api/v2/workspaces/2/contents',
  556. status=200,
  557. params=params,
  558. ).json_body # nopep8
  559. assert len(res) == 1
  560. content = res[0]
  561. assert content['content_type'] == 'page'
  562. assert content['content_id'] == 13
  563. assert content['is_archived'] is True
  564. assert content['is_deleted'] is False
  565. assert content['label'].startswith('Fruit Salad')
  566. assert content['parent_id'] == 10
  567. assert content['show_in_ui'] is True
  568. assert content['slug'].startswith('fruit-salad')
  569. assert content['status'] == 'open'
  570. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  571. assert content['workspace_id'] == 2
  572. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8
  573. """
  574. Check obtain workspace folder deleted contents
  575. """
  576. params = {
  577. 'parent_id': 10,
  578. 'show_archived': 0,
  579. 'show_deleted': 1,
  580. 'show_active': 0,
  581. }
  582. self.testapp.authorization = (
  583. 'Basic',
  584. (
  585. 'admin@admin.admin',
  586. 'admin@admin.admin'
  587. )
  588. )
  589. res = self.testapp.get(
  590. '/api/v2/workspaces/2/contents',
  591. status=200,
  592. params=params,
  593. ).json_body # nopep8
  594. assert len(res) == 1
  595. content = res[0]
  596. assert content['content_type'] == 'page'
  597. assert content['content_id'] == 14
  598. assert content['is_archived'] is False
  599. assert content['is_deleted'] is True
  600. assert content['label'].startswith('Bad Fruit Salad')
  601. assert content['parent_id'] == 10
  602. assert content['show_in_ui'] is True
  603. assert content['slug'].startswith('bad-fruit-salad')
  604. assert content['status'] == 'open'
  605. assert set(content['sub_content_types']) == {'thread', 'page', 'folder', 'file'} # nopep8
  606. assert content['workspace_id'] == 2
  607. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8
  608. """
  609. Check obtain workspace folder content who does not match any type
  610. (archived, deleted, active) result should be empty list.
  611. """
  612. params = {
  613. 'parent_id': 10,
  614. 'show_archived': 0,
  615. 'show_deleted': 0,
  616. 'show_active': 0,
  617. }
  618. self.testapp.authorization = (
  619. 'Basic',
  620. (
  621. 'admin@admin.admin',
  622. 'admin@admin.admin'
  623. )
  624. )
  625. res = self.testapp.get(
  626. '/api/v2/workspaces/2/contents',
  627. status=200,
  628. params=params,
  629. ).json_body # nopep8
  630. # TODO - G.M - 30-05-2018 - Check this test
  631. assert res == []
  632. # Error case
  633. def test_api__get_workspace_content__err_403__unallowed_user(self):
  634. """
  635. Check obtain workspace content list with an unreachable workspace for
  636. user
  637. """
  638. self.testapp.authorization = (
  639. 'Basic',
  640. (
  641. 'lawrence-not-real-email@fsf.local',
  642. 'foobarbaz'
  643. )
  644. )
  645. res = self.testapp.get('/api/v2/workspaces/3/contents', status=403)
  646. assert isinstance(res.json, dict)
  647. assert 'code' in res.json.keys()
  648. assert 'message' in res.json.keys()
  649. assert 'details' in res.json.keys()
  650. def test_api__get_workspace_content__err_401__unregistered_user(self):
  651. """
  652. Check obtain workspace content list with an unregistered user
  653. """
  654. self.testapp.authorization = (
  655. 'Basic',
  656. (
  657. 'john@doe.doe',
  658. 'lapin'
  659. )
  660. )
  661. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  662. assert isinstance(res.json, dict)
  663. assert 'code' in res.json.keys()
  664. assert 'message' in res.json.keys()
  665. assert 'details' in res.json.keys()
  666. def test_api__get_workspace_content__err_403__workspace_does_not_exist(self): # nopep8
  667. """
  668. Check obtain workspace contents list with an existing user but
  669. an unexisting workspace
  670. """
  671. self.testapp.authorization = (
  672. 'Basic',
  673. (
  674. 'admin@admin.admin',
  675. 'admin@admin.admin'
  676. )
  677. )
  678. res = self.testapp.get('/api/v2/workspaces/5/contents', status=403)
  679. assert isinstance(res.json, dict)
  680. assert 'code' in res.json.keys()
  681. assert 'message' in res.json.keys()
  682. assert 'details' in res.json.keys()
  683. def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8
  684. """
  685. Create generic content
  686. """
  687. self.testapp.authorization = (
  688. 'Basic',
  689. (
  690. 'admin@admin.admin',
  691. 'admin@admin.admin'
  692. )
  693. )
  694. params = {
  695. 'label': 'GenericCreatedContent',
  696. 'content_type': 'markdownpage',
  697. }
  698. res = self.testapp.post_json(
  699. '/api/v2/workspaces/1/contents',
  700. params=params,
  701. status=200
  702. )
  703. assert res
  704. assert res.json_body
  705. assert res.json_body['status'] == 'open'
  706. assert res.json_body['content_id']
  707. assert res.json_body['content_type'] == 'markdownpage'
  708. assert res.json_body['is_archived'] is False
  709. assert res.json_body['is_deleted'] is False
  710. assert res.json_body['workspace_id'] == 1
  711. assert res.json_body['slug'] == 'genericcreatedcontent'
  712. assert res.json_body['parent_id'] is None
  713. assert res.json_body['show_in_ui'] is True
  714. assert res.json_body['sub_content_types']
  715. params_active = {
  716. 'parent_id': 0,
  717. 'show_archived': 0,
  718. 'show_deleted': 0,
  719. 'show_active': 1,
  720. }
  721. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  722. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  723. assert res.json_body in active_contents
  724. def test_api_put_move_content__ok_200__nominal_case(self):
  725. """
  726. Move content
  727. move Apple_Pie (content_id: 8)
  728. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  729. of workspace Recipes.
  730. """
  731. self.testapp.authorization = (
  732. 'Basic',
  733. (
  734. 'admin@admin.admin',
  735. 'admin@admin.admin'
  736. )
  737. )
  738. params = {
  739. 'new_parent_id': '4', # Salads
  740. }
  741. params_folder1 = {
  742. 'parent_id': 3,
  743. 'show_archived': 0,
  744. 'show_deleted': 0,
  745. 'show_active': 1,
  746. }
  747. params_folder2 = {
  748. 'parent_id': 4,
  749. 'show_archived': 0,
  750. 'show_deleted': 0,
  751. 'show_active': 1,
  752. }
  753. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  754. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  755. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  756. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  757. # TODO - G.M - 2018-06-163 - Check content
  758. res = self.testapp.put_json(
  759. '/api/v2/workspaces/2/contents/8/move',
  760. params=params,
  761. status=204
  762. )
  763. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  764. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  765. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  766. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  767. def test_api_put_delete_content__ok_200__nominal_case(self):
  768. """
  769. delete content
  770. delete Apple_pie ( content_id: 8, parent_id: 3)
  771. """
  772. self.testapp.authorization = (
  773. 'Basic',
  774. (
  775. 'admin@admin.admin',
  776. 'admin@admin.admin'
  777. )
  778. )
  779. params_active = {
  780. 'parent_id': 3,
  781. 'show_archived': 0,
  782. 'show_deleted': 0,
  783. 'show_active': 1,
  784. }
  785. params_deleted = {
  786. 'parent_id': 3,
  787. 'show_archived': 0,
  788. 'show_deleted': 1,
  789. 'show_active': 0,
  790. }
  791. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  792. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  793. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  794. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  795. # TODO - G.M - 2018-06-163 - Check content
  796. res = self.testapp.put_json(
  797. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  798. '/api/v2/workspaces/2/contents/8/delete',
  799. status=204
  800. )
  801. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  802. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  803. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  804. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  805. def test_api_put_archive_content__ok_200__nominal_case(self):
  806. """
  807. archive content
  808. archive Apple_pie ( content_id: 8, parent_id: 3)
  809. """
  810. self.testapp.authorization = (
  811. 'Basic',
  812. (
  813. 'admin@admin.admin',
  814. 'admin@admin.admin'
  815. )
  816. )
  817. params_active = {
  818. 'parent_id': 3,
  819. 'show_archived': 0,
  820. 'show_deleted': 0,
  821. 'show_active': 1,
  822. }
  823. params_archived = {
  824. 'parent_id': 3,
  825. 'show_archived': 1,
  826. 'show_deleted': 0,
  827. 'show_active': 0,
  828. }
  829. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  830. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  831. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  832. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  833. res = self.testapp.put_json(
  834. '/api/v2/workspaces/2/contents/8/archive',
  835. status=204
  836. )
  837. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  838. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  839. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  840. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  841. def test_api_put_undelete_content__ok_200__nominal_case(self):
  842. """
  843. Undelete content
  844. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  845. """
  846. self.testapp.authorization = (
  847. 'Basic',
  848. (
  849. 'bob@fsf.local',
  850. 'foobarbaz'
  851. )
  852. )
  853. params_active = {
  854. 'parent_id': 10,
  855. 'show_archived': 0,
  856. 'show_deleted': 0,
  857. 'show_active': 1,
  858. }
  859. params_deleted = {
  860. 'parent_id': 10,
  861. 'show_archived': 0,
  862. 'show_deleted': 1,
  863. 'show_active': 0,
  864. }
  865. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  866. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  867. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  868. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  869. res = self.testapp.put_json(
  870. '/api/v2/workspaces/2/contents/14/undelete',
  871. status=204
  872. )
  873. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  874. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  875. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  876. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  877. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  878. """
  879. unarchive content,
  880. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  881. """
  882. self.testapp.authorization = (
  883. 'Basic',
  884. (
  885. 'bob@fsf.local',
  886. 'foobarbaz'
  887. )
  888. )
  889. params_active = {
  890. 'parent_id': 10,
  891. 'show_archived': 0,
  892. 'show_deleted': 0,
  893. 'show_active': 1,
  894. }
  895. params_archived = {
  896. 'parent_id': 10,
  897. 'show_archived': 1,
  898. 'show_deleted': 0,
  899. 'show_active': 0,
  900. }
  901. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  902. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  903. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  904. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  905. res = self.testapp.put_json(
  906. '/api/v2/workspaces/2/contents/13/unarchive',
  907. status=204
  908. )
  909. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  910. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  911. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  912. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8