@@ 480-583 (lines=104) @@ | ||
477 | assert res[3]['content_id'] == main_folder.content_id |
|
478 | ||
479 | ||
480 | class TestUserSetContentAsRead(FunctionalTest): |
|
481 | """ |
|
482 | Tests for /api/v2/users/me/workspaces/{workspace_id}/contents/{content_id}/read # nopep8 |
|
483 | """ |
|
484 | ||
485 | def test_api_set_content_as_read__ok__200__nominal(self): |
|
486 | # init DB |
|
487 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
488 | admin = dbsession.query(models.User) \ |
|
489 | .filter(models.User.email == '[email protected]') \ |
|
490 | .one() |
|
491 | workspace_api = WorkspaceApi( |
|
492 | current_user=admin, |
|
493 | session=dbsession, |
|
494 | config=self.app_config |
|
495 | ||
496 | ) |
|
497 | workspace = WorkspaceApi( |
|
498 | current_user=admin, |
|
499 | session=dbsession, |
|
500 | config=self.app_config, |
|
501 | ).create_workspace( |
|
502 | 'test workspace', |
|
503 | save_now=True |
|
504 | ) |
|
505 | uapi = UserApi( |
|
506 | current_user=admin, |
|
507 | session=dbsession, |
|
508 | config=self.app_config, |
|
509 | ) |
|
510 | gapi = GroupApi( |
|
511 | current_user=admin, |
|
512 | session=dbsession, |
|
513 | config=self.app_config, |
|
514 | ) |
|
515 | groups = [gapi.get_one_with_name('users')] |
|
516 | test_user = uapi.create_user( |
|
517 | email='[email protected]', |
|
518 | password='pass', |
|
519 | name='bob', |
|
520 | groups=groups, |
|
521 | timezone='Europe/Paris', |
|
522 | lang='fr', |
|
523 | do_save=True, |
|
524 | do_notify=False, |
|
525 | ) |
|
526 | rapi = RoleApi( |
|
527 | current_user=admin, |
|
528 | session=dbsession, |
|
529 | config=self.app_config, |
|
530 | ) |
|
531 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
532 | api = ContentApi( |
|
533 | current_user=admin, |
|
534 | session=dbsession, |
|
535 | config=self.app_config, |
|
536 | ) |
|
537 | api2 = ContentApi( |
|
538 | current_user=test_user, |
|
539 | session=dbsession, |
|
540 | config=self.app_config, |
|
541 | ) |
|
542 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
543 | # creation order test |
|
544 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
545 | api.mark_unread(firstly_created) |
|
546 | api2.mark_unread(firstly_created) |
|
547 | dbsession.flush() |
|
548 | transaction.commit() |
|
549 | ||
550 | self.testapp.authorization = ( |
|
551 | 'Basic', |
|
552 | ( |
|
553 | '[email protected]', |
|
554 | 'pass' |
|
555 | ) |
|
556 | ) |
|
557 | # before |
|
558 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
559 | user_id=test_user.user_id, |
|
560 | workspace_id=workspace.workspace_id |
|
561 | ), |
|
562 | status=200 |
|
563 | ) |
|
564 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
565 | assert res.json_body[0]['read_by_user'] is False |
|
566 | ||
567 | # read |
|
568 | self.testapp.put( |
|
569 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read'.format( # nopep8 |
|
570 | workspace_id=workspace.workspace_id, |
|
571 | content_id=firstly_created.content_id, |
|
572 | user_id=test_user.user_id, |
|
573 | ) |
|
574 | ) |
|
575 | # after |
|
576 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
577 | user_id=test_user.user_id, |
|
578 | workspace_id=workspace.workspace_id |
|
579 | ), |
|
580 | status=200 |
|
581 | ) |
|
582 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
583 | assert res.json_body[0]['read_by_user'] is True |
|
584 | ||
585 | class TestUserSetContentAsUnread(FunctionalTest): |
|
586 | """ |
|
@@ 585-683 (lines=99) @@ | ||
582 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
583 | assert res.json_body[0]['read_by_user'] is True |
|
584 | ||
585 | class TestUserSetContentAsUnread(FunctionalTest): |
|
586 | """ |
|
587 | Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread # nopep8 |
|
588 | """ |
|
589 | def test_api_set_content_as_unread__ok__200__nominal(self): |
|
590 | # init DB |
|
591 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
592 | admin = dbsession.query(models.User) \ |
|
593 | .filter(models.User.email == '[email protected]') \ |
|
594 | .one() |
|
595 | workspace_api = WorkspaceApi( |
|
596 | current_user=admin, |
|
597 | session=dbsession, |
|
598 | config=self.app_config |
|
599 | ||
600 | ) |
|
601 | workspace = WorkspaceApi( |
|
602 | current_user=admin, |
|
603 | session=dbsession, |
|
604 | config=self.app_config, |
|
605 | ).create_workspace( |
|
606 | 'test workspace', |
|
607 | save_now=True |
|
608 | ) |
|
609 | uapi = UserApi( |
|
610 | current_user=admin, |
|
611 | session=dbsession, |
|
612 | config=self.app_config, |
|
613 | ) |
|
614 | gapi = GroupApi( |
|
615 | current_user=admin, |
|
616 | session=dbsession, |
|
617 | config=self.app_config, |
|
618 | ) |
|
619 | groups = [gapi.get_one_with_name('users')] |
|
620 | test_user = uapi.create_user( |
|
621 | email='[email protected]', |
|
622 | password='pass', |
|
623 | name='bob', |
|
624 | groups=groups, |
|
625 | timezone='Europe/Paris', |
|
626 | lang='fr', |
|
627 | do_save=True, |
|
628 | do_notify=False, |
|
629 | ) |
|
630 | rapi = RoleApi( |
|
631 | current_user=admin, |
|
632 | session=dbsession, |
|
633 | config=self.app_config, |
|
634 | ) |
|
635 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
636 | api = ContentApi( |
|
637 | current_user=admin, |
|
638 | session=dbsession, |
|
639 | config=self.app_config, |
|
640 | ) |
|
641 | api2 = ContentApi( |
|
642 | current_user=test_user, |
|
643 | session=dbsession, |
|
644 | config=self.app_config, |
|
645 | ) |
|
646 | main_folder = api.create(content_type_list.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
|
647 | # creation order test |
|
648 | firstly_created = api.create(content_type_list.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
|
649 | api.mark_read(firstly_created) |
|
650 | api2.mark_read(firstly_created) |
|
651 | dbsession.flush() |
|
652 | transaction.commit() |
|
653 | ||
654 | self.testapp.authorization = ( |
|
655 | 'Basic', |
|
656 | ( |
|
657 | '[email protected]', |
|
658 | 'pass' |
|
659 | ) |
|
660 | ) |
|
661 | # before |
|
662 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
663 | user_id=test_user.user_id, |
|
664 | workspace_id=workspace.workspace_id |
|
665 | ), status=200) |
|
666 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
667 | assert res.json_body[0]['read_by_user'] is True |
|
668 | ||
669 | # unread |
|
670 | self.testapp.put( |
|
671 | '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread'.format( # nopep8 |
|
672 | workspace_id=workspace.workspace_id, |
|
673 | content_id=firstly_created.content_id, |
|
674 | user_id=test_user.user_id, |
|
675 | ) |
|
676 | ) |
|
677 | # after |
|
678 | res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
|
679 | user_id=test_user.user_id, |
|
680 | workspace_id=workspace.workspace_id |
|
681 | ), status=200) |
|
682 | assert res.json_body[0]['content_id'] == firstly_created.content_id |
|
683 | assert res.json_body[0]['read_by_user'] is False |
|
684 | ||
685 | ||
686 |