Quellcode durchsuchen

Merge pull request #16 from lebouquetin/feature/improve-mail-notifications

Tracim vor 10 Jahren
Ursprung
Commit
c34e9484d6
3 geänderte Dateien mit 362 neuen und 106 gelöschten Zeilen
  1. 4 2
      tracim/tracim/lib/content.py
  2. 9 1
      tracim/tracim/lib/user.py
  3. 349 103
      tracim/tracim/tests/library/test_content_api.py

+ 4 - 2
tracim/tracim/lib/content.py Datei anzeigen

@@ -66,6 +66,7 @@ class ContentApi(object):
66 66
 
67 67
     def __init__(self, current_user: User, show_archived=False, show_deleted=False, all_content_in_treeview=True):
68 68
         self._user = current_user
69
+        self._user_id = current_user.user_id if current_user else None
69 70
         self._show_archived = show_archived
70 71
         self._show_deleted = show_deleted
71 72
         self._show_all_type_of_contents_in_treeview = all_content_in_treeview
@@ -134,8 +135,9 @@ class ContentApi(object):
134 135
             result = result.filter(Content.workspace_id==workspace.workspace_id)
135 136
 
136 137
         if self._user:
138
+            user = DBSession.query(User).get(self._user_id)
137 139
             # Filter according to user workspaces
138
-            workspace_ids = [r.workspace_id for r in self._user.roles \
140
+            workspace_ids = [r.workspace_id for r in user.roles \
139 141
                              if r.role>=UserRoleInWorkspace.READER]
140 142
             result = result.filter(Content.workspace_id.in_(workspace_ids))
141 143
 
@@ -222,7 +224,7 @@ class ContentApi(object):
222 224
 
223 225
         return result
224 226
 
225
-    def create(self, content_type: str, workspace: Workspace=None, parent: Content=None, label:str ='', do_save=False) -> Content:
227
+    def create(self, content_type: str, workspace: Workspace, parent: Content=None, label:str ='', do_save=False) -> Content:
226 228
         assert content_type in ContentType.allowed_types()
227 229
         content = Content()
228 230
         content.owner = self._user

+ 9 - 1
tracim/tracim/lib/user.py Datei anzeigen

@@ -44,9 +44,17 @@ class UserApi(object):
44 44
         except:
45 45
             return False
46 46
 
47
-    def create_user(self, save_now=False) -> User:
47
+    def create_user(self, email=None, groups=[], save_now=False) -> User:
48 48
         user = User()
49
+
50
+        if email:
51
+            user.email = email
52
+
53
+        for group in groups:
54
+            user.groups.append(group)
55
+
49 56
         DBSession.add(user)
57
+
50 58
         if save_now:
51 59
             DBSession.flush()
52 60
 

+ 349 - 103
tracim/tracim/tests/library/test_content_api.py Datei anzeigen

@@ -2,20 +2,23 @@
2 2
 
3 3
 from nose.tools import eq_
4 4
 from nose.tools import raises
5
+from tracim.lib.group import GroupApi
5 6
 
6 7
 import transaction
7 8
 
8
-from tracim.lib.base import logger
9 9
 from tracim.lib.content import compare_content_for_sorting_by_type_and_name
10 10
 from tracim.lib.content import ContentApi
11
+from tracim.lib.group import GroupApi
11 12
 from tracim.lib.user import UserApi
12
-from tracim.lib.user import UserStaticApi
13
+from tracim.lib.workspace import RoleApi
14
+from tracim.lib.workspace import WorkspaceApi
15
+
16
+from tracim.model.auth import Group
13 17
 
14
-from tracim.model.auth import User
15 18
 from tracim.model.data import ActionDescription
16 19
 from tracim.model.data import Content
17 20
 from tracim.model.data import ContentType
18
-from tracim.model.data import ContentStatus
21
+from tracim.model.data import UserRoleInWorkspace
19 22
 
20 23
 from tracim.tests import TestStandard
21 24
 
@@ -85,115 +88,235 @@ class TestContentApi(TestStandard):
85 88
         items = [c1, c2]
86 89
         sorteds = ContentApi.sort_content(items)
87 90
 
88
-        eq_(sorteds[0], c2, 'value is {} instead of {}'.format(sorteds[0].content_id, c2.content_id))
89
-        eq_(sorteds[1], c1, 'value is {} instead of {}'.format(sorteds[1].content_id, c1.content_id))
91
+        eq_(sorteds[0], c2,
92
+            'value is {} instead of {}'.format(sorteds[0].content_id,
93
+                                               c2.content_id))
94
+        eq_(sorteds[1], c1,
95
+            'value is {} instead of {}'.format(sorteds[1].content_id,
96
+                                               c1.content_id))
90 97
 
91 98
     def test_delete(self):
92
-        api = ContentApi(None)
93
-        item = api.create(ContentType.Folder, None, None, 'not_deleted', True)
94
-        item2 = api.create(ContentType.Folder, None, None, 'to_delete', True)
99
+        uapi = UserApi(None)
100
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
101
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
102
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
103
+
104
+        user = uapi.create_user(email='this.is@user',
105
+                                groups=groups, save_now=True)
106
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
107
+                                                        save_now=True)
108
+
109
+        api = ContentApi(user)
110
+        item = api.create(ContentType.Folder, workspace, None,
111
+                          'not_deleted', True)
112
+        item2 = api.create(ContentType.Folder, workspace, None,
113
+                           'to_delete', True)
114
+        uid = user.user_id
115
+        wid = workspace.workspace_id
95 116
         transaction.commit()
