@@ 249-373 (lines=125) @@ | ||
246 | workspace_id=workspace.workspace_id |
|
247 | ), status=400) |
|
248 | ||
249 | def test_api__get_recently_active_content__ok__200__user_itself(self): |
|
250 | ||
251 | # init DB |
|
252 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
253 | admin = dbsession.query(models.User) \ |
|
254 | .filter(models.User.email == '[email protected]') \ |
|
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 | uapi = UserApi( |
|
280 | current_user=admin, |
|
281 | session=dbsession, |
|
282 | config=self.app_config, |
|
283 | ) |
|
284 | gapi = GroupApi( |
|
285 | current_user=admin, |
|
286 | session=dbsession, |
|
287 | config=self.app_config, |
|
288 | ) |
|
289 | groups = [gapi.get_one_with_name('users')] |
|
290 | test_user = uapi.create_user( |
|
291 | email='[email protected]', |
|
292 | password='pass', |
|
293 | name='bob', |
|
294 | groups=groups, |
|
295 | timezone='Europe/Paris', |
|
296 | lang='fr', |
|
297 | do_save=True, |
|
298 | do_notify=False, |
|
299 | ) |
|
300 | rapi = RoleApi( |
|
301 | current_user=admin, |
|
302 | session=dbsession, |
|
303 | config=self.app_config, |
|
304 | ) |
|
305 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
306 | api = ContentApi( |
|
307 | current_user=admin, |
|
308 | session=dbsession, |
|
309 | config=self.app_config, |
|
310 | ) |
|
311 | main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True) # nopep8 |
|
312 | main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
313 | # creation order test |
|
314 | firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
315 | secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
|
316 | # update order test |
|
317 | firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
|
318 | secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
|
319 | with new_revision( |
|
320 | session=dbsession, |
|
321 | tm=transaction.manager, |
|
322 | content=firstly_created_but_recently_updated, |
|
323 | ): |
|
324 | firstly_created_but_recently_updated.description = 'Just an update' |
|
325 | api.save(firstly_created_but_recently_updated) |
|
326 | # comment change order |
|
327 | firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
|
328 | secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
|
329 | comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
|
330 | content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True) # nopep8 |
|
331 | dbsession.flush() |
|
332 | transaction.commit() |
|
333 | ||
334 | self.testapp.authorization = ( |
|
335 | 'Basic', |
|
336 | ( |
|
337 | '[email protected]', |
|
338 | 'pass' |
|
339 | ) |
|
340 | ) |
|
341 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/recently_active'.format( # nopep8 |
|
342 | user_id=test_user.user_id, |
|
343 | workspace_id=workspace.workspace_id |
|
344 | ), status=200) |
|
345 | res = res.json_body |
|
346 | assert len(res) == 7 |
|
347 | for elem in res: |
|
348 | assert isinstance(elem['content_id'], int) |
|
349 | assert isinstance(elem['content_type'], str) |
|
350 | assert elem['content_type'] != 'comments' |
|
351 | assert isinstance(elem['is_archived'], bool) |
|
352 | assert isinstance(elem['is_deleted'], bool) |
|
353 | assert isinstance(elem['label'], str) |
|
354 | assert isinstance(elem['parent_id'], int) or elem['parent_id'] is None |
|
355 | assert isinstance(elem['show_in_ui'], bool) |
|
356 | assert isinstance(elem['slug'], str) |
|
357 | assert isinstance(elem['status'], str) |
|
358 | assert isinstance(elem['sub_content_types'], list) |
|
359 | for sub_content_type in elem['sub_content_types']: |
|
360 | assert isinstance(sub_content_type, str) |
|
361 | assert isinstance(elem['workspace_id'], int) |
|
362 | # comment is newest than page2 |
|
363 | assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id |
|
364 | assert res[1]['content_id'] == secondly_created_but_not_commented.content_id |
|
365 | # last updated content is newer than other one despite creation |
|
366 | # of the other is more recent |
|
367 | assert res[2]['content_id'] == firstly_created_but_recently_updated.content_id |
|
368 | assert res[3]['content_id'] == secondly_created_but_not_updated.content_id |
|
369 | # creation order is inverted here as last created is last active |
|
370 | assert res[4]['content_id'] == secondly_created.content_id |
|
371 | assert res[5]['content_id'] == firstly_created.content_id |
|
372 | # folder subcontent modification does not change folder order |
|
373 | assert res[6]['content_id'] == main_folder.content_id |
|
374 | ||
375 | def test_api__get_recently_active_content__ok__200__other_user(self): |
|
376 | ||
@@ 33-156 (lines=124) @@ | ||
30 | """ |
|
31 | fixtures = [BaseFixture] |
|
32 | ||
33 | def test_api__get_recently_active_content__ok__200__admin(self): |
|
34 | ||
35 | # init DB |
|
36 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
37 | admin = dbsession.query(models.User) \ |
|
38 | .filter(models.User.email == '[email protected]') \ |
|
39 | .one() |
|
40 | workspace_api = WorkspaceApi( |
|
41 | current_user=admin, |
|
42 | session=dbsession, |
|
43 | config=self.app_config |
|
44 | ||
45 | ) |
|
46 | workspace = WorkspaceApi( |
|
47 | current_user=admin, |
|
48 | session=dbsession, |
|
49 | config=self.app_config, |
|
50 | ).create_workspace( |
|
51 | 'test workspace', |
|
52 | save_now=True |
|
53 | ) |
|
54 | workspace2 = WorkspaceApi( |
|
55 | current_user=admin, |
|
56 | session=dbsession, |
|
57 | config=self.app_config, |
|
58 | ).create_workspace( |
|
59 | 'test workspace2', |
|
60 | save_now=True |
|
61 | ) |
|
62 | uapi = UserApi( |
|
63 | current_user=admin, |
|
64 | session=dbsession, |
|
65 | config=self.app_config, |
|
66 | ) |
|
67 | gapi = GroupApi( |
|
68 | current_user=admin, |
|
69 | session=dbsession, |
|
70 | config=self.app_config, |
|
71 | ) |
|
72 | groups = [gapi.get_one_with_name('users')] |
|
73 | test_user = uapi.create_user( |
|
74 | email='[email protected]', |
|
75 | password='pass', |
|
76 | name='bob', |
|
77 | groups=groups, |
|
78 | timezone='Europe/Paris', |
|
79 | lang='fr', |
|
80 | do_save=True, |
|
81 | do_notify=False, |
|
82 | ) |
|
83 | rapi = RoleApi( |
|
84 | current_user=admin, |
|
85 | session=dbsession, |
|
86 | config=self.app_config, |
|
87 | ) |
|
88 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
89 | api = ContentApi( |
|
90 | current_user=admin, |
|
91 | session=dbsession, |
|
92 | config=self.app_config, |
|
93 | ) |
|
94 | main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True) # nopep8 |
|
95 | main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
96 | # creation order test |
|
97 | firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
98 | secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True) # nopep8 |
|
99 | # update order test |
|
100 | firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True) # nopep8 |
|
101 | secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True) # nopep8 |
|
102 | with new_revision( |
|
103 | session=dbsession, |
|
104 | tm=transaction.manager, |
|
105 | content=firstly_created_but_recently_updated, |
|
106 | ): |
|
107 | firstly_created_but_recently_updated.description = 'Just an update' |
|
108 | api.save(firstly_created_but_recently_updated) |
|
109 | # comment change order |
|
110 | firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True) # nopep8 |
|
111 | secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8 |
|
112 | comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8 |
|
113 | content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True) # nopep8 |
|
114 | dbsession.flush() |
|
115 | transaction.commit() |
|
116 | ||
117 | self.testapp.authorization = ( |
|
118 | 'Basic', |
|
119 | ( |
|
120 | '[email protected]', |
|
121 | '[email protected]' |
|
122 | ) |
|
123 | ) |
|
124 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/recently_active'.format( # nopep8 |
|
125 | user_id=test_user.user_id, |
|
126 | workspace_id=workspace.workspace_id |
|
127 | ), status=200) |
|
128 | res = res.json_body |
|
129 | assert len(res) == 7 |
|
130 | for elem in res: |
|
131 | assert isinstance(elem['content_id'], int) |
|
132 | assert isinstance(elem['content_type'], str) |
|
133 | assert elem['content_type'] != 'comments' |
|
134 | assert isinstance(elem['is_archived'], bool) |
|
135 | assert isinstance(elem['is_deleted'], bool) |
|
136 | assert isinstance(elem['label'], str) |
|
137 | assert isinstance(elem['parent_id'], int) or elem['parent_id'] is None |
|
138 | assert isinstance(elem['show_in_ui'], bool) |
|
139 | assert isinstance(elem['slug'], str) |
|
140 | assert isinstance(elem['status'], str) |
|
141 | assert isinstance(elem['sub_content_types'], list) |
|
142 | for sub_content_type in elem['sub_content_types']: |
|
143 | assert isinstance(sub_content_type, str) |
|
144 | assert isinstance(elem['workspace_id'], int) |
|
145 | # comment is newest than page2 |
|
146 | assert res[0]['content_id'] == firstly_created_but_recently_commented.content_id |
|
147 | assert res[1]['content_id'] == secondly_created_but_not_commented.content_id |
|
148 | # last updated content is newer than other one despite creation |
|
149 | # of the other is more recent |
|
150 | assert res[2]['content_id'] == firstly_created_but_recently_updated.content_id |
|
151 | assert res[3]['content_id'] == secondly_created_but_not_updated.content_id |
|
152 | # creation order is inverted here as last created is last active |
|
153 | assert res[4]['content_id'] == secondly_created.content_id |
|
154 | assert res[5]['content_id'] == firstly_created.content_id |
|
155 | # folder subcontent modification does not change folder order |
|
156 | assert res[6]['content_id'] == main_folder.content_id |
|
157 | ||
158 | def test_api__get_recently_active_content__err__400__no_access_to_workspace(self): |
|
159 |