test_workspaces.py 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for /api/v2/workspaces subpath endpoints.
  4. """
  5. import pytest
  6. from tracim.tests import FunctionalTest
  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['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['icon'] == ""
  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['icon'] == ""
  44. sidebar_entry = workspace['sidebar_entries'][2]
  45. assert sidebar_entry['slug'] == 'contents/pagehtml'
  46. assert sidebar_entry['label'] == 'Text Documents'
  47. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=pagehtml' # nopep8
  48. assert sidebar_entry['hexcolor'] == "#3f52e3"
  49. assert sidebar_entry['icon'] == "file-text-o"
  50. sidebar_entry = workspace['sidebar_entries'][3]
  51. assert sidebar_entry['slug'] == 'contents/pagemarkdownplus'
  52. assert sidebar_entry['label'] == 'Rich Markdown Files'
  53. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=pagemarkdownplus" # nopep8
  54. assert sidebar_entry['hexcolor'] == "#f12d2d"
  55. assert sidebar_entry['icon'] == "file-code"
  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['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['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['icon'] == "calendar-alt"
  74. def test_api__get_workspace__err_403__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=403)
  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_403__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=403)
  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_slug'] == 'workspace_manager'
  142. assert user_role['user_id'] == 1
  143. assert user_role['workspace_id'] == 1
  144. assert user_role['user']['display_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_403__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=403)
  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_403__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=403)
  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['id'] == 1
  219. assert content['is_archived'] is False
  220. assert content['is_deleted'] is False
  221. assert content['label'] == 'Tools'
  222. assert content['parent_id'] is None
  223. assert content['show_in_ui'] == True
  224. assert content['slug'] == 'tools'
  225. assert content['status_slug'] == 'open'
  226. assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
  227. assert content['workspace_id'] == 1
  228. content = res[1]
  229. assert content['id'] == 2
  230. assert content['is_archived'] is False
  231. assert content['is_deleted'] is False
  232. assert content['label'] == 'Menus'
  233. assert content['parent_id'] is None
  234. assert content['show_in_ui'] == True
  235. assert content['slug'] == 'menus'
  236. assert content['status_slug'] == 'open'
  237. assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
  238. assert content['workspace_id'] == 1
  239. content = res[2]
  240. assert content['id'] == 11
  241. assert content['is_archived'] is False
  242. assert content['is_deleted'] is False
  243. assert content['label'] == 'Current Menu'
  244. assert content['parent_id'] == 2
  245. assert content['show_in_ui'] == True
  246. assert content['slug'] == 'current-menu'
  247. assert content['status_slug'] == 'open'
  248. assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
  249. assert content['workspace_id'] == 1
  250. # Root related
  251. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  252. """
  253. Check obtain workspace all root contents
  254. """
  255. params = {
  256. 'parent_id': 0,
  257. 'show_archived': 1,
  258. 'show_deleted': 1,
  259. 'show_active': 1,
  260. }
  261. self.testapp.authorization = (
  262. 'Basic',
  263. (
  264. 'admin@admin.admin',
  265. 'admin@admin.admin'
  266. )
  267. )
  268. res = self.testapp.get(
  269. '/api/v2/workspaces/1/contents',
  270. status=200,
  271. params=params,
  272. ).json_body # nopep8
  273. # TODO - G.M - 30-05-2018 - Check this test
  274. assert len(res) == 2
  275. content = res[0]
  276. assert content['id'] == 1
  277. assert content['is_archived'] is False
  278. assert content['is_deleted'] is False
  279. assert content['label'] == 'Tools'
  280. assert content['parent_id'] is None
  281. assert content['show_in_ui'] == True
  282. assert content['slug'] == 'tools'
  283. assert content['status_slug'] == 'open'
  284. assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
  285. assert content['workspace_id'] == 1
  286. content = res[1]
  287. assert content['id'] == 2
  288. assert content['is_archived'] is False
  289. assert content['is_deleted'] is False
  290. assert content['label'] == 'Menus'
  291. assert content['parent_id'] is None
  292. assert content['show_in_ui'] == True
  293. assert content['slug'] == 'menus'
  294. assert content['status_slug'] == 'open'
  295. assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
  296. assert content['workspace_id'] == 1
  297. @pytest.mark.xfail()
  298. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self):
  299. """
  300. Check obtain workspace root active contents
  301. """
  302. params = {
  303. 'parent_id': 0,
  304. 'show_archived': 0,
  305. 'show_deleted': 0,
  306. 'show_active': 1,
  307. }
  308. self.testapp.authorization = (
  309. 'Basic',
  310. (
  311. 'admin@admin.admin',
  312. 'admin@admin.admin'
  313. )
  314. )
  315. res = self.testapp.get(
  316. '/api/v2/workspaces/1/contents',
  317. status=200,
  318. params=params,
  319. ).json_body # nopep8
  320. # TODO - G.M - 30-05-2018 - Check this test
  321. raise NotImplementedError()
  322. @pytest.mark.xfail()
  323. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self):
  324. """
  325. Check obtain workspace root archived contents
  326. """
  327. params = {
  328. 'parent_id': 0,
  329. 'show_archived': 1,
  330. 'show_deleted': 0,
  331. 'show_active': 0,
  332. }
  333. self.testapp.authorization = (
  334. 'Basic',
  335. (
  336. 'admin@admin.admin',
  337. 'admin@admin.admin'
  338. )
  339. )
  340. res = self.testapp.get(
  341. '/api/v2/workspaces/1/contents',
  342. status=200,
  343. params=params,
  344. ).json_body # nopep8
  345. # TODO - G.M - 30-05-2018 - Check this test
  346. raise NotImplementedError()
  347. @pytest.mark.xfail()
  348. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self):
  349. """
  350. Check obtain workspace root deleted contents
  351. """
  352. params = {
  353. 'parent_id': 0,
  354. 'show_archived': 0,
  355. 'show_deleted': 1,
  356. 'show_active': 0,
  357. }
  358. self.testapp.authorization = (
  359. 'Basic',
  360. (
  361. 'admin@admin.admin',
  362. 'admin@admin.admin'
  363. )
  364. )
  365. res = self.testapp.get(
  366. '/api/v2/workspaces/1/contents',
  367. status=200,
  368. params=params,
  369. ).json_body # nopep8
  370. # TODO - G.M - 30-05-2018 - Check this test
  371. raise NotImplementedError()
  372. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  373. """
  374. Check obtain workspace root content who does not match any type
  375. (archived, deleted, active) result should be empty list.
  376. """
  377. params = {
  378. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  379. 'show_archived': 0,
  380. 'show_deleted': 0,
  381. 'show_active': 0,
  382. }
  383. self.testapp.authorization = (
  384. 'Basic',
  385. (
  386. 'admin@admin.admin',
  387. 'admin@admin.admin'
  388. )
  389. )
  390. res = self.testapp.get(
  391. '/api/v2/workspaces/1/contents',
  392. status=200,
  393. params=params,
  394. ).json_body # nopep8
  395. # TODO - G.M - 30-05-2018 - Check this test
  396. assert res == []
  397. # Folder related
  398. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  399. """
  400. Check obtain workspace folder all contents
  401. """
  402. params = {
  403. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  404. 'show_archived': 1,
  405. 'show_deleted': 1,
  406. 'show_active': 1,
  407. }
  408. self.testapp.authorization = (
  409. 'Basic',
  410. (
  411. 'admin@admin.admin',
  412. 'admin@admin.admin'
  413. )
  414. )
  415. res = self.testapp.get(
  416. '/api/v2/workspaces/1/contents',
  417. status=200,
  418. params=params,
  419. ).json_body # nopep8
  420. # TODO - G.M - 30-05-2018 - Check this test
  421. assert len(res) == 1
  422. content = res[0]
  423. assert content['id'] == 11
  424. assert content['is_archived'] is False
  425. assert content['is_deleted'] is False
  426. assert content['label'] == 'Current Menu'
  427. assert content['parent_id'] == 2
  428. assert content['show_in_ui'] == True
  429. assert content['slug'] == 'current-menu'
  430. assert content['status_slug'] == 'open'
  431. assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
  432. assert content['workspace_id'] == 1
  433. @pytest.mark.xfail()
  434. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):
  435. """
  436. Check obtain workspace folder active contents
  437. """
  438. params = {
  439. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  440. 'show_archived': 0,
  441. 'show_deleted': 0,
  442. 'show_active': 1,
  443. }
  444. self.testapp.authorization = (
  445. 'Basic',
  446. (
  447. 'admin@admin.admin',
  448. 'admin@admin.admin'
  449. )
  450. )
  451. res = self.testapp.get(
  452. '/api/v2/workspaces/1/contents',
  453. status=200,
  454. params=params,
  455. ).json_body # nopep8
  456. # TODO - G.M - 30-05-2018 - Check this test
  457. raise NotImplementedError()
  458. @pytest.mark.xfail()
  459. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):
  460. """
  461. Check obtain workspace folder archived contents
  462. """
  463. params = {
  464. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  465. 'show_archived': 0,
  466. 'show_deleted': 0,
  467. 'show_active': 1,
  468. }
  469. self.testapp.authorization = (
  470. 'Basic',
  471. (
  472. 'admin@admin.admin',
  473. 'admin@admin.admin'
  474. )
  475. )
  476. res = self.testapp.get(
  477. '/api/v2/workspaces/1/contents',
  478. status=200,
  479. params=params,
  480. ).json_body # nopep8
  481. # TODO - G.M - 30-05-2018 - Check this test
  482. raise NotImplementedError()
  483. @pytest.mark.xfail()
  484. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):
  485. """
  486. Check obtain workspace folder deleted contents
  487. """
  488. params = {
  489. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  490. 'show_archived': 0,
  491. 'show_deleted': 0,
  492. 'show_active': 1,
  493. }
  494. self.testapp.authorization = (
  495. 'Basic',
  496. (
  497. 'admin@admin.admin',
  498. 'admin@admin.admin'
  499. )
  500. )
  501. res = self.testapp.get(
  502. '/api/v2/workspaces/1/contents',
  503. status=200,
  504. params=params,
  505. ).json_body # nopep8
  506. # TODO - G.M - 30-05-2018 - Check this test
  507. raise NotImplementedError()
  508. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self):
  509. """
  510. Check obtain workspace folder content who does not match any type
  511. (archived, deleted, active) result should be empty list.
  512. """
  513. params = {
  514. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  515. 'show_archived': 0,
  516. 'show_deleted': 0,
  517. 'show_active': 0,
  518. }
  519. self.testapp.authorization = (
  520. 'Basic',
  521. (
  522. 'admin@admin.admin',
  523. 'admin@admin.admin'
  524. )
  525. )
  526. res = self.testapp.get(
  527. '/api/v2/workspaces/1/contents',
  528. status=200,
  529. params=params,
  530. ).json_body # nopep8
  531. # TODO - G.M - 30-05-2018 - Check this test
  532. assert res == []
  533. # Error case
  534. def test_api__get_workspace_content__err_403__unallowed_user(self):
  535. """
  536. Check obtain workspace content list with an unreachable workspace for
  537. user
  538. """
  539. self.testapp.authorization = (
  540. 'Basic',
  541. (
  542. 'lawrence-not-real-email@fsf.local',
  543. 'foobarbaz'
  544. )
  545. )
  546. res = self.testapp.get('/api/v2/workspaces/3/contents', status=403)
  547. assert isinstance(res.json, dict)
  548. assert 'code' in res.json.keys()
  549. assert 'message' in res.json.keys()
  550. assert 'details' in res.json.keys()
  551. def test_api__get_workspace_content__err_401__unregistered_user(self):
  552. """
  553. Check obtain workspace content list with an unregistered user
  554. """
  555. self.testapp.authorization = (
  556. 'Basic',
  557. (
  558. 'john@doe.doe',
  559. 'lapin'
  560. )
  561. )
  562. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  563. assert isinstance(res.json, dict)
  564. assert 'code' in res.json.keys()
  565. assert 'message' in res.json.keys()
  566. assert 'details' in res.json.keys()
  567. def test_api__get_workspace_content__err_403__workspace_does_not_exist(self): # nopep8
  568. """
  569. Check obtain workspace contents list with an existing user but
  570. an unexisting workspace
  571. """
  572. self.testapp.authorization = (
  573. 'Basic',
  574. (
  575. 'admin@admin.admin',
  576. 'admin@admin.admin'
  577. )
  578. )
  579. res = self.testapp.get('/api/v2/workspaces/5/contents', status=403)
  580. assert isinstance(res.json, dict)
  581. assert 'code' in res.json.keys()
  582. assert 'message' in res.json.keys()
  583. assert 'details' in res.json.keys()