test_workspaces.py 63KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for /api/v2/workspaces subpath endpoints.
  4. """
  5. from tracim.tests import FunctionalTest
  6. from tracim.tests import set_html_document_slug_to_legacy
  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['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['fa_icon'] == "signal"
  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['fa_icon'] == "th"
  44. sidebar_entry = workspace['sidebar_entries'][2]
  45. assert sidebar_entry['slug'] == 'contents/html-documents'
  46. assert sidebar_entry['label'] == 'Text Documents'
  47. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=html-documents' # nopep8
  48. assert sidebar_entry['hexcolor'] == "#3f52e3"
  49. assert sidebar_entry['fa_icon'] == "file-text-o"
  50. sidebar_entry = workspace['sidebar_entries'][3]
  51. assert sidebar_entry['slug'] == 'contents/markdownpluspage'
  52. assert sidebar_entry['label'] == 'Markdown Plus Documents'
  53. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=markdownpluspage" # nopep8
  54. assert sidebar_entry['hexcolor'] == "#f12d2d"
  55. assert sidebar_entry['fa_icon'] == "file-code-o"
  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['fa_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['fa_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['fa_icon'] == "calendar"
  74. def test_api__update_workspace__ok_200__nominal_case(self) -> None:
  75. """
  76. Test update workspace
  77. """
  78. self.testapp.authorization = (
  79. 'Basic',
  80. (
  81. 'admin@admin.admin',
  82. 'admin@admin.admin'
  83. )
  84. )
  85. params = {
  86. 'label': 'superworkspace',
  87. 'description': 'mysuperdescription'
  88. }
  89. # Before
  90. res = self.testapp.get(
  91. '/api/v2/workspaces/1',
  92. status=200
  93. )
  94. assert res.json_body
  95. workspace = res.json_body
  96. assert workspace['workspace_id'] == 1
  97. assert workspace['slug'] == 'business'
  98. assert workspace['label'] == 'Business'
  99. assert workspace['description'] == 'All importants documents'
  100. assert len(workspace['sidebar_entries']) == 7
  101. # modify workspace
  102. res = self.testapp.put_json(
  103. '/api/v2/workspaces/1',
  104. status=200,
  105. params=params,
  106. )
  107. assert res.json_body
  108. workspace = res.json_body
  109. assert workspace['workspace_id'] == 1
  110. assert workspace['slug'] == 'superworkspace'
  111. assert workspace['label'] == 'superworkspace'
  112. assert workspace['description'] == 'mysuperdescription'
  113. assert len(workspace['sidebar_entries']) == 7
  114. # after
  115. res = self.testapp.get(
  116. '/api/v2/workspaces/1',
  117. status=200
  118. )
  119. assert res.json_body
  120. workspace = res.json_body
  121. assert workspace['workspace_id'] == 1
  122. assert workspace['slug'] == 'superworkspace'
  123. assert workspace['label'] == 'superworkspace'
  124. assert workspace['description'] == 'mysuperdescription'
  125. assert len(workspace['sidebar_entries']) == 7
  126. def test_api__update_workspace__err_400__empty_label(self) -> None:
  127. """
  128. Test update workspace with empty label
  129. """
  130. self.testapp.authorization = (
  131. 'Basic',
  132. (
  133. 'admin@admin.admin',
  134. 'admin@admin.admin'
  135. )
  136. )
  137. params = {
  138. 'label': '',
  139. 'description': 'mysuperdescription'
  140. }
  141. res = self.testapp.put_json(
  142. '/api/v2/workspaces/1',
  143. status=400,
  144. params=params,
  145. )
  146. def test_api__create_workspace__ok_200__nominal_case(self) -> None:
  147. """
  148. Test create workspace
  149. """
  150. self.testapp.authorization = (
  151. 'Basic',
  152. (
  153. 'admin@admin.admin',
  154. 'admin@admin.admin'
  155. )
  156. )
  157. params = {
  158. 'label': 'superworkspace',
  159. 'description': 'mysuperdescription'
  160. }
  161. res = self.testapp.post_json(
  162. '/api/v2/workspaces',
  163. status=200,
  164. params=params,
  165. )
  166. assert res.json_body
  167. workspace = res.json_body
  168. workspace_id = res.json_body['workspace_id']
  169. res = self.testapp.get(
  170. '/api/v2/workspaces/{}'.format(workspace_id),
  171. status=200
  172. )
  173. workspace_2 = res.json_body
  174. assert workspace == workspace_2
  175. def test_api__create_workspace__err_400__empty_label(self) -> None:
  176. """
  177. Test create workspace with empty label
  178. """
  179. self.testapp.authorization = (
  180. 'Basic',
  181. (
  182. 'admin@admin.admin',
  183. 'admin@admin.admin'
  184. )
  185. )
  186. params = {
  187. 'label': '',
  188. 'description': 'mysuperdescription'
  189. }
  190. res = self.testapp.post_json(
  191. '/api/v2/workspaces',
  192. status=400,
  193. params=params,
  194. )
  195. def test_api__get_workspace__err_400__unallowed_user(self) -> None:
  196. """
  197. Check obtain workspace unreachable for user
  198. """
  199. self.testapp.authorization = (
  200. 'Basic',
  201. (
  202. 'lawrence-not-real-email@fsf.local',
  203. 'foobarbaz'
  204. )
  205. )
  206. res = self.testapp.get('/api/v2/workspaces/1', status=400)
  207. assert isinstance(res.json, dict)
  208. assert 'code' in res.json.keys()
  209. assert 'message' in res.json.keys()
  210. assert 'details' in res.json.keys()
  211. def test_api__get_workspace__err_401__unregistered_user(self) -> None:
  212. """
  213. Check obtain workspace without registered user.
  214. """
  215. self.testapp.authorization = (
  216. 'Basic',
  217. (
  218. 'john@doe.doe',
  219. 'lapin'
  220. )
  221. )
  222. res = self.testapp.get('/api/v2/workspaces/1', status=401)
  223. assert isinstance(res.json, dict)
  224. assert 'code' in res.json.keys()
  225. assert 'message' in res.json.keys()
  226. assert 'details' in res.json.keys()
  227. def test_api__get_workspace__err_400__workspace_does_not_exist(self) -> None: # nopep8
  228. """
  229. Check obtain workspace who does not exist with an existing user.
  230. """
  231. self.testapp.authorization = (
  232. 'Basic',
  233. (
  234. 'admin@admin.admin',
  235. 'admin@admin.admin'
  236. )
  237. )
  238. res = self.testapp.get('/api/v2/workspaces/5', status=400)
  239. assert isinstance(res.json, dict)
  240. assert 'code' in res.json.keys()
  241. assert 'message' in res.json.keys()
  242. assert 'details' in res.json.keys()
  243. class TestWorkspaceMembersEndpoint(FunctionalTest):
  244. """
  245. Tests for /api/v2/workspaces/{workspace_id}/members endpoint
  246. """
  247. fixtures = [BaseFixture, ContentFixtures]
  248. def test_api__get_workspace_members__ok_200__nominal_case(self):
  249. """
  250. Check obtain workspace members list with a reachable workspace for user
  251. """
  252. self.testapp.authorization = (
  253. 'Basic',
  254. (
  255. 'admin@admin.admin',
  256. 'admin@admin.admin'
  257. )
  258. )
  259. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  260. assert len(res) == 1
  261. user_role = res[0]
  262. assert user_role['role'] == 'workspace-manager'
  263. assert user_role['user_id'] == 1
  264. assert user_role['workspace_id'] == 1
  265. assert user_role['workspace']['workspace_id'] == 1
  266. assert user_role['workspace']['label'] == 'Business'
  267. assert user_role['workspace']['slug'] == 'business'
  268. assert user_role['user']['public_name'] == 'Global manager'
  269. assert user_role['user']['user_id'] == 1
  270. assert user_role['is_active'] is True
  271. # TODO - G.M - 24-05-2018 - [Avatar] Replace
  272. # by correct value when avatar feature will be enabled
  273. assert user_role['user']['avatar_url'] is None
  274. def test_api__get_workspace_members__err_400__unallowed_user(self):
  275. """
  276. Check obtain workspace members list with an unreachable workspace for
  277. user
  278. """
  279. self.testapp.authorization = (
  280. 'Basic',
  281. (
  282. 'lawrence-not-real-email@fsf.local',
  283. 'foobarbaz'
  284. )
  285. )
  286. res = self.testapp.get('/api/v2/workspaces/3/members', status=400)
  287. assert isinstance(res.json, dict)
  288. assert 'code' in res.json.keys()
  289. assert 'message' in res.json.keys()
  290. assert 'details' in res.json.keys()
  291. def test_api__get_workspace_members__err_401__unregistered_user(self):
  292. """
  293. Check obtain workspace members list with an unregistered user
  294. """
  295. self.testapp.authorization = (
  296. 'Basic',
  297. (
  298. 'john@doe.doe',
  299. 'lapin'
  300. )
  301. )
  302. res = self.testapp.get('/api/v2/workspaces/1/members', status=401)
  303. assert isinstance(res.json, dict)
  304. assert 'code' in res.json.keys()
  305. assert 'message' in res.json.keys()
  306. assert 'details' in res.json.keys()
  307. def test_api__get_workspace_members__err_400__workspace_does_not_exist(self): # nopep8
  308. """
  309. Check obtain workspace members list with an existing user but
  310. an unexisting workspace
  311. """
  312. self.testapp.authorization = (
  313. 'Basic',
  314. (
  315. 'admin@admin.admin',
  316. 'admin@admin.admin'
  317. )
  318. )
  319. res = self.testapp.get('/api/v2/workspaces/5/members', status=400)
  320. assert isinstance(res.json, dict)
  321. assert 'code' in res.json.keys()
  322. assert 'message' in res.json.keys()
  323. assert 'details' in res.json.keys()
  324. def test_api__create_workspace_member_role__ok_200__user_id(self):
  325. """
  326. Create workspace member role
  327. :return:
  328. """
  329. self.testapp.authorization = (
  330. 'Basic',
  331. (
  332. 'admin@admin.admin',
  333. 'admin@admin.admin'
  334. )
  335. )
  336. # create workspace role
  337. params = {
  338. 'user_id': 2,
  339. 'user_email_or_public_name': None,
  340. 'role': 'content-manager',
  341. }
  342. res = self.testapp.post_json(
  343. '/api/v2/workspaces/1/members',
  344. status=200,
  345. params=params,
  346. )
  347. user_role_found = res.json_body
  348. assert user_role_found['role'] == 'content-manager'
  349. assert user_role_found['user_id'] == 2
  350. assert user_role_found['workspace_id'] == 1
  351. assert user_role_found['newly_created'] is False
  352. assert user_role_found['email_sent'] is False
  353. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  354. assert len(res) == 2
  355. user_role = res[0]
  356. assert user_role['role'] == 'workspace-manager'
  357. assert user_role['user_id'] == 1
  358. assert user_role['workspace_id'] == 1
  359. user_role = res[1]
  360. assert user_role_found['role'] == user_role['role']
  361. assert user_role_found['user_id'] == user_role['user_id']
  362. assert user_role_found['workspace_id'] == user_role['workspace_id']
  363. def test_api__create_workspace_member_role__ok_200__user_email(self):
  364. """
  365. Create workspace member role
  366. :return:
  367. """
  368. self.testapp.authorization = (
  369. 'Basic',
  370. (
  371. 'admin@admin.admin',
  372. 'admin@admin.admin'
  373. )
  374. )
  375. # create workspace role
  376. params = {
  377. 'user_id': None,
  378. 'user_email_or_public_name': 'lawrence-not-real-email@fsf.local',
  379. 'role': 'content-manager',
  380. }
  381. res = self.testapp.post_json(
  382. '/api/v2/workspaces/1/members',
  383. status=200,
  384. params=params,
  385. )
  386. user_role_found = res.json_body
  387. assert user_role_found['role'] == 'content-manager'
  388. assert user_role_found['user_id'] == 2
  389. assert user_role_found['workspace_id'] == 1
  390. assert user_role_found['newly_created'] is False
  391. assert user_role_found['email_sent'] is False
  392. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  393. assert len(res) == 2
  394. user_role = res[0]
  395. assert user_role['role'] == 'workspace-manager'
  396. assert user_role['user_id'] == 1
  397. assert user_role['workspace_id'] == 1
  398. user_role = res[1]
  399. assert user_role_found['role'] == user_role['role']
  400. assert user_role_found['user_id'] == user_role['user_id']
  401. assert user_role_found['workspace_id'] == user_role['workspace_id']
  402. def test_api__create_workspace_member_role__ok_200__user_public_name(self):
  403. """
  404. Create workspace member role
  405. :return:
  406. """
  407. self.testapp.authorization = (
  408. 'Basic',
  409. (
  410. 'admin@admin.admin',
  411. 'admin@admin.admin'
  412. )
  413. )
  414. # create workspace role
  415. params = {
  416. 'user_id': None,
  417. 'user_email_or_public_name': 'Lawrence L.',
  418. 'role': 'content-manager',
  419. }
  420. res = self.testapp.post_json(
  421. '/api/v2/workspaces/1/members',
  422. status=200,
  423. params=params,
  424. )
  425. user_role_found = res.json_body
  426. assert user_role_found['role'] == 'content-manager'
  427. assert user_role_found['user_id'] == 2
  428. assert user_role_found['workspace_id'] == 1
  429. assert user_role_found['newly_created'] is False
  430. assert user_role_found['email_sent'] is False
  431. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  432. assert len(res) == 2
  433. user_role = res[0]
  434. assert user_role['role'] == 'workspace-manager'
  435. assert user_role['user_id'] == 1
  436. assert user_role['workspace_id'] == 1
  437. user_role = res[1]
  438. assert user_role_found['role'] == user_role['role']
  439. assert user_role_found['user_id'] == user_role['user_id']
  440. assert user_role_found['workspace_id'] == user_role['workspace_id']
  441. def test_api__create_workspace_member_role__err_400__nothing(self):
  442. """
  443. Create workspace member role
  444. :return:
  445. """
  446. self.testapp.authorization = (
  447. 'Basic',
  448. (
  449. 'admin@admin.admin',
  450. 'admin@admin.admin'
  451. )
  452. )
  453. # create workspace role
  454. params = {
  455. 'user_id': None,
  456. 'user_email_or_public_name': None,
  457. 'role': 'content-manager',
  458. }
  459. res = self.testapp.post_json(
  460. '/api/v2/workspaces/1/members',
  461. status=400,
  462. params=params,
  463. )
  464. def test_api__create_workspace_member_role__err_400__wrong_user_id(self):
  465. """
  466. Create workspace member role
  467. :return:
  468. """
  469. self.testapp.authorization = (
  470. 'Basic',
  471. (
  472. 'admin@admin.admin',
  473. 'admin@admin.admin'
  474. )
  475. )
  476. # create workspace role
  477. params = {
  478. 'user_id': 47,
  479. 'user_email_or_public_name': None,
  480. 'role': 'content-manager',
  481. }
  482. res = self.testapp.post_json(
  483. '/api/v2/workspaces/1/members',
  484. status=400,
  485. params=params,
  486. )
  487. def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8
  488. """
  489. Create workspace member role
  490. :return:
  491. """
  492. self.testapp.authorization = (
  493. 'Basic',
  494. (
  495. 'admin@admin.admin',
  496. 'admin@admin.admin'
  497. )
  498. )
  499. # create workspace role
  500. params = {
  501. 'user_id': None,
  502. 'user_email_or_public_name': 'nothing@nothing.nothing',
  503. 'role': 'content-manager',
  504. }
  505. res = self.testapp.post_json(
  506. '/api/v2/workspaces/1/members',
  507. status=200,
  508. params=params,
  509. )
  510. user_role_found = res.json_body
  511. assert user_role_found['role'] == 'content-manager'
  512. assert user_role_found['user_id']
  513. user_id = user_role_found['user_id']
  514. assert user_role_found['workspace_id'] == 1
  515. assert user_role_found['newly_created'] is True
  516. assert user_role_found['email_sent'] is False
  517. res = self.testapp.get('/api/v2/workspaces/1/members',
  518. status=200).json_body # nopep8
  519. assert len(res) == 2
  520. user_role = res[0]
  521. assert user_role['role'] == 'workspace-manager'
  522. assert user_role['user_id'] == 1
  523. assert user_role['workspace_id'] == 1
  524. user_role = res[1]
  525. assert user_role_found['role'] == user_role['role']
  526. assert user_role_found['user_id'] == user_role['user_id']
  527. assert user_role_found['workspace_id'] == user_role['workspace_id']
  528. def test_api__update_workspace_member_role__ok_200__nominal_case(self):
  529. """
  530. Update worskpace member role
  531. """
  532. # before
  533. self.testapp.authorization = (
  534. 'Basic',
  535. (
  536. 'admin@admin.admin',
  537. 'admin@admin.admin'
  538. )
  539. )
  540. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  541. assert len(res) == 1
  542. user_role = res[0]
  543. assert user_role['role'] == 'workspace-manager'
  544. assert user_role['user_id'] == 1
  545. assert user_role['workspace_id'] == 1
  546. # update workspace role
  547. params = {
  548. 'role': 'content-manager',
  549. }
  550. res = self.testapp.put_json(
  551. '/api/v2/workspaces/1/members/1',
  552. status=200,
  553. params=params,
  554. )
  555. user_role = res.json_body
  556. assert user_role['role'] == 'content-manager'
  557. assert user_role['user_id'] == 1
  558. assert user_role['workspace_id'] == 1
  559. # after
  560. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  561. assert len(res) == 1
  562. user_role = res[0]
  563. assert user_role['role'] == 'content-manager'
  564. assert user_role['user_id'] == 1
  565. assert user_role['workspace_id'] == 1
  566. class TestWorkspaceContents(FunctionalTest):
  567. """
  568. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  569. """
  570. fixtures = [BaseFixture, ContentFixtures]
  571. def test_api__get_workspace_content__ok_200__get_default(self):
  572. """
  573. Check obtain workspace contents with defaults filters
  574. """
  575. self.testapp.authorization = (
  576. 'Basic',
  577. (
  578. 'admin@admin.admin',
  579. 'admin@admin.admin'
  580. )
  581. )
  582. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  583. # TODO - G.M - 30-05-2018 - Check this test
  584. assert len(res) == 3
  585. content = res[0]
  586. assert content['content_id'] == 1
  587. assert content['is_archived'] is False
  588. assert content['is_deleted'] is False
  589. assert content['label'] == 'Tools'
  590. assert content['parent_id'] is None
  591. assert content['show_in_ui'] is True
  592. assert content['slug'] == 'tools'
  593. assert content['status'] == 'open'
  594. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  595. assert content['workspace_id'] == 1
  596. content = res[1]
  597. assert content['content_id'] == 2
  598. assert content['is_archived'] is False
  599. assert content['is_deleted'] is False
  600. assert content['label'] == 'Menus'
  601. assert content['parent_id'] is None
  602. assert content['show_in_ui'] is True
  603. assert content['slug'] == 'menus'
  604. assert content['status'] == 'open'
  605. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  606. assert content['workspace_id'] == 1
  607. content = res[2]
  608. assert content['content_id'] == 11
  609. assert content['is_archived'] is False
  610. assert content['is_deleted'] is False
  611. assert content['label'] == 'Current Menu'
  612. assert content['parent_id'] == 2
  613. assert content['show_in_ui'] is True
  614. assert content['slug'] == 'current-menu'
  615. assert content['status'] == 'open'
  616. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  617. assert content['workspace_id'] == 1
  618. # Root related
  619. def test_api__get_workspace_content__ok_200__get_all_root_content__legacy_html_slug(self): # nopep8
  620. """
  621. Check obtain workspace all root contents
  622. """
  623. set_html_document_slug_to_legacy(self.session_factory)
  624. params = {
  625. 'parent_id': 0,
  626. 'show_archived': 1,
  627. 'show_deleted': 1,
  628. 'show_active': 1,
  629. }
  630. self.testapp.authorization = (
  631. 'Basic',
  632. (
  633. 'bob@fsf.local',
  634. 'foobarbaz'
  635. )
  636. )
  637. res = self.testapp.get(
  638. '/api/v2/workspaces/3/contents',
  639. status=200,
  640. params=params,
  641. ).json_body # nopep8
  642. # TODO - G.M - 30-05-2018 - Check this test
  643. assert len(res) == 4
  644. content = res[1]
  645. assert content['content_type'] == 'html-documents'
  646. assert content['content_id'] == 15
  647. assert content['is_archived'] is False
  648. assert content['is_deleted'] is False
  649. assert content['label'] == 'New Fruit Salad'
  650. assert content['parent_id'] is None
  651. assert content['show_in_ui'] is True
  652. assert content['slug'] == 'new-fruit-salad'
  653. assert content['status'] == 'open'
  654. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  655. assert content['workspace_id'] == 3
  656. content = res[2]
  657. assert content['content_type'] == 'html-documents'
  658. assert content['content_id'] == 16
  659. assert content['is_archived'] is True
  660. assert content['is_deleted'] is False
  661. assert content['label'].startswith('Fruit Salad')
  662. assert content['parent_id'] is None
  663. assert content['show_in_ui'] is True
  664. assert content['slug'].startswith('fruit-salad')
  665. assert content['status'] == 'open'
  666. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  667. assert content['workspace_id'] == 3
  668. content = res[3]
  669. assert content['content_type'] == 'html-documents'
  670. assert content['content_id'] == 17
  671. assert content['is_archived'] is False
  672. assert content['is_deleted'] is True
  673. assert content['label'].startswith('Bad Fruit Salad')
  674. assert content['parent_id'] is None
  675. assert content['show_in_ui'] is True
  676. assert content['slug'].startswith('bad-fruit-salad')
  677. assert content['status'] == 'open'
  678. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  679. assert content['workspace_id'] == 3
  680. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  681. """
  682. Check obtain workspace all root contents
  683. """
  684. params = {
  685. 'parent_id': 0,
  686. 'show_archived': 1,
  687. 'show_deleted': 1,
  688. 'show_active': 1,
  689. }
  690. self.testapp.authorization = (
  691. 'Basic',
  692. (
  693. 'bob@fsf.local',
  694. 'foobarbaz'
  695. )
  696. )
  697. res = self.testapp.get(
  698. '/api/v2/workspaces/3/contents',
  699. status=200,
  700. params=params,
  701. ).json_body # nopep8
  702. # TODO - G.M - 30-05-2018 - Check this test
  703. assert len(res) == 4
  704. content = res[1]
  705. assert content['content_type'] == 'html-documents'
  706. assert content['content_id'] == 15
  707. assert content['is_archived'] is False
  708. assert content['is_deleted'] is False
  709. assert content['label'] == 'New Fruit Salad'
  710. assert content['parent_id'] is None
  711. assert content['show_in_ui'] is True
  712. assert content['slug'] == 'new-fruit-salad'
  713. assert content['status'] == 'open'
  714. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  715. assert content['workspace_id'] == 3
  716. content = res[2]
  717. assert content['content_type'] == 'html-documents'
  718. assert content['content_id'] == 16
  719. assert content['is_archived'] is True
  720. assert content['is_deleted'] is False
  721. assert content['label'].startswith('Fruit Salad')
  722. assert content['parent_id'] is None
  723. assert content['show_in_ui'] is True
  724. assert content['slug'].startswith('fruit-salad')
  725. assert content['status'] == 'open'
  726. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  727. assert content['workspace_id'] == 3
  728. content = res[3]
  729. assert content['content_type'] == 'html-documents'
  730. assert content['content_id'] == 17
  731. assert content['is_archived'] is False
  732. assert content['is_deleted'] is True
  733. assert content['label'].startswith('Bad Fruit Salad')
  734. assert content['parent_id'] is None
  735. assert content['show_in_ui'] is True
  736. assert content['slug'].startswith('bad-fruit-salad')
  737. assert content['status'] == 'open'
  738. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  739. assert content['workspace_id'] == 3
  740. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8
  741. """
  742. Check obtain workspace root active contents
  743. """
  744. params = {
  745. 'parent_id': 0,
  746. 'show_archived': 0,
  747. 'show_deleted': 0,
  748. 'show_active': 1,
  749. }
  750. self.testapp.authorization = (
  751. 'Basic',
  752. (
  753. 'bob@fsf.local',
  754. 'foobarbaz'
  755. )
  756. )
  757. res = self.testapp.get(
  758. '/api/v2/workspaces/3/contents',
  759. status=200,
  760. params=params,
  761. ).json_body # nopep8
  762. # TODO - G.M - 30-05-2018 - Check this test
  763. assert len(res) == 2
  764. content = res[1]
  765. assert content['content_type'] == 'html-documents'
  766. assert content['content_id'] == 15
  767. assert content['is_archived'] is False
  768. assert content['is_deleted'] is False
  769. assert content['label'] == 'New Fruit Salad'
  770. assert content['parent_id'] is None
  771. assert content['show_in_ui'] is True
  772. assert content['slug'] == 'new-fruit-salad'
  773. assert content['status'] == 'open'
  774. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  775. assert content['workspace_id'] == 3
  776. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8
  777. """
  778. Check obtain workspace root archived contents
  779. """
  780. params = {
  781. 'parent_id': 0,
  782. 'show_archived': 1,
  783. 'show_deleted': 0,
  784. 'show_active': 0,
  785. }
  786. self.testapp.authorization = (
  787. 'Basic',
  788. (
  789. 'bob@fsf.local',
  790. 'foobarbaz'
  791. )
  792. )
  793. res = self.testapp.get(
  794. '/api/v2/workspaces/3/contents',
  795. status=200,
  796. params=params,
  797. ).json_body # nopep8
  798. assert len(res) == 1
  799. content = res[0]
  800. assert content['content_type'] == 'html-documents'
  801. assert content['content_id'] == 16
  802. assert content['is_archived'] is True
  803. assert content['is_deleted'] is False
  804. assert content['label'].startswith('Fruit Salad')
  805. assert content['parent_id'] is None
  806. assert content['show_in_ui'] is True
  807. assert content['slug'].startswith('fruit-salad')
  808. assert content['status'] == 'open'
  809. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  810. assert content['workspace_id'] == 3
  811. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8
  812. """
  813. Check obtain workspace root deleted contents
  814. """
  815. params = {
  816. 'parent_id': 0,
  817. 'show_archived': 0,
  818. 'show_deleted': 1,
  819. 'show_active': 0,
  820. }
  821. self.testapp.authorization = (
  822. 'Basic',
  823. (
  824. 'bob@fsf.local',
  825. 'foobarbaz'
  826. )
  827. )
  828. res = self.testapp.get(
  829. '/api/v2/workspaces/3/contents',
  830. status=200,
  831. params=params,
  832. ).json_body # nopep8
  833. # TODO - G.M - 30-05-2018 - Check this test
  834. assert len(res) == 1
  835. content = res[0]
  836. assert content['content_type'] == 'html-documents'
  837. assert content['content_id'] == 17
  838. assert content['is_archived'] is False
  839. assert content['is_deleted'] is True
  840. assert content['label'].startswith('Bad Fruit Salad')
  841. assert content['parent_id'] is None
  842. assert content['show_in_ui'] is True
  843. assert content['slug'].startswith('bad-fruit-salad')
  844. assert content['status'] == 'open'
  845. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  846. assert content['workspace_id'] == 3
  847. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  848. """
  849. Check obtain workspace root content who does not match any type
  850. (archived, deleted, active) result should be empty list.
  851. """
  852. params = {
  853. 'parent_id': 0,
  854. 'show_archived': 0,
  855. 'show_deleted': 0,
  856. 'show_active': 0,
  857. }
  858. self.testapp.authorization = (
  859. 'Basic',
  860. (
  861. 'bob@fsf.local',
  862. 'foobarbaz'
  863. )
  864. )
  865. res = self.testapp.get(
  866. '/api/v2/workspaces/3/contents',
  867. status=200,
  868. params=params,
  869. ).json_body # nopep8
  870. # TODO - G.M - 30-05-2018 - Check this test
  871. assert res == []
  872. # Folder related
  873. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  874. """
  875. Check obtain workspace folder all contents
  876. """
  877. params = {
  878. 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id
  879. 'show_archived': 1,
  880. 'show_deleted': 1,
  881. 'show_active': 1,
  882. }
  883. self.testapp.authorization = (
  884. 'Basic',
  885. (
  886. 'admin@admin.admin',
  887. 'admin@admin.admin'
  888. )
  889. )
  890. res = self.testapp.get(
  891. '/api/v2/workspaces/2/contents',
  892. status=200,
  893. params=params,
  894. ).json_body # nopep8
  895. assert len(res) == 3
  896. content = res[0]
  897. assert content['content_type'] == 'html-documents'
  898. assert content['content_id'] == 12
  899. assert content['is_archived'] is False
  900. assert content['is_deleted'] is False
  901. assert content['label'] == 'New Fruit Salad'
  902. assert content['parent_id'] == 10
  903. assert content['show_in_ui'] is True
  904. assert content['slug'] == 'new-fruit-salad'
  905. assert content['status'] == 'open'
  906. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  907. assert content['workspace_id'] == 2
  908. content = res[1]
  909. assert content['content_type'] == 'html-documents'
  910. assert content['content_id'] == 13
  911. assert content['is_archived'] is True
  912. assert content['is_deleted'] is False
  913. assert content['label'].startswith('Fruit Salad')
  914. assert content['parent_id'] == 10
  915. assert content['show_in_ui'] is True
  916. assert content['slug'].startswith('fruit-salad')
  917. assert content['status'] == 'open'
  918. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  919. assert content['workspace_id'] == 2
  920. content = res[2]
  921. assert content['content_type'] == 'html-documents'
  922. assert content['content_id'] == 14
  923. assert content['is_archived'] is False
  924. assert content['is_deleted'] is True
  925. assert content['label'].startswith('Bad Fruit Salad')
  926. assert content['parent_id'] == 10
  927. assert content['show_in_ui'] is True
  928. assert content['slug'].startswith('bad-fruit-salad')
  929. assert content['status'] == 'open'
  930. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  931. assert content['workspace_id'] == 2
  932. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8
  933. """
  934. Check obtain workspace folder active contents
  935. """
  936. params = {
  937. 'parent_id': 10,
  938. 'show_archived': 0,
  939. 'show_deleted': 0,
  940. 'show_active': 1,
  941. }
  942. self.testapp.authorization = (
  943. 'Basic',
  944. (
  945. 'admin@admin.admin',
  946. 'admin@admin.admin'
  947. )
  948. )
  949. res = self.testapp.get(
  950. '/api/v2/workspaces/2/contents',
  951. status=200,
  952. params=params,
  953. ).json_body # nopep8
  954. assert len(res) == 1
  955. content = res[0]
  956. assert content['content_type']
  957. assert content['content_id'] == 12
  958. assert content['is_archived'] is False
  959. assert content['is_deleted'] is False
  960. assert content['label'] == 'New Fruit Salad'
  961. assert content['parent_id'] == 10
  962. assert content['show_in_ui'] is True
  963. assert content['slug'] == 'new-fruit-salad'
  964. assert content['status'] == 'open'
  965. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  966. assert content['workspace_id'] == 2
  967. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8
  968. """
  969. Check obtain workspace folder archived contents
  970. """
  971. params = {
  972. 'parent_id': 10,
  973. 'show_archived': 1,
  974. 'show_deleted': 0,
  975. 'show_active': 0,
  976. }
  977. self.testapp.authorization = (
  978. 'Basic',
  979. (
  980. 'admin@admin.admin',
  981. 'admin@admin.admin'
  982. )
  983. )
  984. res = self.testapp.get(
  985. '/api/v2/workspaces/2/contents',
  986. status=200,
  987. params=params,
  988. ).json_body # nopep8
  989. assert len(res) == 1
  990. content = res[0]
  991. assert content['content_type'] == 'html-documents'
  992. assert content['content_id'] == 13
  993. assert content['is_archived'] is True
  994. assert content['is_deleted'] is False
  995. assert content['label'].startswith('Fruit Salad')
  996. assert content['parent_id'] == 10
  997. assert content['show_in_ui'] is True
  998. assert content['slug'].startswith('fruit-salad')
  999. assert content['status'] == 'open'
  1000. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1001. assert content['workspace_id'] == 2
  1002. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8
  1003. """
  1004. Check obtain workspace folder deleted contents
  1005. """
  1006. params = {
  1007. 'parent_id': 10,
  1008. 'show_archived': 0,
  1009. 'show_deleted': 1,
  1010. 'show_active': 0,
  1011. }
  1012. self.testapp.authorization = (
  1013. 'Basic',
  1014. (
  1015. 'admin@admin.admin',
  1016. 'admin@admin.admin'
  1017. )
  1018. )
  1019. res = self.testapp.get(
  1020. '/api/v2/workspaces/2/contents',
  1021. status=200,
  1022. params=params,
  1023. ).json_body # nopep8
  1024. assert len(res) == 1
  1025. content = res[0]
  1026. assert content['content_type'] == 'html-documents'
  1027. assert content['content_id'] == 14
  1028. assert content['is_archived'] is False
  1029. assert content['is_deleted'] is True
  1030. assert content['label'].startswith('Bad Fruit Salad')
  1031. assert content['parent_id'] == 10
  1032. assert content['show_in_ui'] is True
  1033. assert content['slug'].startswith('bad-fruit-salad')
  1034. assert content['status'] == 'open'
  1035. assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'} # nopep8
  1036. assert content['workspace_id'] == 2
  1037. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8
  1038. """
  1039. Check obtain workspace folder content who does not match any type
  1040. (archived, deleted, active) result should be empty list.
  1041. """
  1042. params = {
  1043. 'parent_id': 10,
  1044. 'show_archived': 0,
  1045. 'show_deleted': 0,
  1046. 'show_active': 0,
  1047. }
  1048. self.testapp.authorization = (
  1049. 'Basic',
  1050. (
  1051. 'admin@admin.admin',
  1052. 'admin@admin.admin'
  1053. )
  1054. )
  1055. res = self.testapp.get(
  1056. '/api/v2/workspaces/2/contents',
  1057. status=200,
  1058. params=params,
  1059. ).json_body # nopep8
  1060. # TODO - G.M - 30-05-2018 - Check this test
  1061. assert res == []
  1062. # Error case
  1063. def test_api__get_workspace_content__err_400__unallowed_user(self):
  1064. """
  1065. Check obtain workspace content list with an unreachable workspace for
  1066. user
  1067. """
  1068. self.testapp.authorization = (
  1069. 'Basic',
  1070. (
  1071. 'lawrence-not-real-email@fsf.local',
  1072. 'foobarbaz'
  1073. )
  1074. )
  1075. res = self.testapp.get('/api/v2/workspaces/3/contents', status=400)
  1076. assert isinstance(res.json, dict)
  1077. assert 'code' in res.json.keys()
  1078. assert 'message' in res.json.keys()
  1079. assert 'details' in res.json.keys()
  1080. def test_api__get_workspace_content__err_401__unregistered_user(self):
  1081. """
  1082. Check obtain workspace content list with an unregistered user
  1083. """
  1084. self.testapp.authorization = (
  1085. 'Basic',
  1086. (
  1087. 'john@doe.doe',
  1088. 'lapin'
  1089. )
  1090. )
  1091. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  1092. assert isinstance(res.json, dict)
  1093. assert 'code' in res.json.keys()
  1094. assert 'message' in res.json.keys()
  1095. assert 'details' in res.json.keys()
  1096. def test_api__get_workspace_content__err_400__workspace_does_not_exist(self): # nopep8
  1097. """
  1098. Check obtain workspace contents list with an existing user but
  1099. an unexisting workspace
  1100. """
  1101. self.testapp.authorization = (
  1102. 'Basic',
  1103. (
  1104. 'admin@admin.admin',
  1105. 'admin@admin.admin'
  1106. )
  1107. )
  1108. res = self.testapp.get('/api/v2/workspaces/5/contents', status=400)
  1109. assert isinstance(res.json, dict)
  1110. assert 'code' in res.json.keys()
  1111. assert 'message' in res.json.keys()
  1112. assert 'details' in res.json.keys()
  1113. def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8
  1114. """
  1115. Create generic content
  1116. """
  1117. self.testapp.authorization = (
  1118. 'Basic',
  1119. (
  1120. 'admin@admin.admin',
  1121. 'admin@admin.admin'
  1122. )
  1123. )
  1124. params = {
  1125. 'label': 'GenericCreatedContent',
  1126. 'content_type': 'markdownpage',
  1127. }
  1128. res = self.testapp.post_json(
  1129. '/api/v2/workspaces/1/contents',
  1130. params=params,
  1131. status=200
  1132. )
  1133. assert res
  1134. assert res.json_body
  1135. assert res.json_body['status'] == 'open'
  1136. assert res.json_body['content_id']
  1137. assert res.json_body['content_type'] == 'markdownpage'
  1138. assert res.json_body['is_archived'] is False
  1139. assert res.json_body['is_deleted'] is False
  1140. assert res.json_body['workspace_id'] == 1
  1141. assert res.json_body['slug'] == 'genericcreatedcontent'
  1142. assert res.json_body['parent_id'] is None
  1143. assert res.json_body['show_in_ui'] is True
  1144. assert res.json_body['sub_content_types']
  1145. params_active = {
  1146. 'parent_id': 0,
  1147. 'show_archived': 0,
  1148. 'show_deleted': 0,
  1149. 'show_active': 1,
  1150. }
  1151. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1152. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1153. assert res.json_body in active_contents
  1154. def test_api__post_content_create_generic_content__err_400__empty_label(self) -> None: # nopep8
  1155. """
  1156. Create generic content
  1157. """
  1158. self.testapp.authorization = (
  1159. 'Basic',
  1160. (
  1161. 'admin@admin.admin',
  1162. 'admin@admin.admin'
  1163. )
  1164. )
  1165. params = {
  1166. 'label': '',
  1167. 'content_type': 'markdownpage',
  1168. }
  1169. res = self.testapp.post_json(
  1170. '/api/v2/workspaces/1/contents',
  1171. params=params,
  1172. status=400
  1173. )
  1174. def test_api__post_content_create_generic_content__err_400__wrong_content_type(self) -> None: # nopep8
  1175. """
  1176. Create generic content
  1177. """
  1178. self.testapp.authorization = (
  1179. 'Basic',
  1180. (
  1181. 'admin@admin.admin',
  1182. 'admin@admin.admin'
  1183. )
  1184. )
  1185. params = {
  1186. 'label': 'GenericCreatedContent',
  1187. 'content_type': 'unexistent-content-type',
  1188. }
  1189. res = self.testapp.post_json(
  1190. '/api/v2/workspaces/1/contents',
  1191. params=params,
  1192. status=400,
  1193. )
  1194. def test_api_put_move_content__ok_200__nominal_case(self):
  1195. """
  1196. Move content
  1197. move Apple_Pie (content_id: 8)
  1198. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1199. of workspace Recipes.
  1200. """
  1201. self.testapp.authorization = (
  1202. 'Basic',
  1203. (
  1204. 'admin@admin.admin',
  1205. 'admin@admin.admin'
  1206. )
  1207. )
  1208. params = {
  1209. 'new_parent_id': '4', # Salads
  1210. 'new_workspace_id': '2',
  1211. }
  1212. params_folder1 = {
  1213. 'parent_id': 3,
  1214. 'show_archived': 0,
  1215. 'show_deleted': 0,
  1216. 'show_active': 1,
  1217. }
  1218. params_folder2 = {
  1219. 'parent_id': 4,
  1220. 'show_archived': 0,
  1221. 'show_deleted': 0,
  1222. 'show_active': 1,
  1223. }
  1224. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1225. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1226. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1227. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1228. # TODO - G.M - 2018-06-163 - Check content
  1229. res = self.testapp.put_json(
  1230. '/api/v2/workspaces/2/contents/8/move',
  1231. params=params,
  1232. status=200
  1233. )
  1234. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1235. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1236. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1237. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1238. assert res.json_body
  1239. assert res.json_body['parent_id'] == 4
  1240. assert res.json_body['content_id'] == 8
  1241. assert res.json_body['workspace_id'] == 2
  1242. def test_api_put_move_content__ok_200__to_root(self):
  1243. """
  1244. Move content
  1245. move Apple_Pie (content_id: 8)
  1246. from Desserts folder(content_id: 3) to root (content_id: 0)
  1247. of workspace Recipes.
  1248. """
  1249. self.testapp.authorization = (
  1250. 'Basic',
  1251. (
  1252. 'admin@admin.admin',
  1253. 'admin@admin.admin'
  1254. )
  1255. )
  1256. params = {
  1257. 'new_parent_id': None, # root
  1258. 'new_workspace_id': 2,
  1259. }
  1260. params_folder1 = {
  1261. 'parent_id': 3,
  1262. 'show_archived': 0,
  1263. 'show_deleted': 0,
  1264. 'show_active': 1,
  1265. }
  1266. params_folder2 = {
  1267. 'parent_id': 0,
  1268. 'show_archived': 0,
  1269. 'show_deleted': 0,
  1270. 'show_active': 1,
  1271. }
  1272. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1273. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1274. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1275. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1276. # TODO - G.M - 2018-06-163 - Check content
  1277. res = self.testapp.put_json(
  1278. '/api/v2/workspaces/2/contents/8/move',
  1279. params=params,
  1280. status=200
  1281. )
  1282. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1283. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1284. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1285. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1286. assert res.json_body
  1287. assert res.json_body['parent_id'] is None
  1288. assert res.json_body['content_id'] == 8
  1289. assert res.json_body['workspace_id'] == 2
  1290. def test_api_put_move_content__ok_200__with_workspace_id(self):
  1291. """
  1292. Move content
  1293. move Apple_Pie (content_id: 8)
  1294. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1295. of workspace Recipes.
  1296. """
  1297. self.testapp.authorization = (
  1298. 'Basic',
  1299. (
  1300. 'admin@admin.admin',
  1301. 'admin@admin.admin'
  1302. )
  1303. )
  1304. params = {
  1305. 'new_parent_id': '4', # Salads
  1306. 'new_workspace_id': '2',
  1307. }
  1308. params_folder1 = {
  1309. 'parent_id': 3,
  1310. 'show_archived': 0,
  1311. 'show_deleted': 0,
  1312. 'show_active': 1,
  1313. }
  1314. params_folder2 = {
  1315. 'parent_id': 4,
  1316. 'show_archived': 0,
  1317. 'show_deleted': 0,
  1318. 'show_active': 1,
  1319. }
  1320. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1321. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1322. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1323. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1324. # TODO - G.M - 2018-06-163 - Check content
  1325. res = self.testapp.put_json(
  1326. '/api/v2/workspaces/2/contents/8/move',
  1327. params=params,
  1328. status=200
  1329. )
  1330. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1331. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1332. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1333. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1334. assert res.json_body
  1335. assert res.json_body['parent_id'] == 4
  1336. assert res.json_body['content_id'] == 8
  1337. assert res.json_body['workspace_id'] == 2
  1338. def test_api_put_move_content__ok_200__to_another_workspace(self):
  1339. """
  1340. Move content
  1341. move Apple_Pie (content_id: 8)
  1342. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  1343. of workspace Business.
  1344. """
  1345. self.testapp.authorization = (
  1346. 'Basic',
  1347. (
  1348. 'admin@admin.admin',
  1349. 'admin@admin.admin'
  1350. )
  1351. )
  1352. params = {
  1353. 'new_parent_id': '2', # Menus
  1354. 'new_workspace_id': '1',
  1355. }
  1356. params_folder1 = {
  1357. 'parent_id': 3,
  1358. 'show_archived': 0,
  1359. 'show_deleted': 0,
  1360. 'show_active': 1,
  1361. }
  1362. params_folder2 = {
  1363. 'parent_id': 2,
  1364. 'show_archived': 0,
  1365. 'show_deleted': 0,
  1366. 'show_active': 1,
  1367. }
  1368. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1369. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1370. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1371. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1372. # TODO - G.M - 2018-06-163 - Check content
  1373. res = self.testapp.put_json(
  1374. '/api/v2/workspaces/2/contents/8/move',
  1375. params=params,
  1376. status=200
  1377. )
  1378. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1379. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1380. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1381. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1382. assert res.json_body
  1383. assert res.json_body['parent_id'] == 2
  1384. assert res.json_body['content_id'] == 8
  1385. assert res.json_body['workspace_id'] == 1
  1386. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  1387. """
  1388. Move content
  1389. move Apple_Pie (content_id: 8)
  1390. from Desserts folder(content_id: 3) to root (content_id: 0)
  1391. of workspace Business.
  1392. """
  1393. self.testapp.authorization = (
  1394. 'Basic',
  1395. (
  1396. 'admin@admin.admin',
  1397. 'admin@admin.admin'
  1398. )
  1399. )
  1400. params = {
  1401. 'new_parent_id': None, # root
  1402. 'new_workspace_id': '1',
  1403. }
  1404. params_folder1 = {
  1405. 'parent_id': 3,
  1406. 'show_archived': 0,
  1407. 'show_deleted': 0,
  1408. 'show_active': 1,
  1409. }
  1410. params_folder2 = {
  1411. 'parent_id': 0,
  1412. 'show_archived': 0,
  1413. 'show_deleted': 0,
  1414. 'show_active': 1,
  1415. }
  1416. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1417. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1418. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1419. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1420. # TODO - G.M - 2018-06-163 - Check content
  1421. res = self.testapp.put_json(
  1422. '/api/v2/workspaces/2/contents/8/move',
  1423. params=params,
  1424. status=200
  1425. )
  1426. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1427. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1428. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1429. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1430. assert res.json_body
  1431. assert res.json_body['parent_id'] is None
  1432. assert res.json_body['content_id'] == 8
  1433. assert res.json_body['workspace_id'] == 1
  1434. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  1435. """
  1436. Move content
  1437. move Apple_Pie (content_id: 8)
  1438. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1439. of workspace Recipes.
  1440. Workspace_id of parent_id don't match with workspace_id of workspace
  1441. """
  1442. self.testapp.authorization = (
  1443. 'Basic',
  1444. (
  1445. 'admin@admin.admin',
  1446. 'admin@admin.admin'
  1447. )
  1448. )
  1449. params = {
  1450. 'new_parent_id': '4', # Salads
  1451. 'new_workspace_id': '1',
  1452. }
  1453. params_folder1 = {
  1454. 'parent_id': 3,
  1455. 'show_archived': 0,
  1456. 'show_deleted': 0,
  1457. 'show_active': 1,
  1458. }
  1459. params_folder2 = {
  1460. 'parent_id': 4,
  1461. 'show_archived': 0,
  1462. 'show_deleted': 0,
  1463. 'show_active': 1,
  1464. }
  1465. res = self.testapp.put_json(
  1466. '/api/v2/workspaces/2/contents/8/move',
  1467. params=params,
  1468. status=400,
  1469. )
  1470. def test_api_put_delete_content__ok_200__nominal_case(self):
  1471. """
  1472. delete content
  1473. delete Apple_pie ( content_id: 8, parent_id: 3)
  1474. """
  1475. self.testapp.authorization = (
  1476. 'Basic',
  1477. (
  1478. 'admin@admin.admin',
  1479. 'admin@admin.admin'
  1480. )
  1481. )
  1482. params_active = {
  1483. 'parent_id': 3,
  1484. 'show_archived': 0,
  1485. 'show_deleted': 0,
  1486. 'show_active': 1,
  1487. }
  1488. params_deleted = {
  1489. 'parent_id': 3,
  1490. 'show_archived': 0,
  1491. 'show_deleted': 1,
  1492. 'show_active': 0,
  1493. }
  1494. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1495. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1496. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1497. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1498. # TODO - G.M - 2018-06-163 - Check content
  1499. res = self.testapp.put_json(
  1500. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1501. '/api/v2/workspaces/2/contents/8/delete',
  1502. status=204
  1503. )
  1504. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1505. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1506. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1507. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1508. def test_api_put_archive_content__ok_200__nominal_case(self):
  1509. """
  1510. archive content
  1511. archive Apple_pie ( content_id: 8, parent_id: 3)
  1512. """
  1513. self.testapp.authorization = (
  1514. 'Basic',
  1515. (
  1516. 'admin@admin.admin',
  1517. 'admin@admin.admin'
  1518. )
  1519. )
  1520. params_active = {
  1521. 'parent_id': 3,
  1522. 'show_archived': 0,
  1523. 'show_deleted': 0,
  1524. 'show_active': 1,
  1525. }
  1526. params_archived = {
  1527. 'parent_id': 3,
  1528. 'show_archived': 1,
  1529. 'show_deleted': 0,
  1530. 'show_active': 0,
  1531. }
  1532. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1533. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1534. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1535. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1536. res = self.testapp.put_json(
  1537. '/api/v2/workspaces/2/contents/8/archive',
  1538. status=204
  1539. )
  1540. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1541. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1542. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1543. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1544. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1545. """
  1546. Undelete content
  1547. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1548. """
  1549. self.testapp.authorization = (
  1550. 'Basic',
  1551. (
  1552. 'bob@fsf.local',
  1553. 'foobarbaz'
  1554. )
  1555. )
  1556. params_active = {
  1557. 'parent_id': 10,
  1558. 'show_archived': 0,
  1559. 'show_deleted': 0,
  1560. 'show_active': 1,
  1561. }
  1562. params_deleted = {
  1563. 'parent_id': 10,
  1564. 'show_archived': 0,
  1565. 'show_deleted': 1,
  1566. 'show_active': 0,
  1567. }
  1568. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1569. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1570. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1571. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1572. res = self.testapp.put_json(
  1573. '/api/v2/workspaces/2/contents/14/undelete',
  1574. status=204
  1575. )
  1576. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1577. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1578. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1579. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1580. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1581. """
  1582. unarchive content,
  1583. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1584. """
  1585. self.testapp.authorization = (
  1586. 'Basic',
  1587. (
  1588. 'bob@fsf.local',
  1589. 'foobarbaz'
  1590. )
  1591. )
  1592. params_active = {
  1593. 'parent_id': 10,
  1594. 'show_archived': 0,
  1595. 'show_deleted': 0,
  1596. 'show_active': 1,
  1597. }
  1598. params_archived = {
  1599. 'parent_id': 10,
  1600. 'show_archived': 1,
  1601. 'show_deleted': 0,
  1602. 'show_active': 0,
  1603. }
  1604. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1605. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1606. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  1607. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  1608. res = self.testapp.put_json(
  1609. '/api/v2/workspaces/2/contents/13/unarchive',
  1610. status=204
  1611. )
  1612. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1613. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1614. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  1615. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8