96 117
 
97
-        items = api.get_all(None, ContentType.Any, None)
118
+        # Refresh instances after commit
119
+        user = uapi.get_one(uid)
120
+        workspace = WorkspaceApi(user).get_one(wid)
121
+        api = ContentApi(user)
122
+        items = api.get_all(None, ContentType.Any, workspace)
98 123
         eq_(2, len(items))
99 124
 
100
-        items = api.get_all(None, ContentType.Any, None)
125
+        items = api.get_all(None, ContentType.Any, workspace)
101 126
         api.delete(items[0])
102 127
         transaction.commit()
103 128
 
104
-        items = api.get_all(None, ContentType.Any, None)
129
+        # Refresh instances after commit
130
+        user = uapi.get_one(uid)
131
+        workspace = WorkspaceApi(user).get_one(wid)
132
+        api = ContentApi(user)
133
+        items = api.get_all(None, ContentType.Any, workspace)
105 134
         eq_(1, len(items))
106 135
         transaction.commit()
107 136
 
108 137
         # Test that the item is still available if "show deleted" is activated
109
-        api = ContentApi(None, show_deleted=True)
110
-        items = api.get_all(None, ContentType.Any, None)
138
+        # Refresh instances after commit
139
+        user = uapi.get_one(uid)
140
+        workspace = WorkspaceApi(user).get_one(wid)
141
+        api = ContentApi(user, show_deleted=True)
142
+        items = api.get_all(None, ContentType.Any, workspace)
111 143
         eq_(2, len(items))
112 144
 
113 145
 
114 146
     def test_archive(self):
115
-        api = ContentApi(None)
116
-        item = api.create(ContentType.Folder, None, None, 'not_archived', True)
117
-        item2 = api.create(ContentType.Folder, None, None, 'to_archive', True)
147
+        uapi = UserApi(None)
148
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
149
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
150
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
151
+
152
+        user = uapi.create_user(email='this.is@user',
153
+                                groups=groups, save_now=True)
154
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
155
+                                                        save_now=True)
156
+
157
+        api = ContentApi(user)
158
+        item = api.create(ContentType.Folder, workspace, None,
159
+                          'not_archived', True)
160
+        item2 = api.create(ContentType.Folder, workspace, None,
161
+                           'to_archive', True)
162
+        uid = user.user_id
163
+        wid = workspace.workspace_id
118 164
         transaction.commit()
119 165
 
120
-        items = api.get_all(None, ContentType.Any, None)
166
+        # Refresh instances after commit
167
+        user = uapi.get_one(uid)
168
+        workspace = WorkspaceApi(user).get_one(wid)
169
+        api = ContentApi(user)
170
+
171
+        items = api.get_all(None, ContentType.Any, workspace)
121 172
         eq_(2, len(items))
122 173
 
123
-        items = api.get_all(None, ContentType.Any, None)
174
+        items = api.get_all(None, ContentType.Any, workspace)
124 175
         api.archive(items[0])
