test_workspaces.py 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. @pytest.mark.xfail()
  199. class TestWorkspaceContents(FunctionalTest):
  200. """
  201. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  202. """
  203. fixtures = [BaseFixture, ContentFixtures]
  204. def test_api__get_workspace_content__ok_200__get_default(self):
  205. """
  206. Check obtain workspace contents with defaults filters
  207. """
  208. self.testapp.authorization = (
  209. 'Basic',
  210. (
  211. 'admin@admin.admin',
  212. 'admin@admin.admin'
  213. )
  214. )
  215. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  216. # TODO - G.M - 30-05-2018 - Check this test
  217. raise NotImplementedError()
  218. # Root related
  219. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  220. """
  221. Check obtain workspace all root contents
  222. """
  223. params = {
  224. 'parent_id': 0,
  225. 'show_archived': 1,
  226. 'show_deleted': 1,
  227. 'show_active': 1,
  228. }
  229. self.testapp.authorization = (
  230. 'Basic',
  231. (
  232. 'admin@admin.admin',
  233. 'admin@admin.admin'
  234. )
  235. )
  236. res = self.testapp.get(
  237. '/api/v2/workspaces/1/contents',
  238. status=200,
  239. params=params,
  240. ).json_body # nopep8
  241. # TODO - G.M - 30-05-2018 - Check this test
  242. raise NotImplementedError()
  243. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self):
  244. """
  245. Check obtain workspace root active contents
  246. """
  247. params = {
  248. 'parent_id': 0,
  249. 'show_archived': 0,
  250. 'show_deleted': 0,
  251. 'show_active': 1,
  252. }
  253. self.testapp.authorization = (
  254. 'Basic',
  255. (
  256. 'admin@admin.admin',
  257. 'admin@admin.admin'
  258. )
  259. )
  260. res = self.testapp.get(
  261. '/api/v2/workspaces/1/contents',
  262. status=200,
  263. params=params,
  264. ).json_body # nopep8
  265. # TODO - G.M - 30-05-2018 - Check this test
  266. raise NotImplementedError()
  267. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self):
  268. """
  269. Check obtain workspace root archived contents
  270. """
  271. params = {
  272. 'parent_id': 0,
  273. 'show_archived': 1,
  274. 'show_deleted': 0,
  275. 'show_active': 0,
  276. }
  277. self.testapp.authorization = (
  278. 'Basic',
  279. (
  280. 'admin@admin.admin',
  281. 'admin@admin.admin'
  282. )
  283. )
  284. res = self.testapp.get(
  285. '/api/v2/workspaces/1/contents',
  286. status=200,
  287. params=params,
  288. ).json_body # nopep8
  289. # TODO - G.M - 30-05-2018 - Check this test
  290. raise NotImplementedError()
  291. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self):
  292. """
  293. Check obtain workspace root deleted contents
  294. """
  295. params = {
  296. 'parent_id': 0,
  297. 'show_archived': 0,
  298. 'show_deleted': 1,
  299. 'show_active': 0,
  300. }
  301. self.testapp.authorization = (
  302. 'Basic',
  303. (
  304. 'admin@admin.admin',
  305. 'admin@admin.admin'
  306. )
  307. )
  308. res = self.testapp.get(
  309. '/api/v2/workspaces/1/contents',
  310. status=200,
  311. params=params,
  312. ).json_body # nopep8
  313. # TODO - G.M - 30-05-2018 - Check this test
  314. raise NotImplementedError()
  315. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  316. """
  317. Check obtain workspace root content who does not match any type
  318. (archived, deleted, active) result should be empty list.
  319. """
  320. params = {
  321. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  322. 'show_archived': 0,
  323. 'show_deleted': 0,
  324. 'show_active': 0,
  325. }
  326. self.testapp.authorization = (
  327. 'Basic',
  328. (
  329. 'admin@admin.admin',
  330. 'admin@admin.admin'
  331. )
  332. )
  333. res = self.testapp.get(
  334. '/api/v2/workspaces/1/contents',
  335. status=200,
  336. params=params,
  337. ).json_body # nopep8
  338. # TODO - G.M - 30-05-2018 - Check this test
  339. raise NotImplementedError()
  340. # Folder related
  341. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  342. """
  343. Check obtain workspace folder all contents
  344. """
  345. params = {
  346. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  347. 'show_archived': 1,
  348. 'show_deleted': 1,
  349. 'show_active': 1,
  350. }
  351. self.testapp.authorization = (
  352. 'Basic',
  353. (
  354. 'admin@admin.admin',
  355. 'admin@admin.admin'
  356. )
  357. )
  358. res = self.testapp.get(
  359. '/api/v2/workspaces/1/contents',
  360. status=200,
  361. params=params,
  362. ).json_body # nopep8
  363. # TODO - G.M - 30-05-2018 - Check this test
  364. raise NotImplementedError()
  365. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):
  366. """
  367. Check obtain workspace folder active contents
  368. """
  369. params = {
  370. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  371. 'show_archived': 0,
  372. 'show_deleted': 0,
  373. 'show_active': 1,
  374. }
  375. self.testapp.authorization = (
  376. 'Basic',
  377. (
  378. 'admin@admin.admin',
  379. 'admin@admin.admin'
  380. )
  381. )
  382. res = self.testapp.get(
  383. '/api/v2/workspaces/1/contents',
  384. status=200,
  385. params=params,
  386. ).json_body # nopep8
  387. # TODO - G.M - 30-05-2018 - Check this test
  388. raise NotImplementedError()
  389. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):
  390. """
  391. Check obtain workspace folder archived contents
  392. """
  393. params = {
  394. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  395. 'show_archived': 0,
  396. 'show_deleted': 0,
  397. 'show_active': 1,
  398. }
  399. self.testapp.authorization = (
  400. 'Basic',
  401. (
  402. 'admin@admin.admin',
  403. 'admin@admin.admin'
  404. )
  405. )
  406. res = self.testapp.get(
  407. '/api/v2/workspaces/1/contents',
  408. status=200,
  409. params=params,
  410. ).json_body # nopep8
  411. # TODO - G.M - 30-05-2018 - Check this test
  412. raise NotImplementedError()
  413. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):
  414. """
  415. Check obtain workspace folder deleted contents
  416. """
  417. params = {
  418. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  419. 'show_archived': 0,
  420. 'show_deleted': 0,
  421. 'show_active': 1,
  422. }
  423. self.testapp.authorization = (
  424. 'Basic',
  425. (
  426. 'admin@admin.admin',
  427. 'admin@admin.admin'
  428. )
  429. )
  430. res = self.testapp.get(
  431. '/api/v2/workspaces/1/contents',
  432. status=200,
  433. params=params,
  434. ).json_body # nopep8
  435. # TODO - G.M - 30-05-2018 - Check this test
  436. raise NotImplementedError()
  437. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self):
  438. """
  439. Check obtain workspace folder content who does not match any type
  440. (archived, deleted, active) result should be empty list.
  441. """
  442. params = {
  443. 'parent_id': 2, # TODO - G.M - 30-05-2018 - Find a real id
  444. 'show_archived': 0,
  445. 'show_deleted': 0,
  446. 'show_active': 0,
  447. }
  448. self.testapp.authorization = (
  449. 'Basic',
  450. (
  451. 'admin@admin.admin',
  452. 'admin@admin.admin'
  453. )
  454. )
  455. res = self.testapp.get(
  456. '/api/v2/workspaces/1/contents',
  457. status=200,
  458. params=params,
  459. ).json_body # nopep8
  460. # TODO - G.M - 30-05-2018 - Check this test
  461. raise NotImplementedError()
  462. # Error case
  463. def test_api__get_workspace_content__err_403__unallowed_user(self):
  464. """
  465. Check obtain workspace content list with an unreachable workspace for
  466. user
  467. """
  468. self.testapp.authorization = (
  469. 'Basic',
  470. (
  471. 'lawrence-not-real-email@fsf.local',
  472. 'foobarbaz'
  473. )
  474. )
  475. res = self.testapp.get('/api/v2/workspaces/3/contents', status=403)
  476. assert isinstance(res.json, dict)
  477. assert 'code' in res.json.keys()
  478. assert 'message' in res.json.keys()
  479. assert 'details' in res.json.keys()
  480. def test_api__get_workspace_content__err_401__unregistered_user(self):
  481. """
  482. Check obtain workspace content list with an unregistered user
  483. """
  484. self.testapp.authorization = (
  485. 'Basic',
  486. (
  487. 'john@doe.doe',
  488. 'lapin'
  489. )
  490. )
  491. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  492. assert isinstance(res.json, dict)
  493. assert 'code' in res.json.keys()
  494. assert 'message' in res.json.keys()
  495. assert 'details' in res.json.keys()
  496. def test_api__get_workspace_content__err_403__workspace_does_not_exist(self): # nopep8
  497. """
  498. Check obtain workspace contents list with an existing user but
  499. an unexisting workspace
  500. """
  501. self.testapp.authorization = (
  502. 'Basic',
  503. (
  504. 'admin@admin.admin',
  505. 'admin@admin.admin'
  506. )
  507. )
  508. res = self.testapp.get('/api/v2/workspaces/5/contents', status=403)
  509. assert isinstance(res.json, dict)
  510. assert 'code' in res.json.keys()
  511. assert 'message' in res.json.keys()
  512. assert 'details' in res.json.keys()
  513. def test_api_get_workspace_content__err_404__parent_id_does_not_exist(self):
  514. # TODO - G.M - 30-05-2018 - Check this test
  515. raise NotImplementedError()