test_workspaces.py 78KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for /api/v2/workspaces subpath endpoints.
  4. """
  5. import requests
  6. import transaction
  7. from depot.io.utils import FileIntent
  8. from tracim_backend import models
  9. from tracim_backend.lib.core.content import ContentApi
  10. from tracim_backend.lib.core.workspace import WorkspaceApi
  11. from tracim_backend.models import get_tm_session
  12. from tracim_backend.models.contents import CONTENT_TYPES
  13. from tracim_backend.tests import FunctionalTest
  14. from tracim_backend.tests import set_html_document_slug_to_legacy
  15. from tracim_backend.fixtures.content import Content as ContentFixtures
  16. from tracim_backend.fixtures.users_and_groups import Base as BaseFixture
  17. class TestWorkspaceEndpoint(FunctionalTest):
  18. """
  19. Tests for /api/v2/workspaces/{workspace_id} endpoint
  20. """
  21. fixtures = [BaseFixture, ContentFixtures]
  22. def test_api__get_workspace__ok_200__nominal_case(self) -> None:
  23. """
  24. Check obtain workspace reachable for user.
  25. """
  26. self.testapp.authorization = (
  27. 'Basic',
  28. (
  29. 'admin@admin.admin',
  30. 'admin@admin.admin'
  31. )
  32. )
  33. res = self.testapp.get('/api/v2/workspaces/1', status=200)
  34. workspace = res.json_body
  35. assert workspace['workspace_id'] == 1
  36. assert workspace['slug'] == 'business'
  37. assert workspace['label'] == 'Business'
  38. assert workspace['description'] == 'All importants documents'
  39. assert len(workspace['sidebar_entries']) == 5
  40. # TODO - G.M - 2018-08-02 - Better test for sidebar entry, make it
  41. # not fixed on active application/content-file
  42. sidebar_entry = workspace['sidebar_entries'][0]
  43. assert sidebar_entry['slug'] == 'dashboard'
  44. assert sidebar_entry['label'] == 'Dashboard'
  45. assert sidebar_entry['route'] == '/#/workspaces/1/dashboard' # nopep8
  46. assert sidebar_entry['hexcolor'] == "#252525"
  47. assert sidebar_entry['fa_icon'] == "signal"
  48. sidebar_entry = workspace['sidebar_entries'][1]
  49. assert sidebar_entry['slug'] == 'contents/all'
  50. assert sidebar_entry['label'] == 'All Contents'
  51. assert sidebar_entry['route'] == "/#/workspaces/1/contents" # nopep8
  52. assert sidebar_entry['hexcolor'] == "#fdfdfd"
  53. assert sidebar_entry['fa_icon'] == "th"
  54. sidebar_entry = workspace['sidebar_entries'][2]
  55. assert sidebar_entry['slug'] == 'contents/html-document'
  56. assert sidebar_entry['label'] == 'Text Documents'
  57. assert sidebar_entry['route'] == '/#/workspaces/1/contents?type=html-document' # nopep8
  58. assert sidebar_entry['hexcolor'] == "#3f52e3"
  59. assert sidebar_entry['fa_icon'] == "file-text-o"
  60. sidebar_entry = workspace['sidebar_entries'][3]
  61. assert sidebar_entry['slug'] == 'contents/file'
  62. assert sidebar_entry['label'] == 'Files'
  63. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=file" # nopep8
  64. assert sidebar_entry['hexcolor'] == "#FF9900"
  65. assert sidebar_entry['fa_icon'] == "paperclip"
  66. sidebar_entry = workspace['sidebar_entries'][4]
  67. assert sidebar_entry['slug'] == 'contents/thread'
  68. assert sidebar_entry['label'] == 'Threads'
  69. assert sidebar_entry['route'] == "/#/workspaces/1/contents?type=thread" # nopep8
  70. assert sidebar_entry['hexcolor'] == "#ad4cf9"
  71. assert sidebar_entry['fa_icon'] == "comments-o"
  72. def test_api__update_workspace__ok_200__nominal_case(self) -> None:
  73. """
  74. Test update workspace
  75. """
  76. self.testapp.authorization = (
  77. 'Basic',
  78. (
  79. 'admin@admin.admin',
  80. 'admin@admin.admin'
  81. )
  82. )
  83. params = {
  84. 'label': 'superworkspace',
  85. 'description': 'mysuperdescription'
  86. }
  87. # Before
  88. res = self.testapp.get(
  89. '/api/v2/workspaces/1',
  90. status=200
  91. )
  92. assert res.json_body
  93. workspace = res.json_body
  94. assert workspace['workspace_id'] == 1
  95. assert workspace['slug'] == 'business'
  96. assert workspace['label'] == 'Business'
  97. assert workspace['description'] == 'All importants documents'
  98. assert len(workspace['sidebar_entries']) == 5
  99. # modify workspace
  100. res = self.testapp.put_json(
  101. '/api/v2/workspaces/1',
  102. status=200,
  103. params=params,
  104. )
  105. assert res.json_body
  106. workspace = res.json_body
  107. assert workspace['workspace_id'] == 1
  108. assert workspace['slug'] == 'superworkspace'
  109. assert workspace['label'] == 'superworkspace'
  110. assert workspace['description'] == 'mysuperdescription'
  111. assert len(workspace['sidebar_entries']) == 5
  112. # after
  113. res = self.testapp.get(
  114. '/api/v2/workspaces/1',
  115. status=200
  116. )
  117. assert res.json_body
  118. workspace = res.json_body
  119. assert workspace['workspace_id'] == 1
  120. assert workspace['slug'] == 'superworkspace'
  121. assert workspace['label'] == 'superworkspace'
  122. assert workspace['description'] == 'mysuperdescription'
  123. assert len(workspace['sidebar_entries']) == 5
  124. def test_api__update_workspace__err_400__empty_label(self) -> None:
  125. """
  126. Test update workspace with empty label
  127. """
  128. self.testapp.authorization = (
  129. 'Basic',
  130. (
  131. 'admin@admin.admin',
  132. 'admin@admin.admin'
  133. )
  134. )
  135. params = {
  136. 'label': '',
  137. 'description': 'mysuperdescription'
  138. }
  139. res = self.testapp.put_json(
  140. '/api/v2/workspaces/1',
  141. status=400,
  142. params=params,
  143. )
  144. def test_api__create_workspace__ok_200__nominal_case(self) -> None:
  145. """
  146. Test create workspace
  147. """
  148. self.testapp.authorization = (
  149. 'Basic',
  150. (
  151. 'admin@admin.admin',
  152. 'admin@admin.admin'
  153. )
  154. )
  155. params = {
  156. 'label': 'superworkspace',
  157. 'description': 'mysuperdescription'
  158. }
  159. res = self.testapp.post_json(
  160. '/api/v2/workspaces',
  161. status=200,
  162. params=params,
  163. )
  164. assert res.json_body
  165. workspace = res.json_body
  166. workspace_id = res.json_body['workspace_id']
  167. res = self.testapp.get(
  168. '/api/v2/workspaces/{}'.format(workspace_id),
  169. status=200
  170. )
  171. workspace_2 = res.json_body
  172. assert workspace == workspace_2
  173. def test_api__create_workspace__err_400__empty_label(self) -> None:
  174. """
  175. Test create workspace with empty label
  176. """
  177. self.testapp.authorization = (
  178. 'Basic',
  179. (
  180. 'admin@admin.admin',
  181. 'admin@admin.admin'
  182. )
  183. )
  184. params = {
  185. 'label': '',
  186. 'description': 'mysuperdescription'
  187. }
  188. res = self.testapp.post_json(
  189. '/api/v2/workspaces',
  190. status=400,
  191. params=params,
  192. )
  193. def test_api__get_workspace__err_400__unallowed_user(self) -> None:
  194. """
  195. Check obtain workspace unreachable for user
  196. """
  197. self.testapp.authorization = (
  198. 'Basic',
  199. (
  200. 'lawrence-not-real-email@fsf.local',
  201. 'foobarbaz'
  202. )
  203. )
  204. res = self.testapp.get('/api/v2/workspaces/1', status=400)
  205. assert isinstance(res.json, dict)
  206. assert 'code' in res.json.keys()
  207. assert 'message' in res.json.keys()
  208. assert 'details' in res.json.keys()
  209. def test_api__get_workspace__err_401__unregistered_user(self) -> None:
  210. """
  211. Check obtain workspace without registered user.
  212. """
  213. self.testapp.authorization = (
  214. 'Basic',
  215. (
  216. 'john@doe.doe',
  217. 'lapin'
  218. )
  219. )
  220. res = self.testapp.get('/api/v2/workspaces/1', status=401)
  221. assert isinstance(res.json, dict)
  222. assert 'code' in res.json.keys()
  223. assert 'message' in res.json.keys()
  224. assert 'details' in res.json.keys()
  225. def test_api__get_workspace__err_400__workspace_does_not_exist(self) -> None: # nopep8
  226. """
  227. Check obtain workspace who does not exist with an existing user.
  228. """
  229. self.testapp.authorization = (
  230. 'Basic',
  231. (
  232. 'admin@admin.admin',
  233. 'admin@admin.admin'
  234. )
  235. )
  236. res = self.testapp.get('/api/v2/workspaces/5', status=400)
  237. assert isinstance(res.json, dict)
  238. assert 'code' in res.json.keys()
  239. assert 'message' in res.json.keys()
  240. assert 'details' in res.json.keys()
  241. class TestWorkspaceMembersEndpoint(FunctionalTest):
  242. """
  243. Tests for /api/v2/workspaces/{workspace_id}/members endpoint
  244. """
  245. fixtures = [BaseFixture, ContentFixtures]
  246. def test_api__get_workspace_members__ok_200__nominal_case(self):
  247. """
  248. Check obtain workspace members list with a reachable workspace for user
  249. """
  250. self.testapp.authorization = (
  251. 'Basic',
  252. (
  253. 'admin@admin.admin',
  254. 'admin@admin.admin'
  255. )
  256. )
  257. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  258. assert len(res) == 1
  259. user_role = res[0]
  260. assert user_role['role'] == 'workspace-manager'
  261. assert user_role['user_id'] == 1
  262. assert user_role['workspace_id'] == 1
  263. assert user_role['workspace']['workspace_id'] == 1
  264. assert user_role['workspace']['label'] == 'Business'
  265. assert user_role['workspace']['slug'] == 'business'
  266. assert user_role['user']['public_name'] == 'Global manager'
  267. assert user_role['user']['user_id'] == 1
  268. assert user_role['is_active'] is True
  269. # TODO - G.M - 24-05-2018 - [Avatar] Replace
  270. # by correct value when avatar feature will be enabled
  271. assert user_role['user']['avatar_url'] is None
  272. def test_api__get_workspace_members__err_400__unallowed_user(self):
  273. """
  274. Check obtain workspace members list with an unreachable workspace for
  275. user
  276. """
  277. self.testapp.authorization = (
  278. 'Basic',
  279. (
  280. 'lawrence-not-real-email@fsf.local',
  281. 'foobarbaz'
  282. )
  283. )
  284. res = self.testapp.get('/api/v2/workspaces/3/members', status=400)
  285. assert isinstance(res.json, dict)
  286. assert 'code' in res.json.keys()
  287. assert 'message' in res.json.keys()
  288. assert 'details' in res.json.keys()
  289. def test_api__get_workspace_members__err_401__unregistered_user(self):
  290. """
  291. Check obtain workspace members list with an unregistered user
  292. """
  293. self.testapp.authorization = (
  294. 'Basic',
  295. (
  296. 'john@doe.doe',
  297. 'lapin'
  298. )
  299. )
  300. res = self.testapp.get('/api/v2/workspaces/1/members', status=401)
  301. assert isinstance(res.json, dict)
  302. assert 'code' in res.json.keys()
  303. assert 'message' in res.json.keys()
  304. assert 'details' in res.json.keys()
  305. def test_api__get_workspace_members__err_400__workspace_does_not_exist(self): # nopep8
  306. """
  307. Check obtain workspace members list with an existing user but
  308. an unexisting workspace
  309. """
  310. self.testapp.authorization = (
  311. 'Basic',
  312. (
  313. 'admin@admin.admin',
  314. 'admin@admin.admin'
  315. )
  316. )
  317. res = self.testapp.get('/api/v2/workspaces/5/members', status=400)
  318. assert isinstance(res.json, dict)
  319. assert 'code' in res.json.keys()
  320. assert 'message' in res.json.keys()
  321. assert 'details' in res.json.keys()
  322. def test_api__create_workspace_member_role__ok_200__user_id(self):
  323. """
  324. Create workspace member role
  325. :return:
  326. """
  327. self.testapp.authorization = (
  328. 'Basic',
  329. (
  330. 'admin@admin.admin',
  331. 'admin@admin.admin'
  332. )
  333. )
  334. # create workspace role
  335. params = {
  336. 'user_id': 2,
  337. 'user_email_or_public_name': None,
  338. 'role': 'content-manager',
  339. }
  340. res = self.testapp.post_json(
  341. '/api/v2/workspaces/1/members',
  342. status=200,
  343. params=params,
  344. )
  345. user_role_found = res.json_body
  346. assert user_role_found['role'] == 'content-manager'
  347. assert user_role_found['user_id'] == 2
  348. assert user_role_found['workspace_id'] == 1
  349. assert user_role_found['newly_created'] is False
  350. assert user_role_found['email_sent'] is False
  351. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  352. assert len(res) == 2
  353. user_role = res[0]
  354. assert user_role['role'] == 'workspace-manager'
  355. assert user_role['user_id'] == 1
  356. assert user_role['workspace_id'] == 1
  357. user_role = res[1]
  358. assert user_role_found['role'] == user_role['role']
  359. assert user_role_found['user_id'] == user_role['user_id']
  360. assert user_role_found['workspace_id'] == user_role['workspace_id']
  361. def test_api__create_workspace_member_role__ok_200__user_email(self):
  362. """
  363. Create workspace member role
  364. :return:
  365. """
  366. self.testapp.authorization = (
  367. 'Basic',
  368. (
  369. 'admin@admin.admin',
  370. 'admin@admin.admin'
  371. )
  372. )
  373. # create workspace role
  374. params = {
  375. 'user_id': None,
  376. 'user_email_or_public_name': 'lawrence-not-real-email@fsf.local',
  377. 'role': 'content-manager',
  378. }
  379. res = self.testapp.post_json(
  380. '/api/v2/workspaces/1/members',
  381. status=200,
  382. params=params,
  383. )
  384. user_role_found = res.json_body
  385. assert user_role_found['role'] == 'content-manager'
  386. assert user_role_found['user_id'] == 2
  387. assert user_role_found['workspace_id'] == 1
  388. assert user_role_found['newly_created'] is False
  389. assert user_role_found['email_sent'] is False
  390. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  391. assert len(res) == 2
  392. user_role = res[0]
  393. assert user_role['role'] == 'workspace-manager'
  394. assert user_role['user_id'] == 1
  395. assert user_role['workspace_id'] == 1
  396. user_role = res[1]
  397. assert user_role_found['role'] == user_role['role']
  398. assert user_role_found['user_id'] == user_role['user_id']
  399. assert user_role_found['workspace_id'] == user_role['workspace_id']
  400. def test_api__create_workspace_member_role__ok_200__user_public_name(self):
  401. """
  402. Create workspace member role
  403. :return:
  404. """
  405. self.testapp.authorization = (
  406. 'Basic',
  407. (
  408. 'admin@admin.admin',
  409. 'admin@admin.admin'
  410. )
  411. )
  412. # create workspace role
  413. params = {
  414. 'user_id': None,
  415. 'user_email_or_public_name': 'Lawrence L.',
  416. 'role': 'content-manager',
  417. }
  418. res = self.testapp.post_json(
  419. '/api/v2/workspaces/1/members',
  420. status=200,
  421. params=params,
  422. )
  423. user_role_found = res.json_body
  424. assert user_role_found['role'] == 'content-manager'
  425. assert user_role_found['user_id'] == 2
  426. assert user_role_found['workspace_id'] == 1
  427. assert user_role_found['newly_created'] is False
  428. assert user_role_found['email_sent'] is False
  429. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  430. assert len(res) == 2
  431. user_role = res[0]
  432. assert user_role['role'] == 'workspace-manager'
  433. assert user_role['user_id'] == 1
  434. assert user_role['workspace_id'] == 1
  435. user_role = res[1]
  436. assert user_role_found['role'] == user_role['role']
  437. assert user_role_found['user_id'] == user_role['user_id']
  438. assert user_role_found['workspace_id'] == user_role['workspace_id']
  439. def test_api__create_workspace_member_role__err_400__nothing(self):
  440. """
  441. Create workspace member role
  442. :return:
  443. """
  444. self.testapp.authorization = (
  445. 'Basic',
  446. (
  447. 'admin@admin.admin',
  448. 'admin@admin.admin'
  449. )
  450. )
  451. # create workspace role
  452. params = {
  453. 'user_id': None,
  454. 'user_email_or_public_name': None,
  455. 'role': 'content-manager',
  456. }
  457. res = self.testapp.post_json(
  458. '/api/v2/workspaces/1/members',
  459. status=400,
  460. params=params,
  461. )
  462. def test_api__create_workspace_member_role__err_400__wrong_user_id(self):
  463. """
  464. Create workspace member role
  465. :return:
  466. """
  467. self.testapp.authorization = (
  468. 'Basic',
  469. (
  470. 'admin@admin.admin',
  471. 'admin@admin.admin'
  472. )
  473. )
  474. # create workspace role
  475. params = {
  476. 'user_id': 47,
  477. 'user_email_or_public_name': None,
  478. 'role': 'content-manager',
  479. }
  480. res = self.testapp.post_json(
  481. '/api/v2/workspaces/1/members',
  482. status=400,
  483. params=params,
  484. )
  485. def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8
  486. """
  487. Create workspace member role
  488. :return:
  489. """
  490. self.testapp.authorization = (
  491. 'Basic',
  492. (
  493. 'admin@admin.admin',
  494. 'admin@admin.admin'
  495. )
  496. )
  497. # create workspace role
  498. params = {
  499. 'user_id': None,
  500. 'user_email_or_public_name': 'nothing@nothing.nothing',
  501. 'role': 'content-manager',
  502. }
  503. res = self.testapp.post_json(
  504. '/api/v2/workspaces/1/members',
  505. status=200,
  506. params=params,
  507. )
  508. user_role_found = res.json_body
  509. assert user_role_found['role'] == 'content-manager'
  510. assert user_role_found['user_id']
  511. user_id = user_role_found['user_id']
  512. assert user_role_found['workspace_id'] == 1
  513. assert user_role_found['newly_created'] is True
  514. assert user_role_found['email_sent'] is False
  515. res = self.testapp.get('/api/v2/workspaces/1/members',
  516. status=200).json_body # nopep8
  517. assert len(res) == 2
  518. user_role = res[0]
  519. assert user_role['role'] == 'workspace-manager'
  520. assert user_role['user_id'] == 1
  521. assert user_role['workspace_id'] == 1
  522. user_role = res[1]
  523. assert user_role_found['role'] == user_role['role']
  524. assert user_role_found['user_id'] == user_role['user_id']
  525. assert user_role_found['workspace_id'] == user_role['workspace_id']
  526. def test_api__update_workspace_member_role__ok_200__nominal_case(self):
  527. """
  528. Update worskpace member role
  529. """
  530. # before
  531. self.testapp.authorization = (
  532. 'Basic',
  533. (
  534. 'admin@admin.admin',
  535. 'admin@admin.admin'
  536. )
  537. )
  538. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  539. assert len(res) == 1
  540. user_role = res[0]
  541. assert user_role['role'] == 'workspace-manager'
  542. assert user_role['user_id'] == 1
  543. assert user_role['workspace_id'] == 1
  544. # update workspace role
  545. params = {
  546. 'role': 'content-manager',
  547. }
  548. res = self.testapp.put_json(
  549. '/api/v2/workspaces/1/members/1',
  550. status=200,
  551. params=params,
  552. )
  553. user_role = res.json_body
  554. assert user_role['role'] == 'content-manager'
  555. assert user_role['user_id'] == 1
  556. assert user_role['workspace_id'] == 1
  557. # after
  558. res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
  559. assert len(res) == 1
  560. user_role = res[0]
  561. assert user_role['role'] == 'content-manager'
  562. assert user_role['user_id'] == 1
  563. assert user_role['workspace_id'] == 1
  564. class TestUserInvitationWithMailActivatedSync(FunctionalTest):
  565. fixtures = [BaseFixture, ContentFixtures]
  566. config_section = 'functional_test_with_mail_test_sync'
  567. def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8
  568. """
  569. Create workspace member role
  570. :return:
  571. """
  572. requests.delete('http://127.0.0.1:8025/api/v1/messages')
  573. self.testapp.authorization = (
  574. 'Basic',
  575. (
  576. 'admin@admin.admin',
  577. 'admin@admin.admin'
  578. )
  579. )
  580. # create workspace role
  581. params = {
  582. 'user_id': None,
  583. 'user_email_or_public_name': 'bob@bob.bob',
  584. 'role': 'content-manager',
  585. }
  586. res = self.testapp.post_json(
  587. '/api/v2/workspaces/1/members',
  588. status=200,
  589. params=params,
  590. )
  591. user_role_found = res.json_body
  592. assert user_role_found['role'] == 'content-manager'
  593. assert user_role_found['user_id']
  594. user_id = user_role_found['user_id']
  595. assert user_role_found['workspace_id'] == 1
  596. assert user_role_found['newly_created'] is True
  597. assert user_role_found['email_sent'] is True
  598. # check mail received
  599. response = requests.get('http://127.0.0.1:8025/api/v1/messages')
  600. response = response.json()
  601. assert len(response) == 1
  602. headers = response[0]['Content']['Headers']
  603. assert headers['From'][0] == 'Tracim Notifications <test_user_from+0@localhost>' # nopep8
  604. assert headers['To'][0] == 'bob <bob@bob.bob>'
  605. assert headers['Subject'][0] == '[TRACIM] Created account'
  606. # TODO - G.M - 2018-08-02 - Place cleanup outside of the test
  607. requests.delete('http://127.0.0.1:8025/api/v1/messages')
  608. class TestUserInvitationWithMailActivatedASync(FunctionalTest):
  609. fixtures = [BaseFixture, ContentFixtures]
  610. config_section = 'functional_test_with_mail_test_async'
  611. def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8
  612. """
  613. Create workspace member role
  614. :return:
  615. """
  616. self.testapp.authorization = (
  617. 'Basic',
  618. (
  619. 'admin@admin.admin',
  620. 'admin@admin.admin'
  621. )
  622. )
  623. # create workspace role
  624. params = {
  625. 'user_id': None,
  626. 'user_email_or_public_name': 'bob@bob.bob',
  627. 'role': 'content-manager',
  628. }
  629. res = self.testapp.post_json(
  630. '/api/v2/workspaces/1/members',
  631. status=200,
  632. params=params,
  633. )
  634. user_role_found = res.json_body
  635. assert user_role_found['newly_created'] is True
  636. assert user_role_found['email_sent'] is False
  637. class TestWorkspaceContents(FunctionalTest):
  638. """
  639. Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
  640. """
  641. fixtures = [BaseFixture, ContentFixtures]
  642. def test_api__get_workspace_content__ok_200__get_default(self):
  643. """
  644. Check obtain workspace contents with defaults filters
  645. """
  646. self.testapp.authorization = (
  647. 'Basic',
  648. (
  649. 'admin@admin.admin',
  650. 'admin@admin.admin'
  651. )
  652. )
  653. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body # nopep8
  654. # TODO - G.M - 30-05-2018 - Check this test
  655. assert len(res) == 3
  656. content = res[0]
  657. assert content['content_id'] == 1
  658. assert content['content_type'] == 'folder'
  659. assert content['is_archived'] is False
  660. assert content['is_deleted'] is False
  661. assert content['label'] == 'Tools'
  662. assert content['parent_id'] is None
  663. assert content['show_in_ui'] is True
  664. assert content['slug'] == 'tools'
  665. assert content['status'] == 'open'
  666. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  667. assert content['workspace_id'] == 1
  668. content = res[1]
  669. assert content['content_id'] == 2
  670. assert content['content_type'] == 'folder'
  671. assert content['is_archived'] is False
  672. assert content['is_deleted'] is False
  673. assert content['label'] == 'Menus'
  674. assert content['parent_id'] is None
  675. assert content['show_in_ui'] is True
  676. assert content['slug'] == 'menus'
  677. assert content['status'] == 'open'
  678. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  679. assert content['workspace_id'] == 1
  680. content = res[2]
  681. assert content['content_id'] == 11
  682. assert content['content_type'] == 'html-document'
  683. assert content['is_archived'] is False
  684. assert content['is_deleted'] is False
  685. assert content['label'] == 'Current Menu'
  686. assert content['parent_id'] == 2
  687. assert content['show_in_ui'] is True
  688. assert content['slug'] == 'current-menu'
  689. assert content['status'] == 'open'
  690. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  691. assert content['workspace_id'] == 1
  692. def test_api__get_workspace_content__ok_200__get_default_html_documents(self):
  693. """
  694. Check obtain workspace contents with defaults filters + content_filter
  695. """
  696. self.testapp.authorization = (
  697. 'Basic',
  698. (
  699. 'admin@admin.admin',
  700. 'admin@admin.admin'
  701. )
  702. )
  703. params = {
  704. 'content_type': 'html-document',
  705. }
  706. res = self.testapp.get('/api/v2/workspaces/1/contents', status=200, params=params).json_body # nopep8
  707. assert len(res) == 1
  708. content = res[0]
  709. assert content
  710. assert content['content_id'] == 11
  711. assert content['content_type'] == 'html-document'
  712. assert content['is_archived'] is False
  713. assert content['is_deleted'] is False
  714. assert content['label'] == 'Current Menu'
  715. assert content['parent_id'] == 2
  716. assert content['show_in_ui'] is True
  717. assert content['slug'] == 'current-menu'
  718. assert content['status'] == 'open'
  719. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  720. assert content['workspace_id'] == 1
  721. # Root related
  722. def test_api__get_workspace_content__ok_200__get_all_root_content__legacy_html_slug(self): # nopep8
  723. """
  724. Check obtain workspace all root contents
  725. """
  726. set_html_document_slug_to_legacy(self.session_factory)
  727. params = {
  728. 'parent_id': 0,
  729. 'show_archived': 1,
  730. 'show_deleted': 1,
  731. 'show_active': 1,
  732. }
  733. self.testapp.authorization = (
  734. 'Basic',
  735. (
  736. 'bob@fsf.local',
  737. 'foobarbaz'
  738. )
  739. )
  740. res = self.testapp.get(
  741. '/api/v2/workspaces/3/contents',
  742. status=200,
  743. params=params,
  744. ).json_body # nopep8
  745. # TODO - G.M - 30-05-2018 - Check this test
  746. assert len(res) == 4
  747. content = res[1]
  748. assert content['content_type'] == 'html-document'
  749. assert content['content_id'] == 15
  750. assert content['is_archived'] is False
  751. assert content['is_deleted'] is False
  752. assert content['label'] == 'New Fruit Salad'
  753. assert content['parent_id'] is None
  754. assert content['show_in_ui'] is True
  755. assert content['slug'] == 'new-fruit-salad'
  756. assert content['status'] == 'open'
  757. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  758. assert content['workspace_id'] == 3
  759. content = res[2]
  760. assert content['content_type'] == 'html-document'
  761. assert content['content_id'] == 16
  762. assert content['is_archived'] is True
  763. assert content['is_deleted'] is False
  764. assert content['label'].startswith('Fruit Salad')
  765. assert content['parent_id'] is None
  766. assert content['show_in_ui'] is True
  767. assert content['slug'].startswith('fruit-salad')
  768. assert content['status'] == 'open'
  769. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  770. assert content['workspace_id'] == 3
  771. content = res[3]
  772. assert content['content_type'] == 'html-document'
  773. assert content['content_id'] == 17
  774. assert content['is_archived'] is False
  775. assert content['is_deleted'] is True
  776. assert content['label'].startswith('Bad Fruit Salad')
  777. assert content['parent_id'] is None
  778. assert content['show_in_ui'] is True
  779. assert content['slug'].startswith('bad-fruit-salad')
  780. assert content['status'] == 'open'
  781. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  782. assert content['workspace_id'] == 3
  783. def test_api__get_workspace_content__ok_200__get_all_root_content(self):
  784. """
  785. Check obtain workspace all root contents
  786. """
  787. params = {
  788. 'parent_id': 0,
  789. 'show_archived': 1,
  790. 'show_deleted': 1,
  791. 'show_active': 1,
  792. }
  793. self.testapp.authorization = (
  794. 'Basic',
  795. (
  796. 'bob@fsf.local',
  797. 'foobarbaz'
  798. )
  799. )
  800. res = self.testapp.get(
  801. '/api/v2/workspaces/3/contents',
  802. status=200,
  803. params=params,
  804. ).json_body # nopep8
  805. # TODO - G.M - 30-05-2018 - Check this test
  806. assert len(res) == 4
  807. content = res[1]
  808. assert content['content_type'] == 'html-document'
  809. assert content['content_id'] == 15
  810. assert content['is_archived'] is False
  811. assert content['is_deleted'] is False
  812. assert content['label'] == 'New Fruit Salad'
  813. assert content['parent_id'] is None
  814. assert content['show_in_ui'] is True
  815. assert content['slug'] == 'new-fruit-salad'
  816. assert content['status'] == 'open'
  817. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  818. assert content['workspace_id'] == 3
  819. content = res[2]
  820. assert content['content_type'] == 'html-document'
  821. assert content['content_id'] == 16
  822. assert content['is_archived'] is True
  823. assert content['is_deleted'] is False
  824. assert content['label'].startswith('Fruit Salad')
  825. assert content['parent_id'] is None
  826. assert content['show_in_ui'] is True
  827. assert content['slug'].startswith('fruit-salad')
  828. assert content['status'] == 'open'
  829. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  830. assert content['workspace_id'] == 3
  831. content = res[3]
  832. assert content['content_type'] == 'html-document'
  833. assert content['content_id'] == 17
  834. assert content['is_archived'] is False
  835. assert content['is_deleted'] is True
  836. assert content['label'].startswith('Bad Fruit Salad')
  837. assert content['parent_id'] is None
  838. assert content['show_in_ui'] is True
  839. assert content['slug'].startswith('bad-fruit-salad')
  840. assert content['status'] == 'open'
  841. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  842. assert content['workspace_id'] == 3
  843. def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8
  844. """
  845. Check obtain workspace root active contents
  846. """
  847. params = {
  848. 'parent_id': 0,
  849. 'show_archived': 0,
  850. 'show_deleted': 0,
  851. 'show_active': 1,
  852. }
  853. self.testapp.authorization = (
  854. 'Basic',
  855. (
  856. 'bob@fsf.local',
  857. 'foobarbaz'
  858. )
  859. )
  860. res = self.testapp.get(
  861. '/api/v2/workspaces/3/contents',
  862. status=200,
  863. params=params,
  864. ).json_body # nopep8
  865. # TODO - G.M - 30-05-2018 - Check this test
  866. assert len(res) == 2
  867. content = res[1]
  868. assert content['content_type'] == 'html-document'
  869. assert content['content_id'] == 15
  870. assert content['is_archived'] is False
  871. assert content['is_deleted'] is False
  872. assert content['label'] == 'New Fruit Salad'
  873. assert content['parent_id'] is None
  874. assert content['show_in_ui'] is True
  875. assert content['slug'] == 'new-fruit-salad'
  876. assert content['status'] == 'open'
  877. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  878. assert content['workspace_id'] == 3
  879. def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8
  880. """
  881. Check obtain workspace root archived contents
  882. """
  883. params = {
  884. 'parent_id': 0,
  885. 'show_archived': 1,
  886. 'show_deleted': 0,
  887. 'show_active': 0,
  888. }
  889. self.testapp.authorization = (
  890. 'Basic',
  891. (
  892. 'bob@fsf.local',
  893. 'foobarbaz'
  894. )
  895. )
  896. res = self.testapp.get(
  897. '/api/v2/workspaces/3/contents',
  898. status=200,
  899. params=params,
  900. ).json_body # nopep8
  901. assert len(res) == 1
  902. content = res[0]
  903. assert content['content_type'] == 'html-document'
  904. assert content['content_id'] == 16
  905. assert content['is_archived'] is True
  906. assert content['is_deleted'] is False
  907. assert content['label'].startswith('Fruit Salad')
  908. assert content['parent_id'] is None
  909. assert content['show_in_ui'] is True
  910. assert content['slug'].startswith('fruit-salad')
  911. assert content['status'] == 'open'
  912. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  913. assert content['workspace_id'] == 3
  914. def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8
  915. """
  916. Check obtain workspace root deleted contents
  917. """
  918. params = {
  919. 'parent_id': 0,
  920. 'show_archived': 0,
  921. 'show_deleted': 1,
  922. 'show_active': 0,
  923. }
  924. self.testapp.authorization = (
  925. 'Basic',
  926. (
  927. 'bob@fsf.local',
  928. 'foobarbaz'
  929. )
  930. )
  931. res = self.testapp.get(
  932. '/api/v2/workspaces/3/contents',
  933. status=200,
  934. params=params,
  935. ).json_body # nopep8
  936. # TODO - G.M - 30-05-2018 - Check this test
  937. assert len(res) == 1
  938. content = res[0]
  939. assert content['content_type'] == 'html-document'
  940. assert content['content_id'] == 17
  941. assert content['is_archived'] is False
  942. assert content['is_deleted'] is True
  943. assert content['label'].startswith('Bad Fruit Salad')
  944. assert content['parent_id'] is None
  945. assert content['show_in_ui'] is True
  946. assert content['slug'].startswith('bad-fruit-salad')
  947. assert content['status'] == 'open'
  948. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  949. assert content['workspace_id'] == 3
  950. def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
  951. """
  952. Check obtain workspace root content who does not match any type
  953. (archived, deleted, active) result should be empty list.
  954. """
  955. params = {
  956. 'parent_id': 0,
  957. 'show_archived': 0,
  958. 'show_deleted': 0,
  959. 'show_active': 0,
  960. }
  961. self.testapp.authorization = (
  962. 'Basic',
  963. (
  964. 'bob@fsf.local',
  965. 'foobarbaz'
  966. )
  967. )
  968. res = self.testapp.get(
  969. '/api/v2/workspaces/3/contents',
  970. status=200,
  971. params=params,
  972. ).json_body # nopep8
  973. # TODO - G.M - 30-05-2018 - Check this test
  974. assert res == []
  975. # Folder related
  976. def test_api__get_workspace_content__ok_200__get_all_filter_content_thread(self):
  977. # prepare data
  978. dbsession = get_tm_session(self.session_factory, transaction.manager)
  979. admin = dbsession.query(models.User) \
  980. .filter(models.User.email == 'admin@admin.admin') \
  981. .one()
  982. workspace_api = WorkspaceApi(
  983. current_user=admin,
  984. session=dbsession,
  985. config=self.app_config
  986. )
  987. business_workspace = workspace_api.get_one(1)
  988. content_api = ContentApi(
  989. current_user=admin,
  990. session=dbsession,
  991. config=self.app_config
  992. )
  993. tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
  994. test_thread = content_api.create(
  995. content_type_slug=CONTENT_TYPES.Thread.slug,
  996. workspace=business_workspace,
  997. parent=tool_folder,
  998. label='Test Thread',
  999. do_save=False,
  1000. do_notify=False,
  1001. )
  1002. test_thread.description = 'Thread description'
  1003. dbsession.add(test_thread)
  1004. test_file = content_api.create(
  1005. content_type_slug=CONTENT_TYPES.File.slug,
  1006. workspace=business_workspace,
  1007. parent=tool_folder,
  1008. label='Test file',
  1009. do_save=False,
  1010. do_notify=False,
  1011. )
  1012. test_file.file_extension = '.txt'
  1013. test_file.depot_file = FileIntent(
  1014. b'Test file',
  1015. 'Test_file.txt',
  1016. 'text/plain',
  1017. )
  1018. test_page_legacy = content_api.create(
  1019. content_type_slug=CONTENT_TYPES.Page.slug,
  1020. workspace=business_workspace,
  1021. label='test_page',
  1022. do_save=False,
  1023. do_notify=False,
  1024. )
  1025. test_page_legacy.type = 'page'
  1026. content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
  1027. test_html_document = content_api.create(
  1028. content_type_slug=CONTENT_TYPES.Page.slug,
  1029. workspace=business_workspace,
  1030. label='test_html_page',
  1031. do_save=False,
  1032. do_notify=False,
  1033. )
  1034. content_api.update_content(test_html_document, 'test_page', '<p>HTML_DOCUMENT</p>') # nopep8
  1035. dbsession.flush()
  1036. transaction.commit()
  1037. # test-itself
  1038. params = {
  1039. 'parent_id': 1,
  1040. 'show_archived': 1,
  1041. 'show_deleted': 1,
  1042. 'show_active': 1,
  1043. 'content_type': 'thread',
  1044. }
  1045. self.testapp.authorization = (
  1046. 'Basic',
  1047. (
  1048. 'admin@admin.admin',
  1049. 'admin@admin.admin'
  1050. )
  1051. )
  1052. res = self.testapp.get(
  1053. '/api/v2/workspaces/1/contents',
  1054. status=200,
  1055. params=params,
  1056. ).json_body
  1057. assert len(res) == 1
  1058. content = res[0]
  1059. assert content['content_type'] == 'thread'
  1060. assert content['content_id']
  1061. assert content['is_archived'] is False
  1062. assert content['is_deleted'] is False
  1063. assert content['label'] == 'Test Thread'
  1064. assert content['parent_id'] == 1
  1065. assert content['show_in_ui'] is True
  1066. assert content['slug'] == 'test-thread'
  1067. assert content['status'] == 'open'
  1068. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1069. assert content['workspace_id'] == 1
  1070. def test_api__get_workspace_content__ok_200__get_all_filter_content_html_and_legacy_page(self): # nopep8
  1071. # prepare data
  1072. dbsession = get_tm_session(self.session_factory, transaction.manager)
  1073. admin = dbsession.query(models.User) \
  1074. .filter(models.User.email == 'admin@admin.admin') \
  1075. .one()
  1076. workspace_api = WorkspaceApi(
  1077. current_user=admin,
  1078. session=dbsession,
  1079. config=self.app_config
  1080. )
  1081. business_workspace = workspace_api.get_one(1)
  1082. content_api = ContentApi(
  1083. current_user=admin,
  1084. session=dbsession,
  1085. config=self.app_config
  1086. )
  1087. tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
  1088. test_thread = content_api.create(
  1089. content_type_slug=CONTENT_TYPES.Thread.slug,
  1090. workspace=business_workspace,
  1091. parent=tool_folder,
  1092. label='Test Thread',
  1093. do_save=False,
  1094. do_notify=False,
  1095. )
  1096. test_thread.description = 'Thread description'
  1097. dbsession.add(test_thread)
  1098. test_file = content_api.create(
  1099. content_type_slug=CONTENT_TYPES.File.slug,
  1100. workspace=business_workspace,
  1101. parent=tool_folder,
  1102. label='Test file',
  1103. do_save=False,
  1104. do_notify=False,
  1105. )
  1106. test_file.file_extension = '.txt'
  1107. test_file.depot_file = FileIntent(
  1108. b'Test file',
  1109. 'Test_file.txt',
  1110. 'text/plain',
  1111. )
  1112. test_page_legacy = content_api.create(
  1113. content_type_slug=CONTENT_TYPES.Page.slug,
  1114. workspace=business_workspace,
  1115. parent=tool_folder,
  1116. label='test_page',
  1117. do_save=False,
  1118. do_notify=False,
  1119. )
  1120. test_page_legacy.type = 'page'
  1121. content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
  1122. test_html_document = content_api.create(
  1123. content_type_slug=CONTENT_TYPES.Page.slug,
  1124. workspace=business_workspace,
  1125. parent=tool_folder,
  1126. label='test_html_page',
  1127. do_save=False,
  1128. do_notify=False,
  1129. )
  1130. content_api.update_content(test_html_document, 'test_html_page', '<p>HTML_DOCUMENT</p>') # nopep8
  1131. dbsession.flush()
  1132. transaction.commit()
  1133. # test-itself
  1134. params = {
  1135. 'parent_id': 1,
  1136. 'show_archived': 1,
  1137. 'show_deleted': 1,
  1138. 'show_active': 1,
  1139. 'content_type': 'html-document',
  1140. }
  1141. self.testapp.authorization = (
  1142. 'Basic',
  1143. (
  1144. 'admin@admin.admin',
  1145. 'admin@admin.admin'
  1146. )
  1147. )
  1148. res = self.testapp.get(
  1149. '/api/v2/workspaces/1/contents',
  1150. status=200,
  1151. params=params,
  1152. ).json_body
  1153. assert len(res) == 2
  1154. content = res[0]
  1155. assert content['content_type'] == 'html-document'
  1156. assert content['content_id']
  1157. assert content['is_archived'] is False
  1158. assert content['is_deleted'] is False
  1159. assert content['label'] == 'test_page'
  1160. assert content['parent_id'] == 1
  1161. assert content['show_in_ui'] is True
  1162. assert content['slug'] == 'test-page'
  1163. assert content['status'] == 'open'
  1164. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1165. assert content['workspace_id'] == 1
  1166. content = res[1]
  1167. assert content['content_type'] == 'html-document'
  1168. assert content['content_id']
  1169. assert content['is_archived'] is False
  1170. assert content['is_deleted'] is False
  1171. assert content['label'] == 'test_html_page'
  1172. assert content['parent_id'] == 1
  1173. assert content['show_in_ui'] is True
  1174. assert content['slug'] == 'test-html-page'
  1175. assert content['status'] == 'open'
  1176. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1177. assert content['workspace_id'] == 1
  1178. assert res[0]['content_id'] != res[1]['content_id']
  1179. def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
  1180. """
  1181. Check obtain workspace folder all contents
  1182. """
  1183. params = {
  1184. 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id
  1185. 'show_archived': 1,
  1186. 'show_deleted': 1,
  1187. 'show_active': 1,
  1188. # 'content_type': 'any'
  1189. }
  1190. self.testapp.authorization = (
  1191. 'Basic',
  1192. (
  1193. 'admin@admin.admin',
  1194. 'admin@admin.admin'
  1195. )
  1196. )
  1197. res = self.testapp.get(
  1198. '/api/v2/workspaces/2/contents',
  1199. status=200,
  1200. params=params,
  1201. ).json_body # nopep8
  1202. assert len(res) == 3
  1203. content = res[0]
  1204. assert content['content_type'] == 'html-document'
  1205. assert content['content_id'] == 12
  1206. assert content['is_archived'] is False
  1207. assert content['is_deleted'] is False
  1208. assert content['label'] == 'New Fruit Salad'
  1209. assert content['parent_id'] == 10
  1210. assert content['show_in_ui'] is True
  1211. assert content['slug'] == 'new-fruit-salad'
  1212. assert content['status'] == 'open'
  1213. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1214. assert content['workspace_id'] == 2
  1215. content = res[1]
  1216. assert content['content_type'] == 'html-document'
  1217. assert content['content_id'] == 13
  1218. assert content['is_archived'] is True
  1219. assert content['is_deleted'] is False
  1220. assert content['label'].startswith('Fruit Salad')
  1221. assert content['parent_id'] == 10
  1222. assert content['show_in_ui'] is True
  1223. assert content['slug'].startswith('fruit-salad')
  1224. assert content['status'] == 'open'
  1225. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1226. assert content['workspace_id'] == 2
  1227. content = res[2]
  1228. assert content['content_type'] == 'html-document'
  1229. assert content['content_id'] == 14
  1230. assert content['is_archived'] is False
  1231. assert content['is_deleted'] is True
  1232. assert content['label'].startswith('Bad Fruit Salad')
  1233. assert content['parent_id'] == 10
  1234. assert content['show_in_ui'] is True
  1235. assert content['slug'].startswith('bad-fruit-salad')
  1236. assert content['status'] == 'open'
  1237. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1238. assert content['workspace_id'] == 2
  1239. def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8
  1240. """
  1241. Check obtain workspace folder active contents
  1242. """
  1243. params = {
  1244. 'parent_id': 10,
  1245. 'show_archived': 0,
  1246. 'show_deleted': 0,
  1247. 'show_active': 1,
  1248. }
  1249. self.testapp.authorization = (
  1250. 'Basic',
  1251. (
  1252. 'admin@admin.admin',
  1253. 'admin@admin.admin'
  1254. )
  1255. )
  1256. res = self.testapp.get(
  1257. '/api/v2/workspaces/2/contents',
  1258. status=200,
  1259. params=params,
  1260. ).json_body # nopep8
  1261. assert len(res) == 1
  1262. content = res[0]
  1263. assert content['content_type']
  1264. assert content['content_id'] == 12
  1265. assert content['is_archived'] is False
  1266. assert content['is_deleted'] is False
  1267. assert content['label'] == 'New Fruit Salad'
  1268. assert content['parent_id'] == 10
  1269. assert content['show_in_ui'] is True
  1270. assert content['slug'] == 'new-fruit-salad'
  1271. assert content['status'] == 'open'
  1272. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1273. assert content['workspace_id'] == 2
  1274. def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8
  1275. """
  1276. Check obtain workspace folder archived contents
  1277. """
  1278. params = {
  1279. 'parent_id': 10,
  1280. 'show_archived': 1,
  1281. 'show_deleted': 0,
  1282. 'show_active': 0,
  1283. }
  1284. self.testapp.authorization = (
  1285. 'Basic',
  1286. (
  1287. 'admin@admin.admin',
  1288. 'admin@admin.admin'
  1289. )
  1290. )
  1291. res = self.testapp.get(
  1292. '/api/v2/workspaces/2/contents',
  1293. status=200,
  1294. params=params,
  1295. ).json_body # nopep8
  1296. assert len(res) == 1
  1297. content = res[0]
  1298. assert content['content_type'] == 'html-document'
  1299. assert content['content_id'] == 13
  1300. assert content['is_archived'] is True
  1301. assert content['is_deleted'] is False
  1302. assert content['label'].startswith('Fruit Salad')
  1303. assert content['parent_id'] == 10
  1304. assert content['show_in_ui'] is True
  1305. assert content['slug'].startswith('fruit-salad')
  1306. assert content['status'] == 'open'
  1307. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1308. assert content['workspace_id'] == 2
  1309. def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8
  1310. """
  1311. Check obtain workspace folder deleted contents
  1312. """
  1313. params = {
  1314. 'parent_id': 10,
  1315. 'show_archived': 0,
  1316. 'show_deleted': 1,
  1317. 'show_active': 0,
  1318. }
  1319. self.testapp.authorization = (
  1320. 'Basic',
  1321. (
  1322. 'admin@admin.admin',
  1323. 'admin@admin.admin'
  1324. )
  1325. )
  1326. res = self.testapp.get(
  1327. '/api/v2/workspaces/2/contents',
  1328. status=200,
  1329. params=params,
  1330. ).json_body # nopep8
  1331. assert len(res) == 1
  1332. content = res[0]
  1333. assert content['content_type'] == 'html-document'
  1334. assert content['content_id'] == 14
  1335. assert content['is_archived'] is False
  1336. assert content['is_deleted'] is True
  1337. assert content['label'].startswith('Bad Fruit Salad')
  1338. assert content['parent_id'] == 10
  1339. assert content['show_in_ui'] is True
  1340. assert content['slug'].startswith('bad-fruit-salad')
  1341. assert content['status'] == 'open'
  1342. assert set(content['sub_content_types']) == {'thread', 'html-document', 'folder', 'file'} # nopep8
  1343. assert content['workspace_id'] == 2
  1344. def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8
  1345. """
  1346. Check obtain workspace folder content who does not match any type
  1347. (archived, deleted, active) result should be empty list.
  1348. """
  1349. params = {
  1350. 'parent_id': 10,
  1351. 'show_archived': 0,
  1352. 'show_deleted': 0,
  1353. 'show_active': 0,
  1354. }
  1355. self.testapp.authorization = (
  1356. 'Basic',
  1357. (
  1358. 'admin@admin.admin',
  1359. 'admin@admin.admin'
  1360. )
  1361. )
  1362. res = self.testapp.get(
  1363. '/api/v2/workspaces/2/contents',
  1364. status=200,
  1365. params=params,
  1366. ).json_body # nopep8
  1367. # TODO - G.M - 30-05-2018 - Check this test
  1368. assert res == []
  1369. # Error case
  1370. def test_api__get_workspace_content__err_400__unallowed_user(self):
  1371. """
  1372. Check obtain workspace content list with an unreachable workspace for
  1373. user
  1374. """
  1375. self.testapp.authorization = (
  1376. 'Basic',
  1377. (
  1378. 'lawrence-not-real-email@fsf.local',
  1379. 'foobarbaz'
  1380. )
  1381. )
  1382. res = self.testapp.get('/api/v2/workspaces/3/contents', status=400)
  1383. assert isinstance(res.json, dict)
  1384. assert 'code' in res.json.keys()
  1385. assert 'message' in res.json.keys()
  1386. assert 'details' in res.json.keys()
  1387. def test_api__get_workspace_content__err_401__unregistered_user(self):
  1388. """
  1389. Check obtain workspace content list with an unregistered user
  1390. """
  1391. self.testapp.authorization = (
  1392. 'Basic',
  1393. (
  1394. 'john@doe.doe',
  1395. 'lapin'
  1396. )
  1397. )
  1398. res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
  1399. assert isinstance(res.json, dict)
  1400. assert 'code' in res.json.keys()
  1401. assert 'message' in res.json.keys()
  1402. assert 'details' in res.json.keys()
  1403. def test_api__get_workspace_content__err_400__workspace_does_not_exist(self): # nopep8
  1404. """
  1405. Check obtain workspace contents list with an existing user but
  1406. an unexisting workspace
  1407. """
  1408. self.testapp.authorization = (
  1409. 'Basic',
  1410. (
  1411. 'admin@admin.admin',
  1412. 'admin@admin.admin'
  1413. )
  1414. )
  1415. res = self.testapp.get('/api/v2/workspaces/5/contents', status=400)
  1416. assert isinstance(res.json, dict)
  1417. assert 'code' in res.json.keys()
  1418. assert 'message' in res.json.keys()
  1419. assert 'details' in res.json.keys()
  1420. def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8
  1421. """
  1422. Create generic content
  1423. """
  1424. self.testapp.authorization = (
  1425. 'Basic',
  1426. (
  1427. 'admin@admin.admin',
  1428. 'admin@admin.admin'
  1429. )
  1430. )
  1431. params = {
  1432. 'parent_id': None,
  1433. 'label': 'GenericCreatedContent',
  1434. 'content_type': 'html-document',
  1435. }
  1436. res = self.testapp.post_json(
  1437. '/api/v2/workspaces/1/contents',
  1438. params=params,
  1439. status=200
  1440. )
  1441. assert res
  1442. assert res.json_body
  1443. assert res.json_body['status'] == 'open'
  1444. assert res.json_body['content_id']
  1445. assert res.json_body['content_type'] == 'html-document'
  1446. assert res.json_body['is_archived'] is False
  1447. assert res.json_body['is_deleted'] is False
  1448. assert res.json_body['workspace_id'] == 1
  1449. assert res.json_body['slug'] == 'genericcreatedcontent'
  1450. assert res.json_body['parent_id'] is None
  1451. assert res.json_body['show_in_ui'] is True
  1452. assert res.json_body['sub_content_types']
  1453. params_active = {
  1454. 'parent_id': 0,
  1455. 'show_archived': 0,
  1456. 'show_deleted': 0,
  1457. 'show_active': 1,
  1458. }
  1459. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1460. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1461. assert res.json_body in active_contents
  1462. def test_api__post_content_create_generic_content__ok_200__no_parent_id_param(self) -> None: # nopep8
  1463. """
  1464. Create generic content
  1465. """
  1466. self.testapp.authorization = (
  1467. 'Basic',
  1468. (
  1469. 'admin@admin.admin',
  1470. 'admin@admin.admin'
  1471. )
  1472. )
  1473. params = {
  1474. 'label': 'GenericCreatedContent',
  1475. 'content_type': 'html-document',
  1476. }
  1477. res = self.testapp.post_json(
  1478. '/api/v2/workspaces/1/contents',
  1479. params=params,
  1480. status=200
  1481. )
  1482. assert res
  1483. assert res.json_body
  1484. assert res.json_body['status'] == 'open'
  1485. assert res.json_body['content_id']
  1486. assert res.json_body['content_type'] == 'html-document'
  1487. assert res.json_body['is_archived'] is False
  1488. assert res.json_body['is_deleted'] is False
  1489. assert res.json_body['workspace_id'] == 1
  1490. assert res.json_body['slug'] == 'genericcreatedcontent'
  1491. assert res.json_body['parent_id'] is None
  1492. assert res.json_body['show_in_ui'] is True
  1493. assert res.json_body['sub_content_types']
  1494. params_active = {
  1495. 'parent_id': 0,
  1496. 'show_archived': 0,
  1497. 'show_deleted': 0,
  1498. 'show_active': 1,
  1499. }
  1500. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1501. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1502. assert res.json_body in active_contents
  1503. def test_api__post_content_create_generic_content__err_400__parent_id_0(self) -> None: # nopep8
  1504. """
  1505. Create generic content
  1506. """
  1507. self.testapp.authorization = (
  1508. 'Basic',
  1509. (
  1510. 'admin@admin.admin',
  1511. 'admin@admin.admin'
  1512. )
  1513. )
  1514. params = {
  1515. 'parent_id': 0,
  1516. 'label': 'GenericCreatedContent',
  1517. 'content_type': 'markdownpage',
  1518. }
  1519. res = self.testapp.post_json(
  1520. '/api/v2/workspaces/1/contents',
  1521. params=params,
  1522. status=400
  1523. )
  1524. def test_api__post_content_create_generic_content__ok_200__in_folder(self) -> None: # nopep8
  1525. """
  1526. Create generic content in folder
  1527. """
  1528. self.testapp.authorization = (
  1529. 'Basic',
  1530. (
  1531. 'admin@admin.admin',
  1532. 'admin@admin.admin'
  1533. )
  1534. )
  1535. params = {
  1536. 'label': 'GenericCreatedContent',
  1537. 'content_type': 'html-document',
  1538. 'parent_id': 10,
  1539. }
  1540. res = self.testapp.post_json(
  1541. '/api/v2/workspaces/1/contents',
  1542. params=params,
  1543. status=200
  1544. )
  1545. assert res
  1546. assert res.json_body
  1547. assert res.json_body['status'] == 'open'
  1548. assert res.json_body['content_id']
  1549. assert res.json_body['content_type'] == 'html-document'
  1550. assert res.json_body['is_archived'] is False
  1551. assert res.json_body['is_deleted'] is False
  1552. assert res.json_body['workspace_id'] == 1
  1553. assert res.json_body['slug'] == 'genericcreatedcontent'
  1554. assert res.json_body['parent_id'] == 10
  1555. assert res.json_body['show_in_ui'] is True
  1556. assert res.json_body['sub_content_types']
  1557. params_active = {
  1558. 'parent_id': 10,
  1559. 'show_archived': 0,
  1560. 'show_deleted': 0,
  1561. 'show_active': 1,
  1562. }
  1563. # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
  1564. active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
  1565. assert res.json_body in active_contents
  1566. def test_api__post_content_create_generic_content__err_400__empty_label(self) -> None: # nopep8
  1567. """
  1568. Create generic content
  1569. """
  1570. self.testapp.authorization = (
  1571. 'Basic',
  1572. (
  1573. 'admin@admin.admin',
  1574. 'admin@admin.admin'
  1575. )
  1576. )
  1577. params = {
  1578. 'label': '',
  1579. 'content_type': 'html-document',
  1580. }
  1581. res = self.testapp.post_json(
  1582. '/api/v2/workspaces/1/contents',
  1583. params=params,
  1584. status=400
  1585. )
  1586. def test_api__post_content_create_generic_content__err_400__wrong_content_type(self) -> None: # nopep8
  1587. """
  1588. Create generic content
  1589. """
  1590. self.testapp.authorization = (
  1591. 'Basic',
  1592. (
  1593. 'admin@admin.admin',
  1594. 'admin@admin.admin'
  1595. )
  1596. )
  1597. params = {
  1598. 'label': 'GenericCreatedContent',
  1599. 'content_type': 'unexistent-content-type',
  1600. }
  1601. res = self.testapp.post_json(
  1602. '/api/v2/workspaces/1/contents',
  1603. params=params,
  1604. status=400,
  1605. )
  1606. def test_api_put_move_content__ok_200__nominal_case(self):
  1607. """
  1608. Move content
  1609. move Apple_Pie (content_id: 8)
  1610. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1611. of workspace Recipes.
  1612. """
  1613. self.testapp.authorization = (
  1614. 'Basic',
  1615. (
  1616. 'admin@admin.admin',
  1617. 'admin@admin.admin'
  1618. )
  1619. )
  1620. params = {
  1621. 'new_parent_id': '4', # Salads
  1622. 'new_workspace_id': '2',
  1623. }
  1624. params_folder1 = {
  1625. 'parent_id': 3,
  1626. 'show_archived': 0,
  1627. 'show_deleted': 0,
  1628. 'show_active': 1,
  1629. }
  1630. params_folder2 = {
  1631. 'parent_id': 4,
  1632. 'show_archived': 0,
  1633. 'show_deleted': 0,
  1634. 'show_active': 1,
  1635. }
  1636. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1637. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1638. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1639. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1640. # TODO - G.M - 2018-06-163 - Check content
  1641. res = self.testapp.put_json(
  1642. '/api/v2/workspaces/2/contents/8/move',
  1643. params=params,
  1644. status=200
  1645. )
  1646. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1647. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1648. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1649. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1650. assert res.json_body
  1651. assert res.json_body['parent_id'] == 4
  1652. assert res.json_body['content_id'] == 8
  1653. assert res.json_body['workspace_id'] == 2
  1654. def test_api_put_move_content__ok_200__to_root(self):
  1655. """
  1656. Move content
  1657. move Apple_Pie (content_id: 8)
  1658. from Desserts folder(content_id: 3) to root (content_id: 0)
  1659. of workspace Recipes.
  1660. """
  1661. self.testapp.authorization = (
  1662. 'Basic',
  1663. (
  1664. 'admin@admin.admin',
  1665. 'admin@admin.admin'
  1666. )
  1667. )
  1668. params = {
  1669. 'new_parent_id': None, # root
  1670. 'new_workspace_id': 2,
  1671. }
  1672. params_folder1 = {
  1673. 'parent_id': 3,
  1674. 'show_archived': 0,
  1675. 'show_deleted': 0,
  1676. 'show_active': 1,
  1677. }
  1678. params_folder2 = {
  1679. 'parent_id': 0,
  1680. 'show_archived': 0,
  1681. 'show_deleted': 0,
  1682. 'show_active': 1,
  1683. }
  1684. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1685. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1686. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1687. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1688. # TODO - G.M - 2018-06-163 - Check content
  1689. res = self.testapp.put_json(
  1690. '/api/v2/workspaces/2/contents/8/move',
  1691. params=params,
  1692. status=200
  1693. )
  1694. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1695. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1696. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1697. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1698. assert res.json_body
  1699. assert res.json_body['parent_id'] is None
  1700. assert res.json_body['content_id'] == 8
  1701. assert res.json_body['workspace_id'] == 2
  1702. def test_api_put_move_content__ok_200__with_workspace_id(self):
  1703. """
  1704. Move content
  1705. move Apple_Pie (content_id: 8)
  1706. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1707. of workspace Recipes.
  1708. """
  1709. self.testapp.authorization = (
  1710. 'Basic',
  1711. (
  1712. 'admin@admin.admin',
  1713. 'admin@admin.admin'
  1714. )
  1715. )
  1716. params = {
  1717. 'new_parent_id': '4', # Salads
  1718. 'new_workspace_id': '2',
  1719. }
  1720. params_folder1 = {
  1721. 'parent_id': 3,
  1722. 'show_archived': 0,
  1723. 'show_deleted': 0,
  1724. 'show_active': 1,
  1725. }
  1726. params_folder2 = {
  1727. 'parent_id': 4,
  1728. 'show_archived': 0,
  1729. 'show_deleted': 0,
  1730. 'show_active': 1,
  1731. }
  1732. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1733. folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1734. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1735. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1736. # TODO - G.M - 2018-06-163 - Check content
  1737. res = self.testapp.put_json(
  1738. '/api/v2/workspaces/2/contents/8/move',
  1739. params=params,
  1740. status=200
  1741. )
  1742. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1743. new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body # nopep8
  1744. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1745. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1746. assert res.json_body
  1747. assert res.json_body['parent_id'] == 4
  1748. assert res.json_body['content_id'] == 8
  1749. assert res.json_body['workspace_id'] == 2
  1750. def test_api_put_move_content__ok_200__to_another_workspace(self):
  1751. """
  1752. Move content
  1753. move Apple_Pie (content_id: 8)
  1754. from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2)
  1755. of workspace Business.
  1756. """
  1757. self.testapp.authorization = (
  1758. 'Basic',
  1759. (
  1760. 'admin@admin.admin',
  1761. 'admin@admin.admin'
  1762. )
  1763. )
  1764. params = {
  1765. 'new_parent_id': '2', # Menus
  1766. 'new_workspace_id': '1',
  1767. }
  1768. params_folder1 = {
  1769. 'parent_id': 3,
  1770. 'show_archived': 0,
  1771. 'show_deleted': 0,
  1772. 'show_active': 1,
  1773. }
  1774. params_folder2 = {
  1775. 'parent_id': 2,
  1776. 'show_archived': 0,
  1777. 'show_deleted': 0,
  1778. 'show_active': 1,
  1779. }
  1780. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1781. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1782. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1783. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1784. # TODO - G.M - 2018-06-163 - Check content
  1785. res = self.testapp.put_json(
  1786. '/api/v2/workspaces/2/contents/8/move',
  1787. params=params,
  1788. status=200
  1789. )
  1790. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1791. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1792. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1793. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1794. assert res.json_body
  1795. assert res.json_body['parent_id'] == 2
  1796. assert res.json_body['content_id'] == 8
  1797. assert res.json_body['workspace_id'] == 1
  1798. def test_api_put_move_content__ok_200__to_another_workspace_root(self):
  1799. """
  1800. Move content
  1801. move Apple_Pie (content_id: 8)
  1802. from Desserts folder(content_id: 3) to root (content_id: 0)
  1803. of workspace Business.
  1804. """
  1805. self.testapp.authorization = (
  1806. 'Basic',
  1807. (
  1808. 'admin@admin.admin',
  1809. 'admin@admin.admin'
  1810. )
  1811. )
  1812. params = {
  1813. 'new_parent_id': None, # root
  1814. 'new_workspace_id': '1',
  1815. }
  1816. params_folder1 = {
  1817. 'parent_id': 3,
  1818. 'show_archived': 0,
  1819. 'show_deleted': 0,
  1820. 'show_active': 1,
  1821. }
  1822. params_folder2 = {
  1823. 'parent_id': 0,
  1824. 'show_archived': 0,
  1825. 'show_deleted': 0,
  1826. 'show_active': 1,
  1827. }
  1828. folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1829. folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1830. assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8
  1831. assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8
  1832. # TODO - G.M - 2018-06-163 - Check content
  1833. res = self.testapp.put_json(
  1834. '/api/v2/workspaces/2/contents/8/move',
  1835. params=params,
  1836. status=200
  1837. )
  1838. new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body # nopep8
  1839. new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body # nopep8
  1840. assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8
  1841. assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8
  1842. assert res.json_body
  1843. assert res.json_body['parent_id'] is None
  1844. assert res.json_body['content_id'] == 8
  1845. assert res.json_body['workspace_id'] == 1
  1846. def test_api_put_move_content__err_400__wrong_workspace_id(self):
  1847. """
  1848. Move content
  1849. move Apple_Pie (content_id: 8)
  1850. from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
  1851. of workspace Recipes.
  1852. Workspace_id of parent_id don't match with workspace_id of workspace
  1853. """
  1854. self.testapp.authorization = (
  1855. 'Basic',
  1856. (
  1857. 'admin@admin.admin',
  1858. 'admin@admin.admin'
  1859. )
  1860. )
  1861. params = {
  1862. 'new_parent_id': '4', # Salads
  1863. 'new_workspace_id': '1',
  1864. }
  1865. params_folder1 = {
  1866. 'parent_id': 3,
  1867. 'show_archived': 0,
  1868. 'show_deleted': 0,
  1869. 'show_active': 1,
  1870. }
  1871. params_folder2 = {
  1872. 'parent_id': 4,
  1873. 'show_archived': 0,
  1874. 'show_deleted': 0,
  1875. 'show_active': 1,
  1876. }
  1877. res = self.testapp.put_json(
  1878. '/api/v2/workspaces/2/contents/8/move',
  1879. params=params,
  1880. status=400,
  1881. )
  1882. def test_api_put_delete_content__ok_200__nominal_case(self):
  1883. """
  1884. delete content
  1885. delete Apple_pie ( content_id: 8, parent_id: 3)
  1886. """
  1887. self.testapp.authorization = (
  1888. 'Basic',
  1889. (
  1890. 'admin@admin.admin',
  1891. 'admin@admin.admin'
  1892. )
  1893. )
  1894. params_active = {
  1895. 'parent_id': 3,
  1896. 'show_archived': 0,
  1897. 'show_deleted': 0,
  1898. 'show_active': 1,
  1899. }
  1900. params_deleted = {
  1901. 'parent_id': 3,
  1902. 'show_archived': 0,
  1903. 'show_deleted': 1,
  1904. 'show_active': 0,
  1905. }
  1906. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1907. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1908. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1909. assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8
  1910. # TODO - G.M - 2018-06-163 - Check content
  1911. res = self.testapp.put_json(
  1912. # INFO - G.M - 2018-06-163 - delete Apple_Pie
  1913. '/api/v2/workspaces/2/contents/8/delete',
  1914. status=204
  1915. )
  1916. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1917. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1918. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1919. assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8
  1920. def test_api_put_archive_content__ok_200__nominal_case(self):
  1921. """
  1922. archive content
  1923. archive Apple_pie ( content_id: 8, parent_id: 3)
  1924. """
  1925. self.testapp.authorization = (
  1926. 'Basic',
  1927. (
  1928. 'admin@admin.admin',
  1929. 'admin@admin.admin'
  1930. )
  1931. )
  1932. params_active = {
  1933. 'parent_id': 3,
  1934. 'show_archived': 0,
  1935. 'show_deleted': 0,
  1936. 'show_active': 1,
  1937. }
  1938. params_archived = {
  1939. 'parent_id': 3,
  1940. 'show_archived': 1,
  1941. 'show_deleted': 0,
  1942. 'show_active': 0,
  1943. }
  1944. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1945. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1946. assert [content for content in active_contents if content['content_id'] == 8] # nopep8
  1947. assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8
  1948. res = self.testapp.put_json(
  1949. '/api/v2/workspaces/2/contents/8/archive',
  1950. status=204
  1951. )
  1952. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1953. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  1954. assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8
  1955. assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8
  1956. def test_api_put_undelete_content__ok_200__nominal_case(self):
  1957. """
  1958. Undelete content
  1959. undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
  1960. """
  1961. self.testapp.authorization = (
  1962. 'Basic',
  1963. (
  1964. 'bob@fsf.local',
  1965. 'foobarbaz'
  1966. )
  1967. )
  1968. params_active = {
  1969. 'parent_id': 10,
  1970. 'show_archived': 0,
  1971. 'show_deleted': 0,
  1972. 'show_active': 1,
  1973. }
  1974. params_deleted = {
  1975. 'parent_id': 10,
  1976. 'show_archived': 0,
  1977. 'show_deleted': 1,
  1978. 'show_active': 0,
  1979. }
  1980. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1981. deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1982. assert not [content for content in active_contents if content['content_id'] == 14] # nopep8
  1983. assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8
  1984. res = self.testapp.put_json(
  1985. '/api/v2/workspaces/2/contents/14/undelete',
  1986. status=204
  1987. )
  1988. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  1989. new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body # nopep8
  1990. assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8
  1991. assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8
  1992. def test_api_put_unarchive_content__ok_200__nominal_case(self):
  1993. """
  1994. unarchive content,
  1995. unarchive Fruit_salads ( content_id: 13, parent_id: 10)
  1996. """
  1997. self.testapp.authorization = (
  1998. 'Basic',
  1999. (
  2000. 'bob@fsf.local',
  2001. 'foobarbaz'
  2002. )
  2003. )
  2004. params_active = {
  2005. 'parent_id': 10,
  2006. 'show_archived': 0,
  2007. 'show_deleted': 0,
  2008. 'show_active': 1,
  2009. }
  2010. params_archived = {
  2011. 'parent_id': 10,
  2012. 'show_archived': 1,
  2013. 'show_deleted': 0,
  2014. 'show_active': 0,
  2015. }
  2016. active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  2017. archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  2018. assert not [content for content in active_contents if content['content_id'] == 13] # nopep8
  2019. assert [content for content in archived_contents if content['content_id'] == 13] # nopep8
  2020. res = self.testapp.put_json(
  2021. '/api/v2/workspaces/2/contents/13/unarchive',
  2022. status=204
  2023. )
  2024. new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body # nopep8
  2025. new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body # nopep8
  2026. assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8
  2027. assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8