125 176
         transaction.commit()
126 177
 
127
-        items = api.get_all(None, ContentType.Any, None)
178
+        # Refresh instances after commit
179
+        user = uapi.get_one(uid)
180
+        workspace = WorkspaceApi(user).get_one(wid)
181
+        api = ContentApi(user)
182
+
183
+        items = api.get_all(None, ContentType.Any, workspace)
128 184
         eq_(1, len(items))
129 185
         transaction.commit()
130 186
 
187
+        # Refresh instances after commit
188
+        user = uapi.get_one(uid)
189
+        workspace = WorkspaceApi(user).get_one(wid)
190
+        api = ContentApi(user)
191
+
131 192
         # Test that the item is still available if "show deleted" is activated
132 193
         api = ContentApi(None, show_archived=True)
133
-        items = api.get_all(None, ContentType.Any, None)
194
+        items = api.get_all(None, ContentType.Any, workspace)
134 195
         eq_(2, len(items))
135 196
 
136 197
     def test_get_all_with_filter(self):
137
-        api = ContentApi(None)
138
-        item = api.create(ContentType.Folder, None, None, 'thefolder', True)
139
-        item2 = api.create(ContentType.File, None, None, 'thefile', True)
198
+        uapi = UserApi(None)
199
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
200
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
201
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
202
+
203
+        user = uapi.create_user(email='this.is@user',
204
+                                groups=groups, save_now=True)
205
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
206
+                                                        save_now=True)
207
+
208
+        api = ContentApi(user)
209
+        item = api.create(ContentType.Folder, workspace, None,
210
+                          'thefolder', True)
211
+        item2 = api.create(ContentType.File, workspace, None, 'thefile', True)
212
+        uid = user.user_id
213
+        wid = workspace.workspace_id
140 214
         transaction.commit()
141 215
 
142
-        items = api.get_all(None, ContentType.Any, None)
216
+        # Refresh instances after commit
217
+        user = uapi.get_one(uid)
218
+        workspace = WorkspaceApi(user).get_one(wid)
219
+        api = ContentApi(user)
220
+
221
+        items = api.get_all(None, ContentType.Any, workspace)
143 222
         eq_(2, len(items))
144 223
 
145
-        items2 = api.get_all(None, ContentType.File, None)
224
+        items2 = api.get_all(None, ContentType.File, workspace)
146 225
         eq_(1, len(items2))
147 226
         eq_('thefile', items2[0].label)
148 227
 
149
-        items3 = api.get_all(None, ContentType.Folder, None)
228
+        items3 = api.get_all(None, ContentType.Folder, workspace)
150 229
         eq_(1, len(items3))
151 230
         eq_('thefolder', items3[0].label)
152 231
 
153 232
     def test_get_all_with_parent_id(self):
154
-        api = ContentApi(None)
155
-        item = api.create(ContentType.Folder, None, None, 'parent', True)
156
-        item2 = api.create(ContentType.File, None, item, 'file1', True)
157
-        item3 = api.create(ContentType.File, None, None, 'file2', True)
233
+        uapi = UserApi(None)
234
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
235
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
236
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
237
+
238
+        user = uapi.create_user(email='this.is@user',
239
+                                groups=groups, save_now=True)
240
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
241
+                                                        save_now=True)
242
+
243
+        api = ContentApi(user)
244
+        item = api.create(ContentType.Folder, workspace, None, 'parent', True)
245
+        item2 = api.create(ContentType.File, workspace, item, 'file1', True)
246
+        item3 = api.create(ContentType.File, workspace, None, 'file2', True)
158 247
         parent_id = item.content_id
159 248
         child_id = item2.content_id
249
+        uid = user.user_id
250
+        wid = workspace.workspace_id
160 251
         transaction.commit()
161 252
 
162
-        items = api.get_all(None, ContentType.Any, None)
253
+        # Refresh instances after commit
254
+        user = uapi.get_one(uid)
255
+        workspace = WorkspaceApi(user).get_one(wid)
256
+        api = ContentApi(user)
257
+
258
+        items = api.get_all(None, ContentType.Any, workspace)
163 259
         eq_(3, len(items))
164 260
 
