test_workspaces.py 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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['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['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['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['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['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['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['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['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_slug'] == 'workspace_manager'
  141. assert user_role['user_id'] == 1
  142. assert user_role['workspace_id'] == 1
  143. assert user_role['user']['display_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['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_slug'] == 'open'
  225. assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'} # nopep8
  226. assert content['workspace_id'] == 1
  227. content = res[1]
  228. assert 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_slug'] == 'open'
  236. assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'} # nopep8
  237. assert content['workspace_id'] == 1
  238. content = res[2]
  239. assert 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_slug'] == 'open'
  247. assert set(content['sub_content_type_slug']) == {'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_slug'] == 'page'
  276. assert 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_slug'] == 'open'
  284. assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'} # nopep8
  285. assert content['workspace_id'] == 3
  286. content = res[2]
  287. assert content['content_type_slug'] == 'page'
  288. assert 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_slug'] == 'open'
  296. assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'} # nopep8
  297. assert content['workspace_id'] == 3
  298. content = res[3]
  299. assert content['content_type_slug'] == 'page'
  300. assert 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_slug'] == 'open'
  308. assert set(content['sub_content_type_slug']) == {'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_slug'] == 'page'
  336. assert 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_slug'] == 'open'
  344. assert set(content['sub_content_type_slug']) == {'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_slug'] == 'page'
  371. assert 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_slug'] == 'open'
  379. assert set(content['sub_content_type_slug']) == {'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_slug'] == 'page'
  407. assert 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_slug'] == 'open'
  415. assert set(content['sub_content_type_slug']) == {'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_slug'] == 'page'
  468. assert 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_slug'] == 'open'
  476. assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'} # nopep8
  477. assert content['workspace_id'] == 2
  478. content = res[1]
  479. assert content['content_type_slug'] == 'page'
  480. assert 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_slug'] == 'open'
  488. assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'} # nopep8
  489. assert content['workspace_id'] == 2
  490. content = res[2]
  491. assert content['content_type_slug'] == 'page'
  492. assert 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_slug'] == 'open'
  500. assert set(content['sub_content_type_slug']) == {'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_slug']
  527. assert 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_slug'] == 'open'
  535. assert set(content['sub_content_type_slug']) == {'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_slug'] == 'page'
  562. assert 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_slug'] == 'open'
  570. assert set(content['sub_content_type_slug']) == {'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_slug'] == 'page'
  597. assert 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_slug'] == 'open'
  605. assert set(content['sub_content_type_slug']) == {'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()