|
@@ -2,13 +2,727 @@
|
2
|
2
|
"""
|
3
|
3
|
Tests for /api/v2/users subpath endpoints.
|
4
|
4
|
"""
|
|
5
|
+from time import sleep
|
|
6
|
+
|
|
7
|
+import pytest
|
|
8
|
+import transaction
|
|
9
|
+
|
|
10
|
+from tracim import models
|
|
11
|
+from tracim.lib.core.content import ContentApi
|
|
12
|
+from tracim.lib.core.user import UserApi
|
|
13
|
+from tracim.lib.core.workspace import WorkspaceApi
|
|
14
|
+from tracim.models import get_tm_session
|
|
15
|
+from tracim.models.contents import ContentTypeLegacy as ContentType
|
|
16
|
+from tracim.models.revision_protection import new_revision
|
5
|
17
|
from tracim.tests import FunctionalTest
|
6
|
18
|
from tracim.fixtures.content import Content as ContentFixtures
|
7
|
19
|
from tracim.fixtures.users_and_groups import Base as BaseFixture
|
8
|
20
|
|
9
|
21
|
|
|
22
|
+class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
|
|
23
|
+ """
|
|
24
|
+ Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/recently_active
|
|
25
|
+ """
|
|
26
|
+ fixtures = [BaseFixture]
|
|
27
|
+
|
|
28
|
+ def test_api__get_recently_active_content__ok__200__nominal_case(self):
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
32
|
+ admin = dbsession.query(models.User) \
|
|
33
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
34
|
+ .one()
|
|
35
|
+ workspace_api = WorkspaceApi(
|
|
36
|
+ current_user=admin,
|
|
37
|
+ session=dbsession,
|
|
38
|
+ config=self.app_config
|
|
39
|
+
|
|
40
|
+ )
|
|
41
|
+ workspace = WorkspaceApi(
|
|
42
|
+ current_user=admin,
|
|
43
|
+ session=dbsession,
|
|
44
|
+ config=self.app_config,
|
|
45
|
+ ).create_workspace(
|
|
46
|
+ 'test workspace',
|
|
47
|
+ save_now=True
|
|
48
|
+ )
|
|
49
|
+ workspace2 = WorkspaceApi(
|
|
50
|
+ current_user=admin,
|
|
51
|
+ session=dbsession,
|
|
52
|
+ config=self.app_config,
|
|
53
|
+ ).create_workspace(
|
|
54
|
+ 'test workspace2',
|
|
55
|
+ save_now=True
|
|
56
|
+ )
|
|
57
|
+
|
|
58
|
+ api = ContentApi(
|
|
59
|
+ current_user=admin,
|
|
60
|
+ session=dbsession,
|
|
61
|
+ config=self.app_config,
|
|
62
|
+ )
|
|
63
|
+ main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)
|
|
64
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
65
|
+
|
|
66
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
67
|
+ secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)
|
|
68
|
+
|
|
69
|
+ firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)
|
|
70
|
+ secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)
|
|
71
|
+ with new_revision(
|
|
72
|
+ session=dbsession,
|
|
73
|
+ tm=transaction.manager,
|
|
74
|
+ content=firstly_created_but_recently_updated,
|
|
75
|
+ ):
|
|
76
|
+ firstly_created_but_recently_updated.description = 'Just an update'
|
|
77
|
+ api.save(firstly_created_but_recently_updated)
|
|
78
|
+
|
|
79
|
+ firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)
|
|
80
|
+ secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)
|
|
81
|
+ comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)
|
|
82
|
+ content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)
|
|
83
|
+ dbsession.flush()
|
|
84
|
+ transaction.commit()
|
|
85
|
+
|
|
86
|
+ self.testapp.authorization = (
|
|
87
|
+ 'Basic',
|
|
88
|
+ (
|
|
89
|
+ 'admin@admin.admin',
|
|
90
|
+ 'admin@admin.admin'
|
|
91
|
+ )
|
|
92
|
+ )
|
|
93
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/recently_active'.format(workspace.workspace_id), status=200)
|
|
94
|
+ res = res.json_body
|
|
95
|
+ assert len(res) == 7
|
|
96
|
+ for elem in res:
|
|
97
|
+ assert isinstance(elem['content_id'], int)
|
|
98
|
+ assert isinstance(elem['content_type'], str)
|
|
99
|
+ assert elem['content_type'] != 'comments'
|
|
100
|
+ assert isinstance(elem['is_archived'], bool)
|
|
101
|
+ assert isinstance(elem['is_deleted'], bool)
|
|
102
|
+ assert isinstance(elem['label'], str)
|
|
103
|
+ assert isinstance(elem['parent_id'], int) or elem['parent_id'] is None
|
|
104
|
+ assert isinstance(elem['show_in_ui'], bool)
|
|
105
|
+ assert isinstance(elem['slug'], str)
|
|
106
|
+ assert isinstance(elem['status'], str)
|
|
107
|
+ assert isinstance(elem['sub_content_types'], list)
|
|
108
|
+ for sub_content_type in elem['sub_content_types']:
|
|
109
|
+ assert isinstance(sub_content_type, str)
|
|
110
|
+ assert isinstance(elem['workspace_id'], int)
|
|
111
|
+
|
|
112
|
+ assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
|
|
113
|
+ assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+ assert res[2]['content_id'] == firstly_created_but_recently_updated.content_id
|
|
117
|
+ assert res[3]['content_id'] == secondly_created_but_not_updated.content_id
|
|
118
|
+
|
|
119
|
+ assert res[4]['content_id'] == secondly_created.content_id
|
|
120
|
+ assert res[5]['content_id'] == firstly_created.content_id
|
|
121
|
+
|
|
122
|
+ assert res[6]['content_id'] == main_folder.content_id
|
|
123
|
+
|
|
124
|
+ @pytest.mark.skip('Test should be fixed')
|
|
125
|
+ def test_api__get_recently_active_content__ok__200__limit_2_multiple(self):
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
131
|
+ admin = dbsession.query(models.User) \
|
|
132
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
133
|
+ .one()
|
|
134
|
+ workspace_api = WorkspaceApi(
|
|
135
|
+ current_user=admin,
|
|
136
|
+ session=dbsession,
|
|
137
|
+ config=self.app_config
|
|
138
|
+
|
|
139
|
+ )
|
|
140
|
+ workspace = WorkspaceApi(
|
|
141
|
+ current_user=admin,
|
|
142
|
+ session=dbsession,
|
|
143
|
+ config=self.app_config,
|
|
144
|
+ ).create_workspace(
|
|
145
|
+ 'test workspace',
|
|
146
|
+ save_now=True
|
|
147
|
+ )
|
|
148
|
+ workspace2 = WorkspaceApi(
|
|
149
|
+ current_user=admin,
|
|
150
|
+ session=dbsession,
|
|
151
|
+ config=self.app_config,
|
|
152
|
+ ).create_workspace(
|
|
153
|
+ 'test workspace2',
|
|
154
|
+ save_now=True
|
|
155
|
+ )
|
|
156
|
+
|
|
157
|
+ api = ContentApi(
|
|
158
|
+ current_user=admin,
|
|
159
|
+ session=dbsession,
|
|
160
|
+ config=self.app_config,
|
|
161
|
+ )
|
|
162
|
+ main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)
|
|
163
|
+ sleep(1)
|
|
164
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
165
|
+
|
|
166
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
167
|
+ sleep(1)
|
|
168
|
+ secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)
|
|
169
|
+
|
|
170
|
+ firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)
|
|
171
|
+ sleep(1)
|
|
172
|
+ secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)
|
|
173
|
+ sleep(1)
|
|
174
|
+ with new_revision(
|
|
175
|
+ session=dbsession,
|
|
176
|
+ tm=transaction.manager,
|
|
177
|
+ content=firstly_created_but_recently_updated,
|
|
178
|
+ ):
|
|
179
|
+ firstly_created_but_recently_updated.description = 'Just an update'
|
|
180
|
+ api.save(firstly_created_but_recently_updated)
|
|
181
|
+
|
|
182
|
+ firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)
|
|
183
|
+ sleep(1)
|
|
184
|
+ secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)
|
|
185
|
+ sleep(1)
|
|
186
|
+ comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)
|
|
187
|
+ sleep(1)
|
|
188
|
+ content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)
|
|
189
|
+ dbsession.flush()
|
|
190
|
+ transaction.commit()
|
|
191
|
+
|
|
192
|
+ self.testapp.authorization = (
|
|
193
|
+ 'Basic',
|
|
194
|
+ (
|
|
195
|
+ 'admin@admin.admin',
|
|
196
|
+ 'admin@admin.admin'
|
|
197
|
+ )
|
|
198
|
+ )
|
|
199
|
+ params = {
|
|
200
|
+ 'limit': 2,
|
|
201
|
+ }
|
|
202
|
+ res = self.testapp.get(
|
|
203
|
+ '/api/v2/users/1/workspaces/{}/contents/recently_active'.format(workspace.workspace_id),
|
|
204
|
+ status=200,
|
|
205
|
+ params=params
|
|
206
|
+ )
|
|
207
|
+ res = res.json_body
|
|
208
|
+ assert len(res) == 2
|
|
209
|
+ for elem in res:
|
|
210
|
+ assert isinstance(elem['content_id'], int)
|
|
211
|
+ assert isinstance(elem['content_type'], str)
|
|
212
|
+ assert elem['content_type'] != 'comments'
|
|
213
|
+ assert isinstance(elem['is_archived'], bool)
|
|
214
|
+ assert isinstance(elem['is_deleted'], bool)
|
|
215
|
+ assert isinstance(elem['label'], str)
|
|
216
|
+ assert isinstance(elem['parent_id'], int) or elem['parent_id'] is None
|
|
217
|
+ assert isinstance(elem['show_in_ui'], bool)
|
|
218
|
+ assert isinstance(elem['slug'], str)
|
|
219
|
+ assert isinstance(elem['status'], str)
|
|
220
|
+ assert isinstance(elem['sub_content_types'], list)
|
|
221
|
+ for sub_content_type in elem['sub_content_types']:
|
|
222
|
+ assert isinstance(sub_content_type, str)
|
|
223
|
+ assert isinstance(elem['workspace_id'], int)
|
|
224
|
+
|
|
225
|
+ assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
|
|
226
|
+ assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
|
|
227
|
+
|
|
228
|
+ params = {
|
|
229
|
+ 'limit': 2,
|
|
230
|
+ 'before_datetime': secondly_created_but_not_commented.get_last_activity_date().strftime('%Y-%m-%dT%H:%M:%SZ'),
|
|
231
|
+ }
|
|
232
|
+ res = self.testapp.get(
|
|
233
|
+ '/api/v2/users/1/workspaces/{}/contents/recently_active'.format(workspace.workspace_id),
|
|
234
|
+ status=200,
|
|
235
|
+ params=params
|
|
236
|
+ )
|
|
237
|
+ res = res.json_body
|
|
238
|
+ assert len(res) == 2
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+ assert res[0]['content_id'] == firstly_created_but_recently_updated.content_id
|
|
242
|
+ assert res[1]['content_id'] == secondly_created_but_not_updated.content_id
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+class TestUserReadStatusEndpoint(FunctionalTest):
|
|
246
|
+ """
|
|
247
|
+ Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status
|
|
248
|
+ """
|
|
249
|
+ def test_api__get_read_status__ok__200__all(self):
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
253
|
+ admin = dbsession.query(models.User) \
|
|
254
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
255
|
+ .one()
|
|
256
|
+ workspace_api = WorkspaceApi(
|
|
257
|
+ current_user=admin,
|
|
258
|
+ session=dbsession,
|
|
259
|
+ config=self.app_config
|
|
260
|
+
|
|
261
|
+ )
|
|
262
|
+ workspace = WorkspaceApi(
|
|
263
|
+ current_user=admin,
|
|
264
|
+ session=dbsession,
|
|
265
|
+ config=self.app_config,
|
|
266
|
+ ).create_workspace(
|
|
267
|
+ 'test workspace',
|
|
268
|
+ save_now=True
|
|
269
|
+ )
|
|
270
|
+ workspace2 = WorkspaceApi(
|
|
271
|
+ current_user=admin,
|
|
272
|
+ session=dbsession,
|
|
273
|
+ config=self.app_config,
|
|
274
|
+ ).create_workspace(
|
|
275
|
+ 'test workspace2',
|
|
276
|
+ save_now=True
|
|
277
|
+ )
|
|
278
|
+
|
|
279
|
+ api = ContentApi(
|
|
280
|
+ current_user=admin,
|
|
281
|
+ session=dbsession,
|
|
282
|
+ config=self.app_config,
|
|
283
|
+ )
|
|
284
|
+ main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)
|
|
285
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
286
|
+
|
|
287
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
288
|
+ secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)
|
|
289
|
+
|
|
290
|
+ firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)
|
|
291
|
+ secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)
|
|
292
|
+ with new_revision(
|
|
293
|
+ session=dbsession,
|
|
294
|
+ tm=transaction.manager,
|
|
295
|
+ content=firstly_created_but_recently_updated,
|
|
296
|
+ ):
|
|
297
|
+ firstly_created_but_recently_updated.description = 'Just an update'
|
|
298
|
+ api.save(firstly_created_but_recently_updated)
|
|
299
|
+
|
|
300
|
+ firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)
|
|
301
|
+ secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)
|
|
302
|
+ comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)
|
|
303
|
+ content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)
|
|
304
|
+ dbsession.flush()
|
|
305
|
+ transaction.commit()
|
|
306
|
+
|
|
307
|
+ self.testapp.authorization = (
|
|
308
|
+ 'Basic',
|
|
309
|
+ (
|
|
310
|
+ 'admin@admin.admin',
|
|
311
|
+ 'admin@admin.admin'
|
|
312
|
+ )
|
|
313
|
+ )
|
|
314
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
315
|
+ res = res.json_body
|
|
316
|
+ assert len(res) == 7
|
|
317
|
+ for elem in res:
|
|
318
|
+ assert isinstance(elem['content_id'], int)
|
|
319
|
+ assert isinstance(elem['read_by_user'], bool)
|
|
320
|
+
|
|
321
|
+ assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
|
|
322
|
+ assert res[1]['content_id'] == secondly_created_but_not_commented.content_id
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+ assert res[2]['content_id'] == firstly_created_but_recently_updated.content_id
|
|
326
|
+ assert res[3]['content_id'] == secondly_created_but_not_updated.content_id
|
|
327
|
+
|
|
328
|
+ assert res[4]['content_id'] == secondly_created.content_id
|
|
329
|
+ assert res[5]['content_id'] == firstly_created.content_id
|
|
330
|
+
|
|
331
|
+ assert res[6]['content_id'] == main_folder.content_id
|
|
332
|
+
|
|
333
|
+ def test_api__get_read_status__ok__200__nominal_case(self):
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
337
|
+ admin = dbsession.query(models.User) \
|
|
338
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
339
|
+ .one()
|
|
340
|
+ workspace_api = WorkspaceApi(
|
|
341
|
+ current_user=admin,
|
|
342
|
+ session=dbsession,
|
|
343
|
+ config=self.app_config
|
|
344
|
+
|
|
345
|
+ )
|
|
346
|
+ workspace = WorkspaceApi(
|
|
347
|
+ current_user=admin,
|
|
348
|
+ session=dbsession,
|
|
349
|
+ config=self.app_config,
|
|
350
|
+ ).create_workspace(
|
|
351
|
+ 'test workspace',
|
|
352
|
+ save_now=True
|
|
353
|
+ )
|
|
354
|
+ workspace2 = WorkspaceApi(
|
|
355
|
+ current_user=admin,
|
|
356
|
+ session=dbsession,
|
|
357
|
+ config=self.app_config,
|
|
358
|
+ ).create_workspace(
|
|
359
|
+ 'test workspace2',
|
|
360
|
+ save_now=True
|
|
361
|
+ )
|
|
362
|
+
|
|
363
|
+ api = ContentApi(
|
|
364
|
+ current_user=admin,
|
|
365
|
+ session=dbsession,
|
|
366
|
+ config=self.app_config,
|
|
367
|
+ )
|
|
368
|
+ main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)
|
|
369
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
370
|
+
|
|
371
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
372
|
+ secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)
|
|
373
|
+
|
|
374
|
+ firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)
|
|
375
|
+ secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)
|
|
376
|
+ with new_revision(
|
|
377
|
+ session=dbsession,
|
|
378
|
+ tm=transaction.manager,
|
|
379
|
+ content=firstly_created_but_recently_updated,
|
|
380
|
+ ):
|
|
381
|
+ firstly_created_but_recently_updated.description = 'Just an update'
|
|
382
|
+ api.save(firstly_created_but_recently_updated)
|
|
383
|
+
|
|
384
|
+ firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)
|
|
385
|
+ secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)
|
|
386
|
+ comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)
|
|
387
|
+ content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)
|
|
388
|
+ dbsession.flush()
|
|
389
|
+ transaction.commit()
|
|
390
|
+
|
|
391
|
+ self.testapp.authorization = (
|
|
392
|
+ 'Basic',
|
|
393
|
+ (
|
|
394
|
+ 'admin@admin.admin',
|
|
395
|
+ 'admin@admin.admin'
|
|
396
|
+ )
|
|
397
|
+ )
|
|
398
|
+ selected_contents_id = [
|
|
399
|
+ firstly_created_but_recently_commented.content_id,
|
|
400
|
+ firstly_created_but_recently_updated.content_id,
|
|
401
|
+ firstly_created.content_id,
|
|
402
|
+ main_folder.content_id,
|
|
403
|
+ ]
|
|
404
|
+ url = '/api/v2/users/1/workspaces/{workspace_id}/contents/read_status?contents_ids={cid1}&contents_ids={cid2}&contents_ids={cid3}&contents_ids={cid4}'.format(
|
|
405
|
+ workspace_id=workspace.workspace_id,
|
|
406
|
+ cid1=selected_contents_id[0],
|
|
407
|
+ cid2=selected_contents_id[1],
|
|
408
|
+ cid3=selected_contents_id[2],
|
|
409
|
+ cid4=selected_contents_id[3],
|
|
410
|
+ )
|
|
411
|
+ res = self.testapp.get(
|
|
412
|
+ url=url,
|
|
413
|
+ status=200,
|
|
414
|
+ )
|
|
415
|
+ res = res.json_body
|
|
416
|
+ assert len(res) == 4
|
|
417
|
+ for elem in res:
|
|
418
|
+ assert isinstance(elem['content_id'], int)
|
|
419
|
+ assert isinstance(elem['read_by_user'], bool)
|
|
420
|
+
|
|
421
|
+ assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+ assert res[1]['content_id'] == firstly_created_but_recently_updated.content_id
|
|
425
|
+
|
|
426
|
+ assert res[2]['content_id'] == firstly_created.content_id
|
|
427
|
+
|
|
428
|
+ assert res[3]['content_id'] == main_folder.content_id
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+class TestUserSetContentAsRead(FunctionalTest):
|
|
432
|
+ """
|
|
433
|
+ Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read
|
|
434
|
+ """
|
|
435
|
+ def test_api_set_content_as_read__ok__200__nominal_case(self):
|
|
436
|
+
|
|
437
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
438
|
+ admin = dbsession.query(models.User) \
|
|
439
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
440
|
+ .one()
|
|
441
|
+ workspace_api = WorkspaceApi(
|
|
442
|
+ current_user=admin,
|
|
443
|
+ session=dbsession,
|
|
444
|
+ config=self.app_config
|
|
445
|
+
|
|
446
|
+ )
|
|
447
|
+ workspace = WorkspaceApi(
|
|
448
|
+ current_user=admin,
|
|
449
|
+ session=dbsession,
|
|
450
|
+ config=self.app_config,
|
|
451
|
+ ).create_workspace(
|
|
452
|
+ 'test workspace',
|
|
453
|
+ save_now=True
|
|
454
|
+ )
|
|
455
|
+ api = ContentApi(
|
|
456
|
+ current_user=admin,
|
|
457
|
+ session=dbsession,
|
|
458
|
+ config=self.app_config,
|
|
459
|
+ )
|
|
460
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
461
|
+
|
|
462
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
463
|
+ api.mark_unread(firstly_created)
|
|
464
|
+ dbsession.flush()
|
|
465
|
+ transaction.commit()
|
|
466
|
+
|
|
467
|
+ self.testapp.authorization = (
|
|
468
|
+ 'Basic',
|
|
469
|
+ (
|
|
470
|
+ 'admin@admin.admin',
|
|
471
|
+ 'admin@admin.admin'
|
|
472
|
+ )
|
|
473
|
+ )
|
|
474
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
475
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
476
|
+ assert res.json_body[0]['read_by_user'] is False
|
|
477
|
+ self.testapp.put(
|
|
478
|
+ '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read'.format(
|
|
479
|
+ workspace_id=workspace.workspace_id,
|
|
480
|
+ content_id=firstly_created.content_id,
|
|
481
|
+ user_id=admin.user_id,
|
|
482
|
+ )
|
|
483
|
+ )
|
|
484
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
485
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
486
|
+ assert res.json_body[0]['read_by_user'] is True
|
|
487
|
+
|
|
488
|
+ def test_api_set_content_as_read__ok__200__with_comments(self):
|
|
489
|
+
|
|
490
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
491
|
+ admin = dbsession.query(models.User) \
|
|
492
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
493
|
+ .one()
|
|
494
|
+ workspace_api = WorkspaceApi(
|
|
495
|
+ current_user=admin,
|
|
496
|
+ session=dbsession,
|
|
497
|
+ config=self.app_config
|
|
498
|
+
|
|
499
|
+ )
|
|
500
|
+ workspace = WorkspaceApi(
|
|
501
|
+ current_user=admin,
|
|
502
|
+ session=dbsession,
|
|
503
|
+ config=self.app_config,
|
|
504
|
+ ).create_workspace(
|
|
505
|
+ 'test workspace',
|
|
506
|
+ save_now=True
|
|
507
|
+ )
|
|
508
|
+ api = ContentApi(
|
|
509
|
+ current_user=admin,
|
|
510
|
+ session=dbsession,
|
|
511
|
+ config=self.app_config,
|
|
512
|
+ )
|
|
513
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
514
|
+
|
|
515
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
516
|
+ comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)
|
|
517
|
+ api.mark_unread(firstly_created)
|
|
518
|
+ api.mark_unread(comments)
|
|
519
|
+ dbsession.flush()
|
|
520
|
+ transaction.commit()
|
|
521
|
+
|
|
522
|
+ self.testapp.authorization = (
|
|
523
|
+ 'Basic',
|
|
524
|
+ (
|
|
525
|
+ 'admin@admin.admin',
|
|
526
|
+ 'admin@admin.admin'
|
|
527
|
+ )
|
|
528
|
+ )
|
|
529
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
530
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
531
|
+ assert res.json_body[0]['read_by_user'] is False
|
|
532
|
+ self.testapp.put(
|
|
533
|
+ '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read'.format(
|
|
534
|
+ workspace_id=workspace.workspace_id,
|
|
535
|
+ content_id=firstly_created.content_id,
|
|
536
|
+ user_id=admin.user_id,
|
|
537
|
+ )
|
|
538
|
+ )
|
|
539
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
540
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
541
|
+ assert res.json_body[0]['read_by_user'] is True
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+ assert comments.has_new_information_for(admin) is False
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+class TestUserSetContentAsUnread(FunctionalTest):
|
|
548
|
+ """
|
|
549
|
+ Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread
|
|
550
|
+ """
|
|
551
|
+ def test_api_set_content_as_unread__ok__200__nominal_case(self):
|
|
552
|
+
|
|
553
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
554
|
+ admin = dbsession.query(models.User) \
|
|
555
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
556
|
+ .one()
|
|
557
|
+ workspace_api = WorkspaceApi(
|
|
558
|
+ current_user=admin,
|
|
559
|
+ session=dbsession,
|
|
560
|
+ config=self.app_config
|
|
561
|
+
|
|
562
|
+ )
|
|
563
|
+ workspace = WorkspaceApi(
|
|
564
|
+ current_user=admin,
|
|
565
|
+ session=dbsession,
|
|
566
|
+ config=self.app_config,
|
|
567
|
+ ).create_workspace(
|
|
568
|
+ 'test workspace',
|
|
569
|
+ save_now=True
|
|
570
|
+ )
|
|
571
|
+ api = ContentApi(
|
|
572
|
+ current_user=admin,
|
|
573
|
+ session=dbsession,
|
|
574
|
+ config=self.app_config,
|
|
575
|
+ )
|
|
576
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
577
|
+
|
|
578
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
579
|
+ api.mark_read(firstly_created)
|
|
580
|
+ dbsession.flush()
|
|
581
|
+ transaction.commit()
|
|
582
|
+
|
|
583
|
+ self.testapp.authorization = (
|
|
584
|
+ 'Basic',
|
|
585
|
+ (
|
|
586
|
+ 'admin@admin.admin',
|
|
587
|
+ 'admin@admin.admin'
|
|
588
|
+ )
|
|
589
|
+ )
|
|
590
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
591
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
592
|
+ assert res.json_body[0]['read_by_user'] is True
|
|
593
|
+ self.testapp.put(
|
|
594
|
+ '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread'.format(
|
|
595
|
+ workspace_id=workspace.workspace_id,
|
|
596
|
+ content_id=firstly_created.content_id,
|
|
597
|
+ user_id=admin.user_id,
|
|
598
|
+ )
|
|
599
|
+ )
|
|
600
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
601
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
602
|
+ assert res.json_body[0]['read_by_user'] is False
|
|
603
|
+
|
|
604
|
+ def test_api_set_content_as_unread__ok__200__with_comments(self):
|
|
605
|
+
|
|
606
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
607
|
+ admin = dbsession.query(models.User) \
|
|
608
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
609
|
+ .one()
|
|
610
|
+ workspace_api = WorkspaceApi(
|
|
611
|
+ current_user=admin,
|
|
612
|
+ session=dbsession,
|
|
613
|
+ config=self.app_config
|
|
614
|
+
|
|
615
|
+ )
|
|
616
|
+ workspace = WorkspaceApi(
|
|
617
|
+ current_user=admin,
|
|
618
|
+ session=dbsession,
|
|
619
|
+ config=self.app_config,
|
|
620
|
+ ).create_workspace(
|
|
621
|
+ 'test workspace',
|
|
622
|
+ save_now=True
|
|
623
|
+ )
|
|
624
|
+ api = ContentApi(
|
|
625
|
+ current_user=admin,
|
|
626
|
+ session=dbsession,
|
|
627
|
+ config=self.app_config,
|
|
628
|
+ )
|
|
629
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
630
|
+
|
|
631
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
632
|
+ comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)
|
|
633
|
+ api.mark_read(firstly_created)
|
|
634
|
+ api.mark_read(comments)
|
|
635
|
+ dbsession.flush()
|
|
636
|
+ transaction.commit()
|
|
637
|
+
|
|
638
|
+ self.testapp.authorization = (
|
|
639
|
+ 'Basic',
|
|
640
|
+ (
|
|
641
|
+ 'admin@admin.admin',
|
|
642
|
+ 'admin@admin.admin'
|
|
643
|
+ )
|
|
644
|
+ )
|
|
645
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
646
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
647
|
+ assert res.json_body[0]['read_by_user'] is True
|
|
648
|
+ self.testapp.put(
|
|
649
|
+ '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread'.format(
|
|
650
|
+ workspace_id=workspace.workspace_id,
|
|
651
|
+ content_id=firstly_created.content_id,
|
|
652
|
+ user_id=admin.user_id,
|
|
653
|
+ )
|
|
654
|
+ )
|
|
655
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
656
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
657
|
+ assert res.json_body[0]['read_by_user'] is False
|
|
658
|
+
|
|
659
|
+ assert comments.has_new_information_for(admin) is True
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+class TestUserSetWorkspaceAsRead(FunctionalTest):
|
|
663
|
+ """
|
|
664
|
+ Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/read
|
|
665
|
+ """
|
|
666
|
+ def test_api_set_content_as_read__ok__200__nominal_case(self):
|
|
667
|
+
|
|
668
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
669
|
+ admin = dbsession.query(models.User) \
|
|
670
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
671
|
+ .one()
|
|
672
|
+ workspace_api = WorkspaceApi(
|
|
673
|
+ current_user=admin,
|
|
674
|
+ session=dbsession,
|
|
675
|
+ config=self.app_config
|
|
676
|
+
|
|
677
|
+ )
|
|
678
|
+ workspace = WorkspaceApi(
|
|
679
|
+ current_user=admin,
|
|
680
|
+ session=dbsession,
|
|
681
|
+ config=self.app_config,
|
|
682
|
+ ).create_workspace(
|
|
683
|
+ 'test workspace',
|
|
684
|
+ save_now=True
|
|
685
|
+ )
|
|
686
|
+ api = ContentApi(
|
|
687
|
+ current_user=admin,
|
|
688
|
+ session=dbsession,
|
|
689
|
+ config=self.app_config,
|
|
690
|
+ )
|
|
691
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)
|
|
692
|
+
|
|
693
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)
|
|
694
|
+ api.mark_unread(main_folder)
|
|
695
|
+ api.mark_unread(firstly_created)
|
|
696
|
+ dbsession.flush()
|
|
697
|
+ transaction.commit()
|
|
698
|
+
|
|
699
|
+ self.testapp.authorization = (
|
|
700
|
+ 'Basic',
|
|
701
|
+ (
|
|
702
|
+ 'admin@admin.admin',
|
|
703
|
+ 'admin@admin.admin'
|
|
704
|
+ )
|
|
705
|
+ )
|
|
706
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
707
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
708
|
+ assert res.json_body[0]['read_by_user'] is False
|
|
709
|
+ assert res.json_body[1]['content_id'] == main_folder.content_id
|
|
710
|
+ assert res.json_body[1]['read_by_user'] is False
|
|
711
|
+ self.testapp.put(
|
|
712
|
+ '/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format(
|
|
713
|
+ workspace_id=workspace.workspace_id,
|
|
714
|
+ content_id=firstly_created.content_id,
|
|
715
|
+ user_id=admin.user_id,
|
|
716
|
+ )
|
|
717
|
+ )
|
|
718
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200)
|
|
719
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
720
|
+ assert res.json_body[0]['read_by_user'] is True
|
|
721
|
+ assert res.json_body[1]['content_id'] == main_folder.content_id
|
|
722
|
+ assert res.json_body[1]['read_by_user'] is True
|
|
723
|
+
|
|
724
|
+
|
10
|
725
|
class TestUserWorkspaceEndpoint(FunctionalTest):
|
11
|
|
-
|
12
|
726
|
"""
|
13
|
727
|
Tests for /api/v2/users/{user_id}/workspaces
|
14
|
728
|
"""
|