165
-        items2 = api.get_all(parent_id, ContentType.File, None)
261
+        items2 = api.get_all(parent_id, ContentType.File, workspace)
166 262
         eq_(1, len(items2))
167 263
         eq_(child_id, items2[0].content_id)
168 264
 
169 265
     @raises(ValueError)
170 266
     def test_set_status_unknown_status(self):
171
-        api = ContentApi(None)
172
-        c = api.create(ContentType.Folder, None, None, 'parent', True)
267
+        uapi = UserApi(None)
268
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
269
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
270
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
271
+
272
+        user = uapi.create_user(email='this.is@user',
273
+                                groups=groups, save_now=True)
274
+
275
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
276
+                                                        save_now=True)
277
+        api = ContentApi(user)
278
+        c = api.create(ContentType.Folder, workspace, None, 'parent', True)
173 279
         api.set_status(c, 'unknown-status')
174 280
 
175 281
     def test_set_status_ok(self):
176
-        api = ContentApi(None)
177
-        c = api.create(ContentType.Folder, None, None, 'parent', True)
178
-        for new_status in ['open', 'closed-validated', 'closed-unvalidated', 'closed-deprecated']:
282
+        uapi = UserApi(None)
283
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
284
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
285
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
286
+
287
+        user = uapi.create_user(email='this.is@user',
288
+                                groups=groups, save_now=True)
289
+
290
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
291
+                                                        save_now=True)
292
+        api = ContentApi(user)
293
+        c = api.create(ContentType.Folder, workspace, None, 'parent', True)
294
+        for new_status in ['open', 'closed-validated', 'closed-unvalidated',
295
+                           'closed-deprecated']:
179 296
             api.set_status(c, new_status)
180 297
             eq_(new_status, c.status)
181 298
             eq_(ActionDescription.STATUS_UPDATE, c.revision_type)
182 299
 
183 300
     def test_create_comment_ok(self):
184 301
         uapi = UserApi(None)
185
-        user = uapi.create_user()
186
-        user.email = 'this.is@user'
187
-        uapi.save(user)
302
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
303
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
304
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
305
+
306
+        user = uapi.create_user(email='this.is@user',
307
+                                groups=groups, save_now=True)
308
+
309
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
310
+                                                        save_now=True)
188 311
 
189 312
         api = ContentApi(user)
190
-        p = api.create(ContentType.Page, None, None, 'this_is_a_page')
191
-        c = api.create_comment(None, p, 'this is the comment', True)
313
+        p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
314
+        c = api.create_comment(workspace, p, 'this is the comment', True)
192 315
 
193 316
         eq_(Content, c.__class__)
194 317
         eq_(p.content_id, c.parent_id)
195 318
         eq_(user, c.owner)
196
-        eq_(None, c.workspace)
319
+        eq_(workspace, c.workspace)
197 320
         eq_(ContentType.Comment, c.type)
198 321
         eq_('this is the comment', c.description)
199 322
         eq_('', c.label)
@@ -202,17 +325,30 @@ class TestContentApi(TestStandard):
202 325
 
203 326
     def test_update(self):
204 327
         uapi = UserApi(None)
328
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
329
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
330
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
205 331
 
206
-        user1 = uapi.create_user()
207
-        user1.email = 'this.is@user'
208
-        uapi.save(user1)
332
+        user1 = uapi.create_user(email='this.is@user',
333
+                                groups=groups, save_now=True)
334
+
335
+        workspace = WorkspaceApi(user1).create_workspace('test workspace',
336
+                                                        save_now=True)
337
+        wid = workspace.workspace_id
209 338
 
210 339
         user2 = uapi.create_user()
211 340
         user2.email = 'this.is@another.user'
212 341
         uapi.save(user2)
213 342
 
343
+        RoleApi(user1).create_one(user2, workspace,
344
+                                  UserRoleInWorkspace.CONTENT_MANAGER,
345
+                                  flush=True)
346
+
347
+        # Test starts here
348
+
214 349
         api = ContentApi(user1)
215
-        p = api.create(ContentType.Page, None, None, 'this_is_a_page', True)
350
+        p = api.create(ContentType.Page, workspace, None,
351
+                       'this_is_a_page', True)
216 352
 
217 353
         u1id = user1.user_id
218 354
         u2id = user2.user_id
