|
@@ -9,7 +9,8 @@ from tracim_backend.lib.core.content import ContentApi
|
9
|
9
|
# TODO - G.M - 28-03-2018 - [GroupApi] Re-enable GroupApi
|
10
|
10
|
from tracim_backend.lib.core.group import GroupApi
|
11
|
11
|
from tracim_backend.lib.core.user import UserApi
|
12
|
|
-from tracim_backend.exceptions import SameValueError
|
|
12
|
+from tracim_backend.exceptions import SameValueError, EmptyLabelNotAllowed, \
|
|
13
|
+ UnallowedSubContent
|
13
|
14
|
# TODO - G.M - 28-03-2018 - [RoleApi] Re-enable RoleApi
|
14
|
15
|
from tracim_backend.lib.core.workspace import RoleApi
|
15
|
16
|
# TODO - G.M - 28-03-2018 - [WorkspaceApi] Re-enable WorkspaceApi
|
|
@@ -101,6 +102,181 @@ class TestContentApi(DefaultTest):
|
101
|
102
|
'value is {} instead of {}'.format(sorteds[1].content_id,
|
102
|
103
|
c1.content_id))
|
103
|
104
|
|
|
105
|
+ def test_unit__create_content__OK_nominal_case(self):
|
|
106
|
+ uapi = UserApi(
|
|
107
|
+ session=self.session,
|
|
108
|
+ config=self.app_config,
|
|
109
|
+ current_user=None,
|
|
110
|
+ )
|
|
111
|
+ group_api = GroupApi(
|
|
112
|
+ current_user=None,
|
|
113
|
+ session=self.session,
|
|
114
|
+ config=self.app_config,
|
|
115
|
+ )
|
|
116
|
+ groups = [group_api.get_one(Group.TIM_USER),
|
|
117
|
+ group_api.get_one(Group.TIM_MANAGER),
|
|
118
|
+ group_api.get_one(Group.TIM_ADMIN)]
|
|
119
|
+
|
|
120
|
+ user = uapi.create_minimal_user(email='this.is@user',
|
|
121
|
+ groups=groups, save_now=True)
|
|
122
|
+ workspace = WorkspaceApi(
|
|
123
|
+ current_user=user,
|
|
124
|
+ session=self.session,
|
|
125
|
+ config=self.app_config,
|
|
126
|
+ ).create_workspace('test workspace', save_now=True)
|
|
127
|
+ api = ContentApi(
|
|
128
|
+ current_user=user,
|
|
129
|
+ session=self.session,
|
|
130
|
+ config=self.app_config,
|
|
131
|
+ )
|
|
132
|
+ item = api.create(
|
|
133
|
+ content_type_slug=CONTENT_TYPES.Folder.slug,
|
|
134
|
+ workspace=workspace,
|
|
135
|
+ parent=None,
|
|
136
|
+ label='not_deleted',
|
|
137
|
+ do_save=True
|
|
138
|
+ )
|
|
139
|
+ assert isinstance(item, Content)
|
|
140
|
+
|
|
141
|
+ def test_unit__create_content__err_empty_label(self):
|
|
142
|
+ uapi = UserApi(
|
|
143
|
+ session=self.session,
|
|
144
|
+ config=self.app_config,
|
|
145
|
+ current_user=None,
|
|
146
|
+ )
|
|
147
|
+ group_api = GroupApi(
|
|
148
|
+ current_user=None,
|
|
149
|
+ session=self.session,
|
|
150
|
+ config=self.app_config,
|
|
151
|
+ )
|
|
152
|
+ groups = [group_api.get_one(Group.TIM_USER),
|
|
153
|
+ group_api.get_one(Group.TIM_MANAGER),
|
|
154
|
+ group_api.get_one(Group.TIM_ADMIN)]
|
|
155
|
+
|
|
156
|
+ user = uapi.create_minimal_user(email='this.is@user',
|
|
157
|
+ groups=groups, save_now=True)
|
|
158
|
+ workspace = WorkspaceApi(
|
|
159
|
+ current_user=user,
|
|
160
|
+ session=self.session,
|
|
161
|
+ config=self.app_config,
|
|
162
|
+ ).create_workspace('test workspace', save_now=True)
|
|
163
|
+ api = ContentApi(
|
|
164
|
+ current_user=user,
|
|
165
|
+ session=self.session,
|
|
166
|
+ config=self.app_config,
|
|
167
|
+ )
|
|
168
|
+ with pytest.raises(EmptyLabelNotAllowed):
|
|
169
|
+ api.create(
|
|
170
|
+ content_type_slug=CONTENT_TYPES.Thread.slug,
|
|
171
|
+ workspace=workspace,
|
|
172
|
+ parent=None,
|
|
173
|
+ label='',
|
|
174
|
+ do_save=True
|
|
175
|
+ )
|
|
176
|
+
|
|
177
|
+ def test_unit__create_content__err_content_type_not_allowed_in_this_folder(self):
|
|
178
|
+ uapi = UserApi(
|
|
179
|
+ session=self.session,
|
|
180
|
+ config=self.app_config,
|
|
181
|
+ current_user=None,
|
|
182
|
+ )
|
|
183
|
+ group_api = GroupApi(
|
|
184
|
+ current_user=None,
|
|
185
|
+ session=self.session,
|
|
186
|
+ config=self.app_config,
|
|
187
|
+ )
|
|
188
|
+ groups = [group_api.get_one(Group.TIM_USER),
|
|
189
|
+ group_api.get_one(Group.TIM_MANAGER),
|
|
190
|
+ group_api.get_one(Group.TIM_ADMIN)]
|
|
191
|
+
|
|
192
|
+ user = uapi.create_minimal_user(email='this.is@user',
|
|
193
|
+ groups=groups, save_now=True)
|
|
194
|
+ workspace = WorkspaceApi(
|
|
195
|
+ current_user=user,
|
|
196
|
+ session=self.session,
|
|
197
|
+ config=self.app_config,
|
|
198
|
+ ).create_workspace('test workspace', save_now=True)
|
|
199
|
+ api = ContentApi(
|
|
200
|
+ current_user=user,
|
|
201
|
+ session=self.session,
|
|
202
|
+ config=self.app_config,
|
|
203
|
+ )
|
|
204
|
+ folder = api.create(
|
|
205
|
+ content_type_slug=CONTENT_TYPES.Folder.slug,
|
|
206
|
+ workspace=workspace,
|
|
207
|
+ parent=None,
|
|
208
|
+ label='plop',
|
|
209
|
+ do_save=False
|
|
210
|
+ )
|
|
211
|
+ allowed_content_dict = {CONTENT_TYPES.Folder.slug: True, CONTENT_TYPES.File.slug: False} # nopep8
|
|
212
|
+ api.set_allowed_content(
|
|
213
|
+ folder,
|
|
214
|
+ allowed_content_dict=allowed_content_dict
|
|
215
|
+ )
|
|
216
|
+ api.save(content=folder)
|
|
217
|
+ # not in list -> do not allow
|
|
218
|
+ with pytest.raises(UnallowedSubContent):
|
|
219
|
+ api.create(
|
|
220
|
+ content_type_slug=CONTENT_TYPES.Event.slug,
|
|
221
|
+ workspace=workspace,
|
|
222
|
+ parent=folder,
|
|
223
|
+ label='lapin',
|
|
224
|
+ do_save=True
|
|
225
|
+ )
|
|
226
|
+ # in list but false -> do not allow
|
|
227
|
+ with pytest.raises(UnallowedSubContent):
|
|
228
|
+ api.create(
|
|
229
|
+ content_type_slug=CONTENT_TYPES.File.slug,
|
|
230
|
+ workspace=workspace,
|
|
231
|
+ parent=folder,
|
|
232
|
+ label='lapin',
|
|
233
|
+ do_save=True
|
|
234
|
+ )
|
|
235
|
+ # in list and true -> allow
|
|
236
|
+ api.create(
|
|
237
|
+ content_type_slug=CONTENT_TYPES.Folder.slug,
|
|
238
|
+ workspace=workspace,
|
|
239
|
+ parent=folder,
|
|
240
|
+ label='lapin',
|
|
241
|
+ do_save=True
|
|
242
|
+ )
|
|
243
|
+
|
|
244
|
+ def test_unit__create_content__err_content_type_not_allowed_in_this_workspace(self):
|
|
245
|
+ uapi = UserApi(
|
|
246
|
+ session=self.session,
|
|
247
|
+ config=self.app_config,
|
|
248
|
+ current_user=None,
|
|
249
|
+ )
|
|
250
|
+ group_api = GroupApi(
|
|
251
|
+ current_user=None,
|
|
252
|
+ session=self.session,
|
|
253
|
+ config=self.app_config,
|
|
254
|
+ )
|
|
255
|
+ groups = [group_api.get_one(Group.TIM_USER),
|
|
256
|
+ group_api.get_one(Group.TIM_MANAGER),
|
|
257
|
+ group_api.get_one(Group.TIM_ADMIN)]
|
|
258
|
+
|
|
259
|
+ user = uapi.create_minimal_user(email='this.is@user',
|
|
260
|
+ groups=groups, save_now=True)
|
|
261
|
+ workspace = WorkspaceApi(
|
|
262
|
+ current_user=user,
|
|
263
|
+ session=self.session,
|
|
264
|
+ config=self.app_config,
|
|
265
|
+ ).create_workspace('test workspace', save_now=True)
|
|
266
|
+ api = ContentApi(
|
|
267
|
+ current_user=user,
|
|
268
|
+ session=self.session,
|
|
269
|
+ config=self.app_config,
|
|
270
|
+ )
|
|
271
|
+ with pytest.raises(UnallowedSubContent):
|
|
272
|
+ api.create(
|
|
273
|
+ content_type_slug=CONTENT_TYPES.Event.slug,
|
|
274
|
+ workspace=workspace,
|
|
275
|
+ parent=None,
|
|
276
|
+ label='lapin',
|
|
277
|
+ do_save=True
|
|
278
|
+ )
|
|
279
|
+
|
104
|
280
|
def test_delete(self):
|
105
|
281
|
uapi = UserApi(
|
106
|
282
|
session=self.session,
|