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