@@ -221,77 +357,126 @@ class TestContentApi(TestStandard):
221 357
 
222 358
         transaction.commit()
223 359
 
224
-        content = api.get_one(pcid, ContentType.Any, None)
360
+        # Refresh instances after commit
361
+        user1 = uapi.get_one(u1id)
362
+        workspace = WorkspaceApi(user1).get_one(wid)
363
+        api = ContentApi(user1)
364
+
365
+        content = api.get_one(pcid, ContentType.Any, workspace)
225 366
         eq_(u1id, content.owner_id)
226 367
         eq_(poid, content.owner_id)
227 368
 
228 369
         u2 = UserApi(None).get_one(u2id)
229 370
         api2 = ContentApi(u2)
230
-        content2 = api2.get_one(pcid, ContentType.Any, None)
371
+        content2 = api2.get_one(pcid, ContentType.Any, workspace)
231 372
         api2.update_content(content2, 'this is an updated page', 'new content')
232 373
         api2.save(content2)
233 374
         transaction.commit()
234 375
 
235
-        updated = api.get_one(pcid, ContentType.Any, None)
236
-        eq_(u2id, updated.owner_id, 'the owner id should be {} (found {})'.format(u2id, updated.owner_id))
376
+        # Refresh instances after commit
377
+        user1 = uapi.get_one(u1id)
378
+        workspace = WorkspaceApi(user1).get_one(wid)
379
+        api = ContentApi(user1)
380
+
381
+        updated = api.get_one(pcid, ContentType.Any, workspace)
382
+        eq_(u2id, updated.owner_id,
383
+            'the owner id should be {} (found {})'.format(u2id,
384
+                                                          updated.owner_id))
237 385
         eq_('this is an updated page', updated.label)
238 386
         eq_('new content', updated.description)
239 387
         eq_(ActionDescription.EDITION, updated.revision_type)
240 388
 
241
-
242 389
     def test_update_file_data(self):
243 390
         uapi = UserApi(None)
391
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
392
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
393
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
244 394
 
245
-        user1 = uapi.create_user()
246
-        user1.email = 'this.is@user'
247
-        uapi.save(user1)
395
+        user1 = uapi.create_user(email='this.is@user',
396
+                                groups=groups, save_now=True)
397
+
398
+        workspace = WorkspaceApi(user1).create_workspace('test workspace',
399
+                                                        save_now=True)
400
+        wid = workspace.workspace_id
248 401
 
249 402
         user2 = uapi.create_user()
250 403
         user2.email = 'this.is@another.user'
251 404
         uapi.save(user2)
252 405
 
406
+        RoleApi(user1).create_one(user2, workspace,
407
+                                  UserRoleInWorkspace.CONTENT_MANAGER,
408
+                                  flush=True)
409
+
410
+        # Test starts here
411
+
253 412
         api = ContentApi(user1)
254
-        p = api.create(ContentType.File, None, None, 'this_is_a_page', True)
413
+        p = api.create(ContentType.File, workspace, None,
414
+                       'this_is_a_page', True)
255 415
 
256 416
         u1id = user1.user_id
257 417
         u2id = user2.user_id
258 418
         pcid = p.content_id
259 419
         poid = p.owner_id
260 420
 
421
+        api.save(p)
261 422
         transaction.commit()
262 423
 
263
-        content = api.get_one(pcid, ContentType.Any, None)
424
+        # Refresh instances after commit
425
+        user1 = uapi.get_one(u1id)
426
+        workspace = WorkspaceApi(user1).get_one(wid)
427
+        api = ContentApi(user1)
428
+
429
+        content = api.get_one(pcid, ContentType.Any, workspace)
264 430
         eq_(u1id, content.owner_id)
265 431
         eq_(poid, content.owner_id)
266 432
 
267 433
         u2 = UserApi(None).get_one(u2id)
268 434
         api2 = ContentApi(u2)
269
-        content2 = api2.get_one(pcid, ContentType.Any, None)
270
-        api2.update_file_data(content2, 'index.html', 'text/html', b'<html>hello world</html>')
435
+        content2 = api2.get_one(pcid, ContentType.Any, workspace)
436
+        api2.update_file_data(content2, 'index.html', 'text/html',
437
+                              b'<html>hello world</html>')
271 438
         api2.save(content2)
