test_workspaces.py 18KB

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