content.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # -*- coding: utf-8 -*-
  2. from depot.io.utils import FileIntent
  3. from tracim import models
  4. from tracim.fixtures import Fixture
  5. from tracim.fixtures.users_and_groups import Test
  6. from tracim.lib.core.content import ContentApi
  7. from tracim.lib.core.userworkspace import RoleApi
  8. from tracim.lib.core.workspace import WorkspaceApi
  9. from tracim.models.data import ContentType
  10. from tracim.models.data import UserRoleInWorkspace
  11. class Content(Fixture):
  12. require = [Test]
  13. def insert(self):
  14. admin = self._session.query(models.User) \
  15. .filter(models.User.email == 'admin@admin.admin') \
  16. .one()
  17. bob = self._session.query(models.User) \
  18. .filter(models.User.email == 'bob@fsf.local') \
  19. .one()
  20. admin_workspace_api = WorkspaceApi(
  21. current_user=admin,
  22. session=self._session,
  23. )
  24. bob_workspace_api = WorkspaceApi(
  25. current_user=bob,
  26. session=self._session,
  27. )
  28. content_api = ContentApi(
  29. current_user=admin,
  30. session=self._session,
  31. config=self._config
  32. )
  33. role_api = RoleApi(
  34. current_user=admin,
  35. session=self._session,
  36. )
  37. # Workspaces
  38. w1 = admin_workspace_api.create_workspace('w1', save_now=True)
  39. w2 = bob_workspace_api.create_workspace('w2', save_now=True)
  40. w3 = admin_workspace_api.create_workspace('w3', save_now=True)
  41. # Workspaces roles
  42. role_api.create_one(
  43. user=bob,
  44. workspace=w1,
  45. role_level=UserRoleInWorkspace.CONTENT_MANAGER,
  46. with_notif=False,
  47. )
  48. # Folders
  49. w1f1 = content_api.create(
  50. content_type=ContentType.Folder,
  51. workspace=w1,
  52. label='w1f1',
  53. do_save=True,
  54. do_notify=False,
  55. )
  56. w1f2 = content_api.create(
  57. content_type=ContentType.Folder,
  58. workspace=w1,
  59. label='w1f2',
  60. do_save=True,
  61. do_notify=False,
  62. )
  63. w2f1 = content_api.create(
  64. content_type=ContentType.Folder,
  65. workspace=w2,
  66. label='w2f1',
  67. do_save=True,
  68. do_notify=False,
  69. )
  70. w2f2 = content_api.create(
  71. content_type=ContentType.Folder,
  72. workspace=w2,
  73. label='w2f2',
  74. do_save=True,
  75. do_notify=False,
  76. )
  77. w3f1 = content_api.create(
  78. content_type=ContentType.Folder,
  79. workspace=w3,
  80. label='w3f3',
  81. do_save=True,
  82. do_notify=False,
  83. )
  84. # Pages, threads, ..
  85. w1f1p1 = content_api.create(
  86. content_type=ContentType.Page,
  87. workspace=w1,
  88. parent=w1f1,
  89. label='w1f1p1',
  90. do_save=True,
  91. do_notify=False,
  92. )
  93. w1f1t1 = content_api.create(
  94. content_type=ContentType.Thread,
  95. workspace=w1,
  96. parent=w1f1,
  97. label='w1f1t1',
  98. do_save=False,
  99. do_notify=False,
  100. )
  101. w1f1t1.description = 'w1f1t1 description'
  102. self._session.add(w1f1t1)
  103. w1f1d1_txt = content_api.create(
  104. content_type=ContentType.File,
  105. workspace=w1,
  106. parent=w1f1,
  107. label='w1f1d1',
  108. do_save=False,
  109. do_notify=False,
  110. )
  111. w1f1d1_txt.file_extension = '.txt'
  112. w1f1d1_txt.depot_file = FileIntent(
  113. b'w1f1d1 content',
  114. 'w1f1d1.txt',
  115. 'text/plain',
  116. )
  117. self._session.add(w1f1d1_txt)
  118. w1f1d2_html = content_api.create(
  119. content_type=ContentType.File,
  120. workspace=w1,
  121. parent=w1f1,
  122. label='w1f1d2',
  123. do_save=False,
  124. do_notify=False,
  125. )
  126. w1f1d2_html.file_extension = '.html'
  127. w1f1d2_html.depot_file = FileIntent(
  128. b'<p>w1f1d2 content</p>',
  129. 'w1f1d2.html',
  130. 'text/html',
  131. )
  132. self._session.add(w1f1d2_html)
  133. w1f1f1 = content_api.create(
  134. content_type=ContentType.Folder,
  135. workspace=w1,
  136. label='w1f1f1',
  137. parent=w1f1,
  138. do_save=True,
  139. do_notify=False,
  140. )
  141. w2f1p1 = content_api.create(
  142. content_type=ContentType.Page,
  143. workspace=w2,
  144. parent=w2f1,
  145. label='w2f1p1',
  146. do_save=True,
  147. do_notify=False,
  148. )
  149. self._session.flush()