272 439
         transaction.commit()
273 440
 
274
-        updated = api.get_one(pcid, ContentType.Any, None)
275
-        eq_(u2id, updated.owner_id, 'the owner id should be {} (found {})'.format(u2id, updated.owner_id))
441
+        # Refresh instances after commit
442
+        user1 = uapi.get_one(u1id)
443
+        workspace = WorkspaceApi(user1).get_one(wid)
444
+
445
+        updated = api.get_one(pcid, ContentType.Any, workspace)
446
+        eq_(u2id, updated.owner_id,
447
+            'the owner id should be {} (found {})'.format(u2id,
448
+                                                          updated.owner_id))
276 449
         eq_('index.html', updated.file_name)
277 450
         eq_('text/html', updated.file_mimetype)
278 451
         eq_(b'<html>hello world</html>', updated.file_content)
279 452
         eq_(ActionDescription.REVISION, updated.revision_type)
280 453
 
281
-
282 454
     def test_archive_unarchive(self):
283 455
         uapi = UserApi(None)
456
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
457
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
458
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
459
+
460
+        user1 = uapi.create_user(email='this.is@user',
461
+                                groups=groups, save_now=True)
462
+        u1id = user1.user_id
284 463
 
285
-        user1 = uapi.create_user()
286
-        user1.email = 'this.is@user'
287
-        uapi.save(user1)
464
+        workspace = WorkspaceApi(user1).create_workspace('test workspace',
465
+                                                        save_now=True)
466
+        wid = workspace.workspace_id
288 467
 
289 468
         user2 = uapi.create_user()
290 469
         user2.email = 'this.is@another.user'
291 470
         uapi.save(user2)
292 471
 
293
-        api = ContentApi(user1, show_archived=True) # show archived is used at the top end of the test
294
-        p = api.create(ContentType.File, None, None, 'this_is_a_page', True)
472
+        RoleApi(user1).create_one(user2, workspace,
473
+                                  UserRoleInWorkspace.CONTENT_MANAGER,
474
+                                  flush=True)
475
+
476
+        # show archived is used at the top end of the test
477
+        api = ContentApi(user1, show_archived=True)
478
+        p = api.create(ContentType.File, workspace, None,
479
+                       'this_is_a_page', True)
295 480
 
296 481
         u1id = user1.user_id
297 482
         u2id = user2.user_id
@@ -302,45 +487,70 @@ class TestContentApi(TestStandard):
302 487
 
303 488
         ####
304 489
 
305
-        content = api.get_one(pcid, ContentType.Any, None)
490
+        # refresh after commit
491
+        user1 = UserApi(None).get_one(u1id)
492
+        workspace = WorkspaceApi(user1).get_one(wid)
493
+
494
+        content = api.get_one(pcid, ContentType.Any, workspace)
306 495
         eq_(u1id, content.owner_id)
307 496
         eq_(poid, content.owner_id)
308 497
 
309 498
         u2 = UserApi(None).get_one(u2id)
310 499
         api2 = ContentApi(u2, show_archived=True)
311
-        content2 = api2.get_one(pcid, ContentType.Any, None)
500
+        content2 = api2.get_one(pcid, ContentType.Any, workspace)
312 501
         api2.archive(content2)
313 502
         api2.save(content2)
314 503
         transaction.commit()
315 504
 
316
-        updated = api2.get_one(pcid, ContentType.Any, None)
317
-        eq_(u2id, updated.owner_id, 'the owner id should be {} (found {})'.format(u2id, updated.owner_id))
505
+        # refresh after commit
506
+        user1 = UserApi(None).get_one(u1id)
507
+        workspace = WorkspaceApi(user1).get_one(wid)
508
+        u2 = UserApi(None).get_one(u2id)
509
+        api = ContentApi(user1, show_archived=True)
510
+        api2 = ContentApi(u2, show_archived=True)
511
+
512
+        updated = api2.get_one(pcid, ContentType.Any, workspace)
513
+        eq_(u2id, updated.owner_id,
514
+            'the owner id should be {} (found {})'.format(u2id,
515
+                                                          updated.owner_id))
318 516
         eq_(True, updated.is_archived)
319 517
         eq_(ActionDescription.ARCHIVING, updated.revision_type)
