| @@ 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 | """ |
|
| @@ 2392-2488 (lines=97) @@ | ||
| 2389 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
| 2390 | assert res.json_body[1]['read_by_user'] is True |
|
| 2391 | ||
| 2392 | def test_api_set_content_as_read__ok__200__user_itself(self): |
|
| 2393 | # init DB |
|
| 2394 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2395 | admin = dbsession.query(models.User) \ |
|
| 2396 | .filter(models.User.email == '[email protected]') \ |
|
| 2397 | .one() |
|
| 2398 | workspace_api = WorkspaceApi( |
|
| 2399 | current_user=admin, |
|
| 2400 | session=dbsession, |
|
| 2401 | config=self.app_config |
|
| 2402 | ||
| 2403 | ) |
|
| 2404 | workspace = WorkspaceApi( |
|
| 2405 | current_user=admin, |
|
| 2406 | session=dbsession, |
|
| 2407 | config=self.app_config, |
|
| 2408 | ).create_workspace( |
|
| 2409 | 'test workspace', |
|
| 2410 | save_now=True |
|
| 2411 | ) |
|
| 2412 | uapi = UserApi( |
|
| 2413 | current_user=admin, |
|
| 2414 | session=dbsession, |
|
| 2415 | config=self.app_config, |
|
| 2416 | ) |
|
| 2417 | gapi = GroupApi( |
|
| 2418 | current_user=admin, |
|
| 2419 | session=dbsession, |
|
| 2420 | config=self.app_config, |
|
| 2421 | ) |
|
| 2422 | groups = [gapi.get_one_with_name('users')] |
|
| 2423 | test_user = uapi.create_user( |
|
| 2424 | email='[email protected]', |
|
| 2425 | password='pass', |
|
| 2426 | name='bob', |
|
| 2427 | groups=groups, |
|
| 2428 | timezone='Europe/Paris', |
|
| 2429 | lang='fr', |
|
| 2430 | do_save=True, |
|
| 2431 | do_notify=False, |
|
| 2432 | ) |
|
| 2433 | rapi = RoleApi( |
|
| 2434 | current_user=admin, |
|
| 2435 | session=dbsession, |
|
| 2436 | config=self.app_config, |
|
| 2437 | ) |
|
| 2438 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
| 2439 | api = ContentApi( |
|
| 2440 | current_user=admin, |
|
| 2441 | session=dbsession, |
|
| 2442 | config=self.app_config, |
|
| 2443 | ) |
|
| 2444 | api2 = ContentApi( |
|
| 2445 | current_user=test_user, |
|
| 2446 | session=dbsession, |
|
| 2447 | config=self.app_config, |
|
| 2448 | ) |
|
| 2449 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
| 2450 | # creation order test |
|
| 2451 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
| 2452 | api.mark_unread(main_folder) |
|
| 2453 | api.mark_unread(firstly_created) |
|
| 2454 | api2.mark_unread(main_folder) |
|
| 2455 | api2.mark_unread(firstly_created) |
|
| 2456 | dbsession.flush() |
|
| 2457 | transaction.commit() |
|
| 2458 | ||
| 2459 | self.testapp.authorization = ( |
|
| 2460 | 'Basic', |
|
| 2461 | ( |
|
| 2462 | '[email protected]', |
|
| 2463 | 'pass' |
|
| 2464 | ) |
|
| 2465 | ) |
|
| 2466 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
| 2467 | user_id=test_user.user_id, |
|
| 2468 | workspace_id=workspace.workspace_id |
|
| 2469 | ), status=200) |
|
| 2470 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
| 2471 | assert res.json_body[0]['read_by_user'] is False |
|
| 2472 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
| 2473 | assert res.json_body[1]['read_by_user'] is False |
|
| 2474 | self.testapp.put( |
|
| 2475 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format( # nopep8 |
|
| 2476 | workspace_id=workspace.workspace_id, |
|
| 2477 | content_id=firstly_created.content_id, |
|
| 2478 | user_id=test_user.user_id, |
|
| 2479 | ) |
|
| 2480 | ) |
|
| 2481 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
| 2482 | user_id=test_user.user_id, |
|
| 2483 | workspace_id=workspace.workspace_id |
|
| 2484 | ), status=200) |
|
| 2485 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
| 2486 | assert res.json_body[0]['read_by_user'] is True |
|
| 2487 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
| 2488 | assert res.json_body[1]['read_by_user'] is True |
|
| 2489 | ||
| 2490 | def test_api_set_content_as_read__err__403__other_user(self): |
|
| 2491 | # init DB |
|
| @@ 2294-2390 (lines=97) @@ | ||
| 2291 | """ |
|
| 2292 | Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/read |
|
| 2293 | """ |
|
| 2294 | def test_api_set_content_as_read__ok__200__admin(self): |
|
| 2295 | # init DB |
|
| 2296 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2297 | admin = dbsession.query(models.User) \ |
|
| 2298 | .filter(models.User.email == '[email protected]') \ |
|
| 2299 | .one() |
|
| 2300 | workspace_api = WorkspaceApi( |
|
| 2301 | current_user=admin, |
|
| 2302 | session=dbsession, |
|
| 2303 | config=self.app_config |
|
| 2304 | ||
| 2305 | ) |
|
| 2306 | workspace = WorkspaceApi( |
|
| 2307 | current_user=admin, |
|
| 2308 | session=dbsession, |
|
| 2309 | config=self.app_config, |
|
| 2310 | ).create_workspace( |
|
| 2311 | 'test workspace', |
|
| 2312 | save_now=True |
|
| 2313 | ) |
|
| 2314 | uapi = UserApi( |
|
| 2315 | current_user=admin, |
|
| 2316 | session=dbsession, |
|
| 2317 | config=self.app_config, |
|
| 2318 | ) |
|
| 2319 | gapi = GroupApi( |
|
| 2320 | current_user=admin, |
|
| 2321 | session=dbsession, |
|
| 2322 | config=self.app_config, |
|
| 2323 | ) |
|
| 2324 | groups = [gapi.get_one_with_name('users')] |
|
| 2325 | test_user = uapi.create_user( |
|
| 2326 | email='[email protected]', |
|
| 2327 | password='pass', |
|
| 2328 | name='bob', |
|
| 2329 | groups=groups, |
|
| 2330 | timezone='Europe/Paris', |
|
| 2331 | lang='fr', |
|
| 2332 | do_save=True, |
|
| 2333 | do_notify=False, |
|
| 2334 | ) |
|
| 2335 | rapi = RoleApi( |
|
| 2336 | current_user=admin, |
|
| 2337 | session=dbsession, |
|
| 2338 | config=self.app_config, |
|
| 2339 | ) |
|
| 2340 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
| 2341 | api = ContentApi( |
|
| 2342 | current_user=admin, |
|
| 2343 | session=dbsession, |
|
| 2344 | config=self.app_config, |
|
| 2345 | ) |
|
| 2346 | api2 = ContentApi( |
|
| 2347 | current_user=test_user, |
|
| 2348 | session=dbsession, |
|
| 2349 | config=self.app_config, |
|
| 2350 | ) |
|
| 2351 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
| 2352 | # creation order test |
|
| 2353 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
| 2354 | api.mark_unread(main_folder) |
|
| 2355 | api.mark_unread(firstly_created) |
|
| 2356 | api2.mark_unread(main_folder) |
|
| 2357 | api2.mark_unread(firstly_created) |
|
| 2358 | dbsession.flush() |
|
| 2359 | transaction.commit() |
|
| 2360 | ||
| 2361 | self.testapp.authorization = ( |
|
| 2362 | 'Basic', |
|
| 2363 | ( |
|
| 2364 | '[email protected]', |
|
| 2365 | '[email protected]' |
|
| 2366 | ) |
|
| 2367 | ) |
|
| 2368 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
| 2369 | user_id=test_user.user_id, |
|
| 2370 | workspace_id=workspace.workspace_id |
|
| 2371 | ), status=200) |
|
| 2372 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
| 2373 | assert res.json_body[0]['read_by_user'] is False |
|
| 2374 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
| 2375 | assert res.json_body[1]['read_by_user'] is False |
|
| 2376 | self.testapp.put( |
|
| 2377 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format( # nopep8 |
|
| 2378 | workspace_id=workspace.workspace_id, |
|
| 2379 | content_id=firstly_created.content_id, |
|
| 2380 | user_id=test_user.user_id, |
|
| 2381 | ) |
|
| 2382 | ) |
|
| 2383 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
| 2384 | user_id=test_user.user_id, |
|
| 2385 | workspace_id=workspace.workspace_id |
|
| 2386 | ), status=200) |
|
| 2387 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
| 2388 | assert res.json_body[0]['read_by_user'] is True |
|
| 2389 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
| 2390 | assert res.json_body[1]['read_by_user'] is True |
|
| 2391 | ||
| 2392 | def test_api_set_content_as_read__ok__200__user_itself(self): |
|
| 2393 | # init DB |
|