test_workspaces.py 59KB

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