320 518
 
321 519
         ####
322 520
 
323
-        updated2 = api.get_one(pcid, ContentType.Any, None)
521
+        updated2 = api.get_one(pcid, ContentType.Any, workspace)
324 522
         api.unarchive(updated)
325 523
         api.save(updated2)
326 524
         eq_(False, updated2.is_archived)
327 525
         eq_(ActionDescription.UNARCHIVING, updated2.revision_type)
328 526
         eq_(u1id, updated2.owner_id)
329 527
 
330
-
331 528
     def test_delete_undelete(self):
332 529
         uapi = UserApi(None)
530
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
531
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
532
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
533
+
534
+        user1 = uapi.create_user(email='this.is@user',
535
+                                groups=groups, save_now=True)
536
+        u1id = user1.user_id
333 537
 
334
-        user1 = uapi.create_user()
335
-        user1.email = 'this.is@user'
336
-        uapi.save(user1)
538
+        workspace = WorkspaceApi(user1).create_workspace('test workspace',
539
+                                                        save_now=True)
540
+        wid = workspace.workspace_id
337 541
 
338 542
         user2 = uapi.create_user()
339 543
         user2.email = 'this.is@another.user'
340 544
         uapi.save(user2)
341 545
 
342
-        api = ContentApi(user1, show_deleted=True) # show archived is used at the top end of the test
343
-        p = api.create(ContentType.File, None, None, 'this_is_a_page', True)
546
+        RoleApi(user1).create_one(user2, workspace,
547
+                                  UserRoleInWorkspace.CONTENT_MANAGER,
548
+                                  flush=True)
549
+
550
+        # show archived is used at the top end of the test
551
+        api = ContentApi(user1, show_deleted=True)
552
+        p = api.create(ContentType.File, workspace, None,
553
+                       'this_is_a_page', True)
344 554
 
345 555
         u1id = user1.user_id
346 556
         u2id = user2.user_id
@@ -350,26 +560,39 @@ class TestContentApi(TestStandard):
350 560
         transaction.commit()
351 561
 
352 562
         ####
563
+        user1 = UserApi(None).get_one(u1id)
564
+        workspace = WorkspaceApi(user1).get_one(wid)
353 565
 
354
-        content = api.get_one(pcid, ContentType.Any, None)
566
+        content = api.get_one(pcid, ContentType.Any, workspace)
355 567
         eq_(u1id, content.owner_id)
356 568
         eq_(poid, content.owner_id)
357 569
 
358 570
         u2 = UserApi(None).get_one(u2id)
359 571
         api2 = ContentApi(u2, show_deleted=True)
360
-        content2 = api2.get_one(pcid, ContentType.Any, None)
572
+        content2 = api2.get_one(pcid, ContentType.Any, workspace)
361 573
         api2.delete(content2)
362 574
         api2.save(content2)
363 575
         transaction.commit()
364 576
 
365
-        updated = api2.get_one(pcid, ContentType.Any, None)
366
-        eq_(u2id, updated.owner_id, 'the owner id should be {} (found {})'.format(u2id, updated.owner_id))
577
+        ####
578
+
579
+        user1 = UserApi(None).get_one(u1id)
580
+        workspace = WorkspaceApi(user1).get_one(wid)
581
+        # show archived is used at the top end of the test
582
+        api = ContentApi(user1, show_deleted=True)
583
+        u2 = UserApi(None).get_one(u2id)
584
+        api2 = ContentApi(u2, show_deleted=True)
585
+
586
+        updated = api2.get_one(pcid, ContentType.Any, workspace)
587
+        eq_(u2id, updated.owner_id,
588
+            'the owner id should be {} (found {})'.format(u2id,
589
+                                                          updated.owner_id))
367 590
         eq_(True, updated.is_deleted)
368 591
         eq_(ActionDescription.DELETION, updated.revision_type)
369 592
 
370 593
         ####
371 594
 
372
-        updated2 = api.get_one(pcid, ContentType.Any, None)
595
+        updated2 = api.get_one(pcid, ContentType.Any, workspace)
373 596
         api.undelete(updated)
374 597
         api.save(updated2)
375 598
         eq_(False, updated2.is_deleted)
