test_user.py 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for /api/v2/users subpath endpoints.
  4. """
  5. from time import sleep
  6. import pytest
  7. import transaction
  8. from tracim import models
  9. from tracim.lib.core.content import ContentApi
  10. from tracim.lib.core.user import UserApi
  11. from tracim.lib.core.workspace import WorkspaceApi
  12. from tracim.models import get_tm_session
  13. from tracim.models.contents import ContentTypeLegacy as ContentType
  14. from tracim.models.revision_protection import new_revision
  15. from tracim.tests import FunctionalTest
  16. from tracim.fixtures.content import Content as ContentFixtures
  17. from tracim.fixtures.users_and_groups import Base as BaseFixture
  18. class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
  19. """
  20. Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/recently_active # nopep8
  21. """
  22. fixtures = [BaseFixture]
  23. def test_api__get_recently_active_content__ok__200__nominal_case(self):
  24. # init DB
  25. dbsession = get_tm_session(self.session_factory, transaction.manager)
  26. admin = dbsession.query(models.User) \
  27. .filter(models.User.email == 'admin@admin.admin') \
  28. .one()
  29. workspace_api = WorkspaceApi(
  30. current_user=admin,
  31. session=dbsession,
  32. config=self.app_config
  33. )
  34. workspace = WorkspaceApi(
  35. current_user=admin,
  36. session=dbsession,
  37. config=self.app_config,
  38. ).create_workspace(
  39. 'test workspace',
  40. save_now=True
  41. )
  42. workspace2 = WorkspaceApi(
  43. current_user=admin,
  44. session=dbsession,
  45. config=self.app_config,
  46. ).create_workspace(
  47. 'test workspace2',
  48. save_now=True
  49. )
  50. api = ContentApi(
  51. current_user=admin,
  52. session=dbsession,
  53. config=self.app_config,
  54. )
  55. main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True) # nopep8
  56. main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
  57. # creation order test
  58. firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
  59. secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True) # nopep8
  60. # update order test
  61. firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True) # nopep8
  62. secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True) # nopep8
  63. with new_revision(
  64. session=dbsession,
  65. tm=transaction.manager,
  66. content=firstly_created_but_recently_updated,
  67. ):
  68. firstly_created_but_recently_updated.description = 'Just an update'
  69. api.save(firstly_created_but_recently_updated)
  70. # comment change order
  71. firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True) # nopep8
  72. secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8
  73. comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8
  74. content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True) # nopep8
  75. dbsession.flush()
  76. transaction.commit()
  77. self.testapp.authorization = (
  78. 'Basic',
  79. (
  80. 'admin@admin.admin',
  81. 'admin@admin.admin'
  82. )
  83. )
  84. res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/recently_active'.format(workspace.workspace_id), status=200) # nopep8
  85. res = res.json_body
  86. assert len(res) == 7
  87. for elem in res:
  88. assert isinstance(elem['content_id'], int)
  89. assert isinstance(elem['content_type'], str)
  90. assert elem['content_type'] != 'comments'
  91. assert isinstance(elem['is_archived'], bool)
  92. assert isinstance(elem['is_deleted'], bool)
  93. assert isinstance(elem['label'], str)
  94. assert isinstance(elem['parent_id'], int) or elem['parent_id'] is None
  95. assert isinstance(elem['show_in_ui'], bool)
  96. assert isinstance(elem['slug'], str)
  97. assert isinstance(elem['status'], str)
  98. assert isinstance(elem['sub_content_types'], list)
  99. for sub_content_type in elem['sub_content_types']:
  100. assert isinstance(sub_content_type, str)
  101. assert isinstance(elem['workspace_id'], int)
  102. # comment is newest than page2
  103. assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
  104. assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
  105. # last updated content is newer than other one despite creation
  106. # of the other is more recent
  107. assert res[2]['content_id'] == firstly_created_but_recently_updated.content_id
  108. assert res[3]['content_id'] == secondly_created_but_not_updated.content_id
  109. # creation order is inverted here as last created is last active
  110. assert res[4]['content_id'] == secondly_created.content_id
  111. assert res[5]['content_id'] == firstly_created.content_id
  112. # folder subcontent modification does not change folder order
  113. assert res[6]['content_id'] == main_folder.content_id
  114. def test_api__get_recently_active_content__ok__200__limit_2_multiple(self):
  115. # TODO - G.M - 2018-07-20 - Better fix for this test, do not use sleep()
  116. # anymore to fix datetime lack of precision.
  117. # init DB
  118. dbsession = get_tm_session(self.session_factory, transaction.manager)
  119. admin = dbsession.query(models.User) \
  120. .filter(models.User.email == 'admin@admin.admin') \
  121. .one()
  122. workspace_api = WorkspaceApi(
  123. current_user=admin,
  124. session=dbsession,
  125. config=self.app_config
  126. )
  127. workspace = WorkspaceApi(
  128. current_user=admin,
  129. session=dbsession,
  130. config=self.app_config,
  131. ).create_workspace(
  132. 'test workspace',
  133. save_now=True
  134. )
  135. workspace2 = WorkspaceApi(
  136. current_user=admin,
  137. session=dbsession,
  138. config=self.app_config,
  139. ).create_workspace(
  140. 'test workspace2',
  141. save_now=True
  142. )
  143. api = ContentApi(
  144. current_user=admin,
  145. session=dbsession,
  146. config=self.app_config,
  147. )
  148. main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True) # nopep8
  149. sleep(1)
  150. main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
  151. # creation order test
  152. firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
  153. sleep(1)
  154. secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True) # nopep8
  155. # update order test
  156. firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True) # nopep8
  157. sleep(1)
  158. secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True) # nopep8
  159. sleep(1)
  160. with new_revision(
  161. session=dbsession,
  162. tm=transaction.manager,
  163. content=firstly_created_but_recently_updated,
  164. ):
  165. firstly_created_but_recently_updated.description = 'Just an update'
  166. api.save(firstly_created_but_recently_updated)
  167. # comment change order
  168. firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True) # nopep8
  169. sleep(1)
  170. secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8
  171. sleep(1)
  172. comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8
  173. sleep(1)
  174. content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True) # nopep8
  175. dbsession.flush()
  176. transaction.commit()
  177. self.testapp.authorization = (
  178. 'Basic',
  179. (
  180. 'admin@admin.admin',
  181. 'admin@admin.admin'
  182. )
  183. )
  184. params = {
  185. 'limit': 2,
  186. }
  187. res = self.testapp.get(
  188. '/api/v2/users/1/workspaces/{}/contents/recently_active'.format(workspace.workspace_id), # nopep8
  189. status=200,
  190. params=params
  191. ) # nopep8
  192. res = res.json_body
  193. assert len(res) == 2
  194. for elem in res:
  195. assert isinstance(elem['content_id'], int)
  196. assert isinstance(elem['content_type'], str)
  197. assert elem['content_type'] != 'comments'
  198. assert isinstance(elem['is_archived'], bool)
  199. assert isinstance(elem['is_deleted'], bool)
  200. assert isinstance(elem['label'], str)
  201. assert isinstance(elem['parent_id'], int) or elem['parent_id'] is None
  202. assert isinstance(elem['show_in_ui'], bool)
  203. assert isinstance(elem['slug'], str)
  204. assert isinstance(elem['status'], str)
  205. assert isinstance(elem['sub_content_types'], list)
  206. for sub_content_type in elem['sub_content_types']:
  207. assert isinstance(sub_content_type, str)
  208. assert isinstance(elem['workspace_id'], int)
  209. # comment is newest than page2
  210. assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
  211. assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
  212. params = {
  213. 'limit': 2,
  214. 'before_datetime': secondly_created_but_not_commented.get_last_activity_date().strftime('%Y-%m-%dT%H:%M:%SZ'), # nopep8
  215. }
  216. res = self.testapp.get(
  217. '/api/v2/users/1/workspaces/{}/contents/recently_active'.format(workspace.workspace_id), # nopep8
  218. status=200,
  219. params=params
  220. )
  221. res = res.json_body
  222. assert len(res) == 2
  223. # last updated content is newer than other one despite creation
  224. # of the other is more recent
  225. assert res[0]['content_id'] == firstly_created_but_recently_updated.content_id
  226. assert res[1]['content_id'] == secondly_created_but_not_updated.content_id
  227. class TestUserReadStatusEndpoint(FunctionalTest):
  228. def test_api__get_read_status__ok__200__all(self):
  229. # init DB
  230. dbsession = get_tm_session(self.session_factory, transaction.manager)
  231. admin = dbsession.query(models.User) \
  232. .filter(models.User.email == 'admin@admin.admin') \
  233. .one()
  234. workspace_api = WorkspaceApi(
  235. current_user=admin,
  236. session=dbsession,
  237. config=self.app_config
  238. )
  239. workspace = WorkspaceApi(
  240. current_user=admin,
  241. session=dbsession,
  242. config=self.app_config,
  243. ).create_workspace(
  244. 'test workspace',
  245. save_now=True
  246. )
  247. workspace2 = WorkspaceApi(
  248. current_user=admin,
  249. session=dbsession,
  250. config=self.app_config,
  251. ).create_workspace(
  252. 'test workspace2',
  253. save_now=True
  254. )
  255. api = ContentApi(
  256. current_user=admin,
  257. session=dbsession,
  258. config=self.app_config,
  259. )
  260. main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True) # nopep8
  261. main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
  262. # creation order test
  263. firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
  264. secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True) # nopep8
  265. # update order test
  266. firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True) # nopep8
  267. secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True) # nopep8
  268. with new_revision(
  269. session=dbsession,
  270. tm=transaction.manager,
  271. content=firstly_created_but_recently_updated,
  272. ):
  273. firstly_created_but_recently_updated.description = 'Just an update'
  274. api.save(firstly_created_but_recently_updated)
  275. # comment change order
  276. firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True) # nopep8
  277. secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8
  278. comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8
  279. content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True) # nopep8
  280. dbsession.flush()
  281. transaction.commit()
  282. self.testapp.authorization = (
  283. 'Basic',
  284. (
  285. 'admin@admin.admin',
  286. 'admin@admin.admin'
  287. )
  288. )
  289. res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200) # nopep8
  290. res = res.json_body
  291. assert len(res) == 7
  292. for elem in res:
  293. assert isinstance(elem['content_id'], int)
  294. assert isinstance(elem['read_by_user'], bool)
  295. # comment is newest than page2
  296. assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
  297. assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
  298. # last updated content is newer than other one despite creation
  299. # of the other is more recent
  300. assert res[2]['content_id'] == firstly_created_but_recently_updated.content_id
  301. assert res[3]['content_id'] == secondly_created_but_not_updated.content_id
  302. # creation order is inverted here as last created is last active
  303. assert res[4]['content_id'] == secondly_created.content_id
  304. assert res[5]['content_id'] == firstly_created.content_id
  305. # folder subcontent modification does not change folder order
  306. assert res[6]['content_id'] == main_folder.content_id
  307. @pytest.mark.xfail(reason='List of item in path bug need to be fixed')
  308. def test_api__get_read_status__ok__200__nominal_case(self):
  309. # init DB
  310. dbsession = get_tm_session(self.session_factory, transaction.manager)
  311. admin = dbsession.query(models.User) \
  312. .filter(models.User.email == 'admin@admin.admin') \
  313. .one()
  314. workspace_api = WorkspaceApi(
  315. current_user=admin,
  316. session=dbsession,
  317. config=self.app_config
  318. )
  319. workspace = WorkspaceApi(
  320. current_user=admin,
  321. session=dbsession,
  322. config=self.app_config,
  323. ).create_workspace(
  324. 'test workspace',
  325. save_now=True
  326. )
  327. workspace2 = WorkspaceApi(
  328. current_user=admin,
  329. session=dbsession,
  330. config=self.app_config,
  331. ).create_workspace(
  332. 'test workspace2',
  333. save_now=True
  334. )
  335. api = ContentApi(
  336. current_user=admin,
  337. session=dbsession,
  338. config=self.app_config,
  339. )
  340. main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True) # nopep8
  341. main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
  342. # creation order test
  343. firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
  344. secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True) # nopep8
  345. # update order test
  346. firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True) # nopep8
  347. secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True) # nopep8
  348. with new_revision(
  349. session=dbsession,
  350. tm=transaction.manager,
  351. content=firstly_created_but_recently_updated,
  352. ):
  353. firstly_created_but_recently_updated.description = 'Just an update'
  354. api.save(firstly_created_but_recently_updated)
  355. # comment change order
  356. firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True) # nopep8
  357. secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8
  358. comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8
  359. content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True) # nopep8
  360. dbsession.flush()
  361. transaction.commit()
  362. self.testapp.authorization = (
  363. 'Basic',
  364. (
  365. 'admin@admin.admin',
  366. 'admin@admin.admin'
  367. )
  368. )
  369. selected_contents_id = [
  370. firstly_created_but_recently_commented.content_id,
  371. firstly_created_but_recently_updated.content_id,
  372. firstly_created.content_id,
  373. main_folder.content_id,
  374. ]
  375. content_id_str = '[{0},{1},{2},{3}]'.format(
  376. selected_contents_id[0],
  377. selected_contents_id[1],
  378. selected_contents_id[2],
  379. selected_contents_id[3],
  380. )
  381. params = {
  382. 'contents_ids': content_id_str
  383. }
  384. res = self.testapp.get(
  385. '/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), # nopep8
  386. status=200,
  387. params=params
  388. )
  389. res = res.json_body
  390. assert len(res) == 4
  391. for elem in res:
  392. assert isinstance(elem['content_id'], int)
  393. assert isinstance(elem['read_by_user'], bool)
  394. # comment is newest than page2
  395. assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
  396. assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
  397. # last updated content is newer than other one despite creation
  398. # of the other is more recent
  399. assert res[2]['content_id'] == firstly_created_but_recently_updated.content_id
  400. assert res[3]['content_id'] == secondly_created_but_not_updated.content_id
  401. # creation order is inverted here as last created is last active
  402. assert res[4]['content_id'] == secondly_created.content_id
  403. assert res[5]['content_id'] == firstly_created.content_id
  404. # folder subcontent modification does not change folder order
  405. assert res[6]['content_id'] == main_folder.content_id
  406. class TestUserWorkspaceEndpoint(FunctionalTest):
  407. """
  408. Tests for /api/v2/users/{user_id}/workspaces
  409. """
  410. fixtures = [BaseFixture, ContentFixtures]
  411. def test_api__get_user_workspaces__ok_200__nominal_case(self):
  412. """
  413. Check obtain all workspaces reachables for user with user auth.
  414. """
  415. self.testapp.authorization = (
  416. 'Basic',
  417. (
  418. 'admin@admin.admin',
  419. 'admin@admin.admin'
  420. )
  421. )
  422. res = self.testapp.get('/api/v2/users/1/workspaces', status=200)
  423. res = res.json_body
  424. workspace = res[0]
  425. assert workspace['workspace_id'] == 1
  426. assert workspace['label'] == 'Business'
  427. assert workspace['slug'] == 'business'
  428. assert len(workspace['sidebar_entries']) == 7
  429. sidebar_entry = workspace['sidebar_entries'][0]
  430. assert sidebar_entry['slug'] == 'dashboard'
  431. assert sidebar_entry['label'] == 'Dashboard'
  432. assert sidebar_entry['route'] == '/#/workspaces/1/dashboard' # nopep8
  433. assert sidebar_entry['hexcolor'] == "#252525"
  434. assert sidebar_entry['fa_icon'] == "signal"
  435. sidebar_entry = workspace['sidebar_entries'][1]
  436. assert sidebar_entry['slug'] == 'contents/all'
  437. assert sidebar_entry['label'] == 'All Contents'
  438. assert sidebar_entry['route'] == "/#/workspaces/1/contents" # nopep8
  439. assert sidebar_entry['hexcolor'] == "#fdfdfd"
  440. assert sidebar_entry['fa_icon'] == "th"
  441. sidebar_entry = workspace['sidebar_entries'][2]
  442. assert sidebar_entry['slug'] == 'contents/html-documents'
  443. assert sidebar_entry['label'] == 'Text Documents'
  444. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=html-documents' # nopep8
  445. assert sidebar_entry['hexcolor'] == "#3f52e3"
  446. assert sidebar_entry['fa_icon'] == "file-text-o"
  447. sidebar_entry = workspace['sidebar_entries'][3]
  448. assert sidebar_entry['slug'] == 'contents/markdownpluspage'
  449. assert sidebar_entry['label'] == 'Markdown Plus Documents'
  450. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=markdownpluspage" # nopep8
  451. assert sidebar_entry['hexcolor'] == "#f12d2d"
  452. assert sidebar_entry['fa_icon'] == "file-code-o"
  453. sidebar_entry = workspace['sidebar_entries'][4]
  454. assert sidebar_entry['slug'] == 'contents/files'
  455. assert sidebar_entry['label'] == 'Files'
  456. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file" # nopep8
  457. assert sidebar_entry['hexcolor'] == "#FF9900"
  458. assert sidebar_entry['fa_icon'] == "paperclip"
  459. sidebar_entry = workspace['sidebar_entries'][5]
  460. assert sidebar_entry['slug'] == 'contents/threads'
  461. assert sidebar_entry['label'] == 'Threads'
  462. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread" # nopep8
  463. assert sidebar_entry['hexcolor'] == "#ad4cf9"
  464. assert sidebar_entry['fa_icon'] == "comments-o"
  465. sidebar_entry = workspace['sidebar_entries'][6]
  466. assert sidebar_entry['slug'] == 'calendar'
  467. assert sidebar_entry['label'] == 'Calendar'
  468. assert sidebar_entry['route'] == "/#/workspaces/1/calendar" # nopep8
  469. assert sidebar_entry['hexcolor'] == "#757575"
  470. assert sidebar_entry['fa_icon'] == "calendar"
  471. def test_api__get_user_workspaces__err_403__unallowed_user(self):
  472. """
  473. Check obtain all workspaces reachables for one user
  474. with another non-admin user auth.
  475. """
  476. self.testapp.authorization = (
  477. 'Basic',
  478. (
  479. 'lawrence-not-real-email@fsf.local',
  480. 'foobarbaz'
  481. )
  482. )
  483. res = self.testapp.get('/api/v2/users/1/workspaces', status=403)
  484. assert isinstance(res.json, dict)
  485. assert 'code' in res.json.keys()
  486. assert 'message' in res.json.keys()
  487. assert 'details' in res.json.keys()
  488. def test_api__get_user_workspaces__err_401__unregistered_user(self):
  489. """
  490. Check obtain all workspaces reachables for one user
  491. without correct user auth (user unregistered).
  492. """
  493. self.testapp.authorization = (
  494. 'Basic',
  495. (
  496. 'john@doe.doe',
  497. 'lapin'
  498. )
  499. )
  500. res = self.testapp.get('/api/v2/users/1/workspaces', status=401)
  501. assert isinstance(res.json, dict)
  502. assert 'code' in res.json.keys()
  503. assert 'message' in res.json.keys()
  504. assert 'details' in res.json.keys()
  505. def test_api__get_user_workspaces__err_400__user_does_not_exist(self):
  506. """
  507. Check obtain all workspaces reachables for one user who does
  508. not exist
  509. with a correct user auth.
  510. """
  511. self.testapp.authorization = (
  512. 'Basic',
  513. (
  514. 'admin@admin.admin',
  515. 'admin@admin.admin'
  516. )
  517. )
  518. res = self.testapp.get('/api/v2/users/5/workspaces', status=400)
  519. assert isinstance(res.json, dict)
  520. assert 'code' in res.json.keys()
  521. assert 'message' in res.json.keys()
  522. assert 'details' in res.json.keys()