@@ 2234-2330 (lines=97) @@ | ||
2231 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
2232 | assert res.json_body[1]['read_by_user'] is True |
|
2233 | ||
2234 | def test_api_set_content_as_read__ok__200__user_itself(self): |
|
2235 | # init DB |
|
2236 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2237 | admin = dbsession.query(models.User) \ |
|
2238 | .filter(models.User.email == '[email protected]') \ |
|
2239 | .one() |
|
2240 | workspace_api = WorkspaceApi( |
|
2241 | current_user=admin, |
|
2242 | session=dbsession, |
|
2243 | config=self.app_config |
|
2244 | ||
2245 | ) |
|
2246 | workspace = WorkspaceApi( |
|
2247 | current_user=admin, |
|
2248 | session=dbsession, |
|
2249 | config=self.app_config, |
|
2250 | ).create_workspace( |
|
2251 | 'test workspace', |
|
2252 | save_now=True |
|
2253 | ) |
|
2254 | uapi = UserApi( |
|
2255 | current_user=admin, |
|
2256 | session=dbsession, |
|
2257 | config=self.app_config, |
|
2258 | ) |
|
2259 | gapi = GroupApi( |
|
2260 | current_user=admin, |
|
2261 | session=dbsession, |
|
2262 | config=self.app_config, |
|
2263 | ) |
|
2264 | groups = [gapi.get_one_with_name('users')] |
|
2265 | test_user = uapi.create_user( |
|
2266 | email='[email protected]', |
|
2267 | password='pass', |
|
2268 | name='bob', |
|
2269 | groups=groups, |
|
2270 | timezone='Europe/Paris', |
|
2271 | lang='fr', |
|
2272 | do_save=True, |
|
2273 | do_notify=False, |
|
2274 | ) |
|
2275 | rapi = RoleApi( |
|
2276 | current_user=admin, |
|
2277 | session=dbsession, |
|
2278 | config=self.app_config, |
|
2279 | ) |
|
2280 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
2281 | api = ContentApi( |
|
2282 | current_user=admin, |
|
2283 | session=dbsession, |
|
2284 | config=self.app_config, |
|
2285 | ) |
|
2286 | api2 = ContentApi( |
|
2287 | current_user=test_user, |
|
2288 | session=dbsession, |
|
2289 | config=self.app_config, |
|
2290 | ) |
|
2291 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
2292 | # creation order test |
|
2293 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
2294 | api.mark_unread(main_folder) |
|
2295 | api.mark_unread(firstly_created) |
|
2296 | api2.mark_unread(main_folder) |
|
2297 | api2.mark_unread(firstly_created) |
|
2298 | dbsession.flush() |
|
2299 | transaction.commit() |
|
2300 | ||
2301 | self.testapp.authorization = ( |
|
2302 | 'Basic', |
|
2303 | ( |
|
2304 | '[email protected]', |
|
2305 | 'pass' |
|
2306 | ) |
|
2307 | ) |
|
2308 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
2309 | user_id=test_user.user_id, |
|
2310 | workspace_id=workspace.workspace_id |
|
2311 | ), status=200) |
|
2312 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
2313 | assert res.json_body[0]['read_by_user'] is False |
|
2314 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
2315 | assert res.json_body[1]['read_by_user'] is False |
|
2316 | self.testapp.put( |
|
2317 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format( # nopep8 |
|
2318 | workspace_id=workspace.workspace_id, |
|
2319 | content_id=firstly_created.content_id, |
|
2320 | user_id=test_user.user_id, |
|
2321 | ) |
|
2322 | ) |
|
2323 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
2324 | user_id=test_user.user_id, |
|
2325 | workspace_id=workspace.workspace_id |
|
2326 | ), status=200) |
|
2327 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
2328 | assert res.json_body[0]['read_by_user'] is True |
|
2329 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
2330 | assert res.json_body[1]['read_by_user'] is True |
|
2331 | ||
2332 | def test_api_set_content_as_read__err__403__other_user(self): |
|
2333 | # init DB |
|
@@ 2136-2232 (lines=97) @@ | ||
2133 | """ |
|
2134 | Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/read |
|
2135 | """ |
|
2136 | def test_api_set_content_as_read__ok__200__admin(self): |
|
2137 | # init DB |
|
2138 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2139 | admin = dbsession.query(models.User) \ |
|
2140 | .filter(models.User.email == '[email protected]') \ |
|
2141 | .one() |
|
2142 | workspace_api = WorkspaceApi( |
|
2143 | current_user=admin, |
|
2144 | session=dbsession, |
|
2145 | config=self.app_config |
|
2146 | ||
2147 | ) |
|
2148 | workspace = WorkspaceApi( |
|
2149 | current_user=admin, |
|
2150 | session=dbsession, |
|
2151 | config=self.app_config, |
|
2152 | ).create_workspace( |
|
2153 | 'test workspace', |
|
2154 | save_now=True |
|
2155 | ) |
|
2156 | uapi = UserApi( |
|
2157 | current_user=admin, |
|
2158 | session=dbsession, |
|
2159 | config=self.app_config, |
|
2160 | ) |
|
2161 | gapi = GroupApi( |
|
2162 | current_user=admin, |
|
2163 | session=dbsession, |
|
2164 | config=self.app_config, |
|
2165 | ) |
|
2166 | groups = [gapi.get_one_with_name('users')] |
|
2167 | test_user = uapi.create_user( |
|
2168 | email='[email protected]', |
|
2169 | password='pass', |
|
2170 | name='bob', |
|
2171 | groups=groups, |
|
2172 | timezone='Europe/Paris', |
|
2173 | lang='fr', |
|
2174 | do_save=True, |
|
2175 | do_notify=False, |
|
2176 | ) |
|
2177 | rapi = RoleApi( |
|
2178 | current_user=admin, |
|
2179 | session=dbsession, |
|
2180 | config=self.app_config, |
|
2181 | ) |
|
2182 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
2183 | api = ContentApi( |
|
2184 | current_user=admin, |
|
2185 | session=dbsession, |
|
2186 | config=self.app_config, |
|
2187 | ) |
|
2188 | api2 = ContentApi( |
|
2189 | current_user=test_user, |
|
2190 | session=dbsession, |
|
2191 | config=self.app_config, |
|
2192 | ) |
|
2193 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
2194 | # creation order test |
|
2195 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
2196 | api.mark_unread(main_folder) |
|
2197 | api.mark_unread(firstly_created) |
|
2198 | api2.mark_unread(main_folder) |
|
2199 | api2.mark_unread(firstly_created) |
|
2200 | dbsession.flush() |
|
2201 | transaction.commit() |
|
2202 | ||
2203 | self.testapp.authorization = ( |
|
2204 | 'Basic', |
|
2205 | ( |
|
2206 | '[email protected]', |
|
2207 | '[email protected]' |
|
2208 | ) |
|
2209 | ) |
|
2210 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
2211 | user_id=test_user.user_id, |
|
2212 | workspace_id=workspace.workspace_id |
|
2213 | ), status=200) |
|
2214 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
2215 | assert res.json_body[0]['read_by_user'] is False |
|
2216 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
2217 | assert res.json_body[1]['read_by_user'] is False |
|
2218 | self.testapp.put( |
|
2219 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format( # nopep8 |
|
2220 | workspace_id=workspace.workspace_id, |
|
2221 | content_id=firstly_created.content_id, |
|
2222 | user_id=test_user.user_id, |
|
2223 | ) |
|
2224 | ) |
|
2225 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
2226 | user_id=test_user.user_id, |
|
2227 | workspace_id=workspace.workspace_id |
|
2228 | ), status=200) |
|
2229 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
2230 | assert res.json_body[0]['read_by_user'] is True |
|
2231 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
2232 | assert res.json_body[1]['read_by_user'] is True |
|
2233 | ||
2234 | def test_api_set_content_as_read__ok__200__user_itself(self): |
|
2235 | # init DB |
@@ 691-787 (lines=97) @@ | ||
688 | """ |
|
689 | Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/read |
|
690 | """ |
|
691 | def test_api_set_content_as_read__ok__200__nominal(self): |
|
692 | # init DB |
|
693 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
694 | admin = dbsession.query(models.User) \ |
|
695 | .filter(models.User.email == '[email protected]') \ |
|
696 | .one() |
|
697 | workspace_api = WorkspaceApi( |
|
698 | current_user=admin, |
|
699 | session=dbsession, |
|
700 | config=self.app_config |
|
701 | ||
702 | ) |
|
703 | workspace = WorkspaceApi( |
|
704 | current_user=admin, |
|
705 | session=dbsession, |
|
706 | config=self.app_config, |
|
707 | ).create_workspace( |
|
708 | 'test workspace', |
|
709 | save_now=True |
|
710 | ) |
|
711 | uapi = UserApi( |
|
712 | current_user=admin, |
|
713 | session=dbsession, |
|
714 | config=self.app_config, |
|
715 | ) |
|
716 | gapi = GroupApi( |
|
717 | current_user=admin, |
|
718 | session=dbsession, |
|
719 | config=self.app_config, |
|
720 | ) |
|
721 | groups = [gapi.get_one_with_name('users')] |
|
722 | test_user = uapi.create_user( |
|
723 | email='[email protected]', |
|
724 | password='pass', |
|
725 | name='bob', |
|
726 | groups=groups, |
|
727 | timezone='Europe/Paris', |
|
728 | lang='fr', |
|
729 | do_save=True, |
|
730 | do_notify=False, |
|
731 | ) |
|
732 | rapi = RoleApi( |
|
733 | current_user=admin, |
|
734 | session=dbsession, |
|
735 | config=self.app_config, |
|
736 | ) |
|
737 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
738 | api = ContentApi( |
|
739 | current_user=admin, |
|
740 | session=dbsession, |
|
741 | config=self.app_config, |
|
742 | ) |
|
743 | api2 = ContentApi( |
|
744 | current_user=test_user, |
|
745 | session=dbsession, |
|
746 | config=self.app_config, |
|
747 | ) |
|
748 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
749 | # creation order test |
|
750 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
751 | api.mark_unread(main_folder) |
|
752 | api.mark_unread(firstly_created) |
|
753 | api2.mark_unread(main_folder) |
|
754 | api2.mark_unread(firstly_created) |
|
755 | dbsession.flush() |
|
756 | transaction.commit() |
|
757 | ||
758 | self.testapp.authorization = ( |
|
759 | 'Basic', |
|
760 | ( |
|
761 | '[email protected]', |
|
762 | 'pass' |
|
763 | ) |
|
764 | ) |
|
765 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
766 | user_id=test_user.user_id, |
|
767 | workspace_id=workspace.workspace_id |
|
768 | ), status=200) |
|
769 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
770 | assert res.json_body[0]['read_by_user'] is False |
|
771 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
772 | assert res.json_body[1]['read_by_user'] is False |
|
773 | self.testapp.put( |
|
774 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format( # nopep8 |
|
775 | workspace_id=workspace.workspace_id, |
|
776 | content_id=firstly_created.content_id, |
|
777 | user_id=test_user.user_id, |
|
778 | ) |
|
779 | ) |
|
780 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
781 | user_id=test_user.user_id, |
|
782 | workspace_id=workspace.workspace_id |
|
783 | ), status=200) |
|
784 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
785 | assert res.json_body[0]['read_by_user'] is True |
|
786 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
787 | assert res.json_body[1]['read_by_user'] is True |
|
788 | ||
789 | class TestAccountEnableWorkspaceNotification(FunctionalTest): |
|
790 | """ |