@@ -381,14 +604,21 @@ class TestContentApi(TestStandard):
381 604
         # This test is based on a bug which does NOT return results found
382 605
         # at root of a workspace (eg a folder)
383 606
         uapi = UserApi(None)
384
-        user = uapi.create_user()
385
-        user.email = 'this.is@user'
386
-        uapi.save(user)
607
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
608
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
609
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
387 610
 
388
-        api = ContentApi(user)
611
+        user = uapi.create_user(email='this.is@user',
612
+                                groups=groups, save_now=True)
389 613
 
390
-        a = api.create(ContentType.Folder, None, None, 'this is randomized folder', True)
391
-        p = api.create(ContentType.Page, None, a, 'this is randomized label content', True)
614
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
615
+                                                        save_now=True)
616
+
617
+        api = ContentApi(user)
618
+        a = api.create(ContentType.Folder, workspace, None,
619
+                       'this is randomized folder', True)
620
+        p = api.create(ContentType.Page, workspace, a,
621
+                       'this is randomized label content', True)
392 622
         p.description = 'This is some amazing test'
393 623
         api.save(p)
394 624
         original_id = p.content_id
@@ -402,16 +632,23 @@ class TestContentApi(TestStandard):
402 632
         # HACK - D.A. - 2015-03-09
403 633
         # This test is based on a bug which does NOT return results found
404 634
         # at root of a workspace (eg a folder)
635
+
405 636
         uapi = UserApi(None)
406
-        user = uapi.create_user()
407
-        user.email = 'this.is@user'
408
-        uapi.save(user)
637
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
638
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
639
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
409 640
 
410
-        api = ContentApi(user)
641
+        user = uapi.create_user(email='this.is@user',
642
+                                groups=groups, save_now=True)
411 643
 
412
-        a = api.create(ContentType.Folder, None, None, 'this is randomized folder', True)
644
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
645
+                                                        save_now=True)
413 646
 
414
-        p = api.create(ContentType.Page, None, a, 'this is dummy label content', True)
647
+        api = ContentApi(user)
648
+        a = api.create(ContentType.Folder, workspace, None,
649
+                       'this is randomized folder', True)
650
+        p = api.create(ContentType.Page, workspace, a,
651
+                       'this is dummy label content', True)
415 652
         p.description = 'This is some amazing test'
416 653
         api.save(p)
417 654
         original_id = p.content_id
@@ -421,22 +658,31 @@ class TestContentApi(TestStandard):
421 658
         item = res.all()[0]
422 659
         eq_(original_id, item.content_id)
423 660
 
424
-
425 661
     def test_search_in_label_or_description(self):
426 662
         # HACK - D.A. - 2015-03-09
427 663
         # This test is based on a bug which does NOT return results found
428 664
         # at root of a workspace (eg a folder)
665
+
429 666
         uapi = UserApi(None)
430
-        user = uapi.create_user()
431
-        user.email = 'this.is@user'
432
-        uapi.save(user)
667
+        groups = [GroupApi(None).get_one(Group.TIM_USER),
668
+                  GroupApi(None).get_one(Group.TIM_MANAGER),
669
+                  GroupApi(None).get_one(Group.TIM_ADMIN)]
670
+
671
+        user = uapi.create_user(email='this.is@user',
672
+                                groups=groups, save_now=True)
673
+
674
+        workspace = WorkspaceApi(user).create_workspace('test workspace',
675
+                                                        save_now=True)
676
+
433 677
 
434 678
         api = ContentApi(user)
435 679
 
436
-        a = api.create(ContentType.Folder, None, None, 'this is randomized folder', True)
437
-        p1 = api.create(ContentType.Page, None, a, 'this is dummy label content', True)
680
+        a = api.create(ContentType.Folder, workspace, None,
681
+                       'this is randomized folder', True)
682
+        p1 = api.create(ContentType.Page, workspace, a,
683
+                        'this is dummy label content', True)
438 684
         p1.description = 'This is some amazing test'
439
-        p2 = api.create(ContentType.Page, None, a, 'Hey ! Jon !', True)
685
+        p2 = api.create(ContentType.Page, workspace, a, 'Hey ! Jon !', True)
440 686
         p2.description = 'What\'s up ?'
441 687
         api.save(p1)
442 688
         api.save(p2)