test_workspaces.py 78KB

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