def setUp(self):
        """ Set up test environment
        """
        super(TestOpengeverSharingIntegration, self).setUp()
        self.grant('Manager')

        self.repo = create(Builder("repository"))
        self.dossier = create(Builder("dossier").within(self.repo))

        self.view_repo = OpengeverSharingView(self.repo, self.portal.REQUEST)
        self.view_dossier = OpengeverSharingView(self.dossier,
                                                 self.portal.REQUEST)

        # Event class to look for fired events
        class MockEvent(object):

            # History: [[interface, context], ]
            event_history = []

            def mock_handler(self, event):
                self.event_history.append(event, )

            def last_event(self):
                return self.event_history[-1]

        self.mock_event = MockEvent()
Beispiel #2
0
    def base_available_roles(self, provide=""):
        """ Test available_roles mehtod from OpengeverSharingView class
        """
        # Context
        context = self.create_dummy()
        if provide:
            directlyProvides(context, provide)

        mock_context = self.mocker.proxy(context)

        # Request
        request = self.create_dummy()
        mock_request = self.mocker.proxy(request)

        # Sharing view
        sharing = OpengeverSharingView(mock_context, mock_request)
        mock_sharing = self.mocker.patch(sharing)
        self.expect(mock_sharing.roles()).result([
            {
                'id': 'Reader',
            },
        ]).count(0, None)

        self.replay()

        return sharing.available_roles()
Beispiel #3
0
    def setUp(self):
        """ Set up test environment
        """
        super(TestOpengeverSharingIntegration, self).setUp()
        self.grant('Manager')
        create(Builder('fixture').with_admin_unit())
        self.repo = create(Builder("repository"))
        self.dossier = create(Builder("dossier").within(self.repo))

        self.view_repo = OpengeverSharingView(self.repo, self.portal.REQUEST)
        self.view_dossier = OpengeverSharingView(self.dossier, self.portal.REQUEST)

        # Event class to look for fired events
        class MockEvent(object):

            # History: [[interface, context], ]
            event_history = []

            def mock_handler(self, event):
                self.event_history.append(event, )

            def last_event(self):
                return self.event_history[-1]

        self.mock_event = MockEvent()
    def test_principal_search_results(self):
        # Context
        context = self.create_dummy()
        mock_context = self.mocker.proxy(context)

        # Request
        request = self.create_dummy()
        mock_request = self.mocker.proxy(request)

        # Sharing view
        _principal_search_results = self.mocker.replace(
            'plone.app.workflow.browser.sharing.SharingView._principal_search_results')

        #contact info mock
        utility_mock = self.mocker.mock()
        self.mock_utility(utility_mock, IContactInformation)

        #registry mock
        registry_mock = self.mocker.mock()
        self.mock_utility(registry_mock, IRegistry)
        reg_proxy_mock = self.mocker.mock()
        self.expect(
            registry_mock.forInterface(ISharingConfiguration)).result(reg_proxy_mock)

        self.expect(reg_proxy_mock.black_list_prefix).result(u'^og_').count(0, None)
        self.expect(reg_proxy_mock.white_list_prefix).result(u'^og_ska-arch').count(0, None)

        user1 = self.create_dummy(userid='sb2m1')
        user2 = self.create_dummy(userid='sb1m1')

        self.expect(utility_mock.list_assigned_users()).result([user1, user2])

        self.expect(
            _principal_search_results(ANY, ANY, ANY, ANY, ANY, ANY)).result(
            [{'type': 'user', 'id': 'sb2m1', 'roles': {u'Publisher': False, u'Administrator': False, u'Editor': False, u'Reader': False, u'Contributor': False, u'Reviewer': False}, 'title': 'Sachbearbeiter2 Mandant1'},
             {'type': 'user', 'id': 'sb1m1', 'roles': {u'Publisher': False, u'Administrator': False, u'Editor': False, u'Reader': False, u'Contributor': False, u'Reviewer': False}, 'title': 'Sachbearbeiter1 Mandant1'},
             {'type': 'user', 'id': 'sb1m2', 'roles': {u'Publisher': False, u'Administrator': False, u'Editor': False, u'Reader': False, u'Contributor': False, u'Reviewer': False}, 'title': 'Leitung1 Mandant1'},
             {'type': 'user', 'id': 'sb2m2', 'roles': {u'Publisher': False, u'Administrator': False, u'Editor': False, u'Reader': False, u'Contributor': False, u'Reviewer': False}, 'title': 'Sekretariat1 Mandant1'},
             {'type': 'group', 'id': 'other_group', 'roles': {u'Publisher': False, u'Administrator': False, u'Editor': False, u'Reader': False, u'Contributor': False, u'Reviewer': False}, 'title': 'Administrator1 Mandant1'},
             {'type': 'group', 'id': 'og_ska-arch_users', 'roles': {u'Publisher': False, u'Administrator': False, u'Editor': False, u'Reader': False, u'Contributor': False, u'Reviewer': False}, 'title': 'Users of SKA ARCH'},
             {'type': 'group', 'id': 'og_bd-arp_users', 'roles': {u'Publisher': False, u'Administrator': False, u'Editor': False, u'Reader': False, u'Contributor': False, u'Reviewer': False}, 'title': 'Users of BD.ARP'},
             {'type': 'group', 'id': 'og_bd-arp_og_ska-arch-users', 'roles': {u'Publisher': False, u'Administrator': False, u'Editor': False, u'Reader': False, u'Contributor': False, u'Reviewer': False}, 'title': 'Users of BD.ARP'},
             ])

        self.replay()

        sharing = OpengeverSharingView(mock_context, mock_request)
        principals = sharing._principal_search_results(
            None, None, None, None, None)

        # the wrapper shouldn't return the users wich aren't assigned to this client.
        # and also the groups from other og cliens shouldn't be returned.
        self.assertTrue(
            [principal.get('id') for principal in principals],
            ['sb2m1', 'sb1m1', 'other_group', 'og_ska-arch_users'])
    def setUp(self):
        """ Set up test environment
        """
        super(TestOpengeverSharingIntegration, self).setUp()
        self.grant('Manager')
        create(Builder('fixture').with_admin_unit())
        self.repo = create(Builder("repository"))
        self.dossier = create(Builder("dossier").within(self.repo))

        self.view_repo = OpengeverSharingView(self.repo, self.portal.REQUEST)
        self.view_dossier = OpengeverSharingView(self.dossier, self.portal.REQUEST)
        self.tab_dossier = SharingTab(self.dossier, self.portal.REQUEST)
Beispiel #6
0
    def base_roles(self, check_permission):
        """ Test roles method of OpengeverSharingView class
        """
        # Context
        mock_context = self.mocker.mock(count=False)

        # Request
        request = self.create_dummy()
        mock_request = self.mocker.proxy(request)

        # Membership Tool
        mtool = MembershipTool()
        mock_mtool = self.mocker.proxy(mtool, spec=None, count=False)
        self.expect(
            mock_mtool.checkPermission('Sharing page: Delegate Reader role',
                                       ANY)).result(True)
        self.expect(
            mock_mtool.checkPermission('Sharing page: Delegate roles',
                                       ANY)).result(False)
        self.mock_tool(mock_mtool, 'portal_membership')

        # SharingPageRole Utility 1
        utility1 = self.mocker.mock(count=False)
        self.expect(utility1.required_permission).result(
            'Sharing page: Delegate Reader role')
        self.expect(utility1.title).result('utility_1')

        self.mock_utility(utility1, ISharingPageRole, 'Reader')

        # SharingPageRole Utility 2
        utility2 = self.mocker.mock(count=False)
        self.expect(utility2.required_permission).result(
            'Sharing page: Delegate roles')
        self.expect(utility2.title).result('utility_2')

        self.mock_utility(utility2, ISharingPageRole, 'Administrator')

        self.replay()

        # Sharing view
        sharing = OpengeverSharingView(mock_context, mock_request)

        return sharing.roles(check_permission)
    def base_roles(self, check_permission):
        """ Test roles method of OpengeverSharingView class
        """
        # Context
        mock_context = self.mocker.mock(count=False)

        # Request
        request = self.create_dummy()
        mock_request = self.mocker.proxy(request)

        # Membership Tool
        mtool = MembershipTool()
        mock_mtool = self.mocker.proxy(mtool, spec=None, count=False)
        self.expect(mock_mtool.checkPermission(
            'Sharing page: Delegate Reader role', ANY)).result(True)
        self.expect(mock_mtool.checkPermission(
            'Sharing page: Delegate roles', ANY)).result(False)
        self.mock_tool(mock_mtool, 'portal_membership')

        # SharingPageRole Utility 1
        utility1 = self.mocker.mock(count=False)
        self.expect(utility1.required_permission).result(
            'Sharing page: Delegate Reader role')
        self.expect(utility1.title).result('utility_1')

        self.mock_utility(utility1, ISharingPageRole, 'Reader')

        # SharingPageRole Utility 2
        utility2 = self.mocker.mock(count=False)
        self.expect(utility2.required_permission).result(
            'Sharing page: Delegate roles')
        self.expect(utility2.title).result('utility_2')

        self.mock_utility(utility2, ISharingPageRole, 'Administrator')

        self.replay()

        # Sharing view
        sharing = OpengeverSharingView(mock_context, mock_request)

        return sharing.roles(check_permission)
    def base_available_roles(self, provide=""):
        """ Test available_roles mehtod from OpengeverSharingView class
        """
        # Context
        context = self.create_dummy()
        if provide:
            directlyProvides(context, provide)

        mock_context = self.mocker.proxy(context)

        # Request
        request = self.create_dummy()
        mock_request = self.mocker.proxy(request)

        # Sharing view
        sharing = OpengeverSharingView(mock_context, mock_request)
        mock_sharing = self.mocker.patch(sharing)
        self.expect(mock_sharing.roles()).result(
            [{'id':'Reader', }, ]).count(0, None)

        self.replay()

        return sharing.available_roles()
Beispiel #9
0
    def base_role_settings(self, roles):
        """ Test role_settings method of OpengeverSharingView class
        """
        result_existing = \
            [{'disabled': False,
              'type': 'group',
              'id': 'AuthenticatedUsers',
              'roles': {},
              'title': u'Logged-in users'}, ]
        result_group = \
             [{'disabled': False,
              'type': 'group',
              'id': u'og_mandant1_users',
              'roles': {},
              'title': 'og_mandant1_users'}, ]
        result_user = \
             [{'disabled': False,
              'type': 'user',
              'id': u'og_ska-arch_leitung',
              'roles': {},
              'title': u'og_ska-arch_leitung'}, ]

        # Member
        member = list('member')
        mock_member = self.mocker.proxy(member, spec=False)
        self.expect(mock_member.getRolesInContext(ANY)).result(roles)

        # Context
        mock_context = self.mocker.mock(count=False)
        self.expect(mock_context.__parent__).result(mock_context)
        self.expect(
            mock_context.portal_membership.getAuthenticatedMember()).result(
                mock_member)

        # Request
        request = self.create_dummy()
        mock_request = self.mocker.proxy(request)
        self.expect(mock_request.form).result({})

        # Sharing view
        sharing = OpengeverSharingView(mock_context, mock_request)
        mock_sharing = self.mocker.patch(sharing, spec=False)
        self.expect(
            mock_sharing.existing_role_settings()).result(result_existing)
        self.expect(mock_sharing.user_search_results()).result(result_group)
        self.expect(mock_sharing.group_search_results()).result(result_user)

        self.replay()

        return mock_sharing.role_settings()
class TestOpengeverSharingIntegration(FunctionalTestCase):
    use_default_fixture = False

    def setUp(self):
        """ Set up test environment
        """
        super(TestOpengeverSharingIntegration, self).setUp()
        self.grant('Manager')
        create(Builder('fixture').with_admin_unit())
        self.repo = create(Builder("repository"))
        self.dossier = create(Builder("dossier").within(self.repo))

        self.view_repo = OpengeverSharingView(self.repo, self.portal.REQUEST)
        self.view_dossier = OpengeverSharingView(self.dossier, self.portal.REQUEST)
        self.tab_dossier = SharingTab(self.dossier, self.portal.REQUEST)

    def _check_roles(self, expected, roles):
        """ Base method to check the received roles
        """
        self.assertItemsEqual(expected, [role['id'] for role in roles])

        # Reset the roles
        setRoles(
            self.portal, TEST_USER_ID, ['Manager', 'Contributor', 'Editor'])

    def test_available_roles(self):
        """ Test available roles if we are reader and owner on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ['Reader', 'Role Manager'])
        expect = [
            u'Reader',
            u'Editor',
            u'Contributor',
            u'Reviewer',
            u'Publisher', ]
        self._check_roles(expect, self.view_dossier.available_roles())

    def test_manageable_roles_with_reader_and_owner(self):
        """ Test manageable roles if we are reader and owner on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ['Reader', 'Role Manager'])
        expect = [
            u'Reader',
            u'Editor',
            u'Contributor',
            u'Reviewer',
            u'Publisher',
            u'Administrator', ]
        self._check_roles(expect, self.view_dossier.roles())

    def test_info_tab_roles(self):
        """ Test the roles displayed in the info tab on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ['Reader', 'Role Manager'])
        expect = [
            u'Reader',
            u'Editor',
            u'Contributor',
            u'Reviewer',
            u'Publisher',
            u'DossierManager',
        ]
        self._check_roles(expect, self.tab_dossier.available_roles())

    def test_update_inherit(self):
        """ tests update inherit method

        We are owner of the portal, with inheritance we are also owner of
        the repo and dossier. If we disable role aquisition on context,
        we lose the role 'owner' on the context
        """

        register_event_recorder(ILocalRolesAcquisitionBlocked)
        register_event_recorder(ILocalRolesAcquisitionActivated)

        # We disable locale role aquisition on dossier
        self.view_dossier.update_inherit(False, reindex=False)
        last_event = get_last_recorded_event()
        self.assertTrue(ILocalRolesAcquisitionBlocked.providedBy(last_event))
        self.assertEquals(last_event.object, self.dossier)

        # we disable it again,it shouldn't fire a event because nothing changed
        self.view_dossier.update_inherit(False, reindex=False)
        self.assertEquals(last_event, get_last_recorded_event())

        # # We enable locale role aquisition on dossier
        self.view_dossier.update_inherit(True, reindex=False)
        # and check the fired event
        last_event = get_last_recorded_event()
        self.assertTrue(ILocalRolesAcquisitionActivated.providedBy(last_event))
        self.assertEquals(last_event.object, self.dossier)

        # we disable it again,it shouldn't fire a event because nothing changed
        self.view_dossier.update_inherit(True, reindex=False)
        self.assertEquals(last_event, get_last_recorded_event())

    def test_update_role_settings(self):
        """ Test update_role_settings method
        """
        register_event_recorder(ILocalRolesModified)

        # If nothing has changed it needs to be reported accordingly
        changed = self.view_repo.update_role_settings([], False)
        self.assertFalse(changed)

        # We try to add the new local role 'publisher'
        new_settings = \
            [{'type': 'user', 'id': 'test_user_1_', 'roles': ['Publisher']}, ]

        changed = self.view_repo.update_role_settings(new_settings, False)
        self.assertTrue(changed)

        last_event = get_last_recorded_event()
        # check the event type
        self.assertTrue(ILocalRolesModified.providedBy(last_event))
        # check the event context
        self.assertEquals(last_event.object, self.repo)
        # check the stored localroles
        self.assertEquals(last_event.old_local_roles,
                          {'test_user_1_': ('Owner',)})
        self.assertEquals(last_event.new_local_roles,
                          (('test_user_1_', ('Owner', 'Publisher')),))

        # now we remvove the local role 'publisher'
        new_settings = \
            [{'type': 'user', 'id': 'test_user_1_', 'roles': []}, ]

        changed = self.view_repo.update_role_settings(new_settings, False)
        self.assertTrue(changed)

        # check event attributes
        last_event = get_last_recorded_event()
        self.assertTrue(ILocalRolesModified.providedBy(last_event))
        self.assertEquals(last_event.object, self.repo)
        self.assertEquals(last_event.old_local_roles,
                          {'test_user_1_': ('Owner', 'Publisher')})
        self.assertTrue(
            last_event.new_local_roles == (('test_user_1_', ('Owner',)),))

    def test_sharing_view_only_returns_users_from_current_admin_unit(self):
        # create other group, from different admin unit

        other_admin_unit = create(Builder('admin_unit').id('other'))
        test_peter = create(Builder('ogds_user')
                            .id('test.peter')
                            .having(firstname='User',
                                    lastname='Test'))
        create(Builder('org_unit')
               .id(u'otherunit')
               .having(admin_unit=other_admin_unit)
               .assign_users([test_peter]))

        # create "current" admin unit
        test_user = create(Builder('ogds_user')
                           .having(firstname='User', lastname='Test'))

        admin_unit = create(Builder('admin_unit')
                            .as_current_admin_unit())

        create(Builder('org_unit')
               .id(u'testunit')
               .having(admin_unit=admin_unit)
               .as_current_org_unit()
               .assign_users([test_user]))

        self.portal.REQUEST.form['search_term'] = TEST_USER_NAME
        results = self.view_dossier.user_search_results()
        self.assertEqual(1, len(results))
        self.assertEqual(TEST_USER_ID, results[0]['id'])
class TestOpengeverSharingIntegration(FunctionalTestCase):
    use_browser = True

    def setUp(self):
        """ Set up test environment
        """
        super(TestOpengeverSharingIntegration, self).setUp()
        self.grant('Manager')

        self.repo = create(Builder("repository"))
        self.dossier = create(Builder("dossier").within(self.repo))

        self.view_repo = OpengeverSharingView(self.repo, self.portal.REQUEST)
        self.view_dossier = OpengeverSharingView(self.dossier,
                                                 self.portal.REQUEST)

        # Event class to look for fired events
        class MockEvent(object):

            # History: [[interface, context], ]
            event_history = []

            def mock_handler(self, event):
                self.event_history.append(event, )

            def last_event(self):
                return self.event_history[-1]

        self.mock_event = MockEvent()

    def _check_roles(self, expect, roles):
        """ Base method to check the received roles
        """
        # Check the roles and sort order
        for role in roles:
            self.assertTrue(role.get('id') in expect)
            expect.remove(role.get('id'))

        self.assertTrue(len(expect) == 0)

        # Reset the roles
        setRoles(self.portal, TEST_USER_ID,
                 ['Manager', 'Contributor', 'Editor'])

    def test_available_roles(self):
        """ Test available roles if we are reader and owner on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ['Reader', 'Role Manager'])
        expect = [
            u'Reader',
            u'Editor',
            u'Contributor',
            u'Reviewer',
            u'Publisher',
        ]
        self._check_roles(expect, self.view_dossier.available_roles())

    def test_manageable_roles_with_reader_and_owner(self):
        """ Test manageable roles if we are reader and owner on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ['Reader', 'Role Manager'])
        expect = [
            u'Reader',
            u'Editor',
            u'Contributor',
            u'Reviewer',
            u'Publisher',
            u'Administrator',
        ]
        self._check_roles(expect, self.view_dossier.roles())

    def test_info_tab_roles(self):
        """ Test the roles displayed in the info tab on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ['Reader', 'Role Manager'])
        expect = [
            u'Reader',
            u'Editor',
            u'Contributor',
            u'Reviewer',
            u'Publisher',
            u'Administrator',
        ]
        self._check_roles(expect,
                          self.view_dossier.roles(check_permission=False))

    def test_update_inherit(self):
        """ tests update inherit method

        We are owner of the portal, with inheritance we are also owner of
        the repo and dossier. If we disable role aquisition on context,
        we lose the role 'owner' on the context
        """

        # Mock event handlers
        provideHandler(
            factory=self.mock_event.mock_handler,
            adapts=[
                ILocalRolesAcquisitionBlocked,
            ],
        )
        provideHandler(
            factory=self.mock_event.mock_handler,
            adapts=[
                ILocalRolesAcquisitionActivated,
            ],
        )

        # We disable locale role aquisition on dossier
        self.view_dossier.update_inherit(False, reindex=False)
        last_event = self.mock_event.last_event()
        self.assertTrue(ILocalRolesAcquisitionBlocked.providedBy(last_event))
        self.assertEquals(last_event.object, self.dossier)

        # we disable it again,it shouldn't fire a event because nothing changed
        self.view_dossier.update_inherit(False, reindex=False)
        self.assertEquals(last_event, self.mock_event.last_event())

        # # We enable locale role aquisition on dossier
        self.view_dossier.update_inherit(True, reindex=False)
        # and check the fired event
        last_event = self.mock_event.last_event()
        self.assertTrue(ILocalRolesAcquisitionActivated.providedBy(last_event))
        self.assertEquals(last_event.object, self.dossier)

        # we disable it again,it shouldn't fire a event because nothing changed
        self.view_dossier.update_inherit(True, reindex=False)
        self.assertEquals(last_event, self.mock_event.last_event())

    def test_update_role_settings(self):
        """ Test update_role_settings method
        """
        # Mock event handler
        provideHandler(
            factory=self.mock_event.mock_handler,
            adapts=[
                ILocalRolesModified,
            ],
        )

        # If nothing has changed it needs to be reported accordingly
        changed = self.view_repo.update_role_settings([], False)
        self.assertFalse(changed)

        # We try to add the new local role 'publisher'
        new_settings = \
            [{'type': 'user', 'id': 'test_user_1_', 'roles': ['Publisher']}, ]

        changed = self.view_repo.update_role_settings(new_settings, False)
        self.assertTrue(changed)

        last_event = self.mock_event.last_event()
        # check the event type
        self.assertTrue(ILocalRolesModified.providedBy(last_event))
        # check the event context
        self.assertEquals(last_event.object, self.repo)
        # check the stored localroles
        self.assertEquals(last_event.old_local_roles,
                          {'test_user_1_': ('Owner', )})
        self.assertEquals(last_event.new_local_roles,
                          (('test_user_1_', ('Owner', 'Publisher')), ))

        # now we remvove the local role 'publisher'
        new_settings = \
            [{'type': 'user', 'id': 'test_user_1_', 'roles': []}, ]

        changed = self.view_repo.update_role_settings(new_settings, False)
        self.assertTrue(changed)

        # check event attributes
        last_event = self.mock_event.last_event()
        self.assertTrue(ILocalRolesModified.providedBy(last_event))
        self.assertEquals(last_event.object, self.repo)
        self.assertEquals(last_event.old_local_roles,
                          {'test_user_1_': ('Owner', 'Publisher')})
        self.assertTrue(last_event.new_local_roles == (('test_user_1_',
                                                        ('Owner', )), ))
class TestOpengeverSharingIntegration(FunctionalTestCase):
    use_browser = True

    def setUp(self):
        """ Set up test environment
        """
        super(TestOpengeverSharingIntegration, self).setUp()
        self.grant("Manager")

        self.repo = create(Builder("repository"))
        self.dossier = create(Builder("dossier").within(self.repo))

        self.view_repo = OpengeverSharingView(self.repo, self.portal.REQUEST)
        self.view_dossier = OpengeverSharingView(self.dossier, self.portal.REQUEST)

        # Event class to look for fired events
        class MockEvent(object):

            # History: [[interface, context], ]
            event_history = []

            def mock_handler(self, event):
                self.event_history.append(event)

            def last_event(self):
                return self.event_history[-1]

        self.mock_event = MockEvent()

    def _check_roles(self, expect, roles):
        """ Base method to check the received roles
        """
        # Check the roles and sort order
        for role in roles:
            self.assertTrue(role.get("id") in expect)
            expect.remove(role.get("id"))

        self.assertTrue(len(expect) == 0)

        # Reset the roles
        setRoles(self.portal, TEST_USER_ID, ["Manager", "Contributor", "Editor"])

    def test_available_roles(self):
        """ Test available roles if we are reader and owner on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ["Reader", "Role Manager"])
        expect = [u"Reader", u"Editor", u"Contributor", u"Reviewer", u"Publisher"]
        self._check_roles(expect, self.view_dossier.available_roles())

    def test_manageable_roles_with_reader_and_owner(self):
        """ Test manageable roles if we are reader and owner on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ["Reader", "Role Manager"])
        expect = [u"Reader", u"Editor", u"Contributor", u"Reviewer", u"Publisher", u"Administrator"]
        self._check_roles(expect, self.view_dossier.roles())

    def test_info_tab_roles(self):
        """ Test the roles displayed in the info tab on a context
        providing IDossier of sharing
        """
        setRoles(self.portal, TEST_USER_ID, ["Reader", "Role Manager"])
        expect = [u"Reader", u"Editor", u"Contributor", u"Reviewer", u"Publisher", u"Administrator"]
        self._check_roles(expect, self.view_dossier.roles(check_permission=False))

    def test_update_inherit(self):
        """ tests update inherit method

        We are owner of the portal, with inheritance we are also owner of
        the repo and dossier. If we disable role aquisition on context,
        we lose the role 'owner' on the context
        """

        # Mock event handlers
        provideHandler(factory=self.mock_event.mock_handler, adapts=[ILocalRolesAcquisitionBlocked])
        provideHandler(factory=self.mock_event.mock_handler, adapts=[ILocalRolesAcquisitionActivated])

        # We disable locale role aquisition on dossier
        self.view_dossier.update_inherit(False, reindex=False)
        last_event = self.mock_event.last_event()
        self.assertTrue(ILocalRolesAcquisitionBlocked.providedBy(last_event))
        self.assertEquals(last_event.object, self.dossier)

        # we disable it again,it shouldn't fire a event because nothing changed
        self.view_dossier.update_inherit(False, reindex=False)
        self.assertEquals(last_event, self.mock_event.last_event())

        # # We enable locale role aquisition on dossier
        self.view_dossier.update_inherit(True, reindex=False)
        # and check the fired event
        last_event = self.mock_event.last_event()
        self.assertTrue(ILocalRolesAcquisitionActivated.providedBy(last_event))
        self.assertEquals(last_event.object, self.dossier)

        # we disable it again,it shouldn't fire a event because nothing changed
        self.view_dossier.update_inherit(True, reindex=False)
        self.assertEquals(last_event, self.mock_event.last_event())

    def test_update_role_settings(self):
        """ Test update_role_settings method
        """
        # Mock event handler
        provideHandler(factory=self.mock_event.mock_handler, adapts=[ILocalRolesModified])

        # If nothing has changed it needs to be reported accordingly
        changed = self.view_repo.update_role_settings([], False)
        self.assertFalse(changed)

        # We try to add the new local role 'publisher'
        new_settings = [{"type": "user", "id": "test_user_1_", "roles": ["Publisher"]}]

        changed = self.view_repo.update_role_settings(new_settings, False)
        self.assertTrue(changed)

        last_event = self.mock_event.last_event()
        # check the event type
        self.assertTrue(ILocalRolesModified.providedBy(last_event))
        # check the event context
        self.assertEquals(last_event.object, self.repo)
        # check the stored localroles
        self.assertEquals(last_event.old_local_roles, {"test_user_1_": ("Owner",)})
        self.assertEquals(last_event.new_local_roles, (("test_user_1_", ("Owner", "Publisher")),))

        # now we remvove the local role 'publisher'
        new_settings = [{"type": "user", "id": "test_user_1_", "roles": []}]

        changed = self.view_repo.update_role_settings(new_settings, False)
        self.assertTrue(changed)

        # check event attributes
        last_event = self.mock_event.last_event()
        self.assertTrue(ILocalRolesModified.providedBy(last_event))
        self.assertEquals(last_event.object, self.repo)
        self.assertEquals(last_event.old_local_roles, {"test_user_1_": ("Owner", "Publisher")})
        self.assertTrue(last_event.new_local_roles == (("test_user_1_", ("Owner",)),))
    def test_principal_search_results(self):
        # Context
        context = self.create_dummy()
        mock_context = self.mocker.proxy(context)

        # Request
        request = self.create_dummy()
        mock_request = self.mocker.proxy(request)

        # Sharing view
        _principal_search_results = self.mocker.replace(
            'plone.app.workflow.browser.sharing.SharingView._principal_search_results'
        )

        #contact info mock
        utility_mock = self.mocker.mock()
        self.mock_utility(utility_mock, IContactInformation)

        #registry mock
        registry_mock = self.mocker.mock()
        self.mock_utility(registry_mock, IRegistry)
        reg_proxy_mock = self.mocker.mock()
        self.expect(registry_mock.forInterface(ISharingConfiguration)).result(
            reg_proxy_mock)

        self.expect(reg_proxy_mock.black_list_prefix).result(u'^og_').count(
            0, None)
        self.expect(
            reg_proxy_mock.white_list_prefix).result(u'^og_ska-arch').count(
                0, None)

        user1 = self.create_dummy(userid='sb2m1')
        user2 = self.create_dummy(userid='sb1m1')

        self.expect(utility_mock.list_assigned_users()).result([user1, user2])

        self.expect(_principal_search_results(
            ANY, ANY, ANY, ANY, ANY, ANY)).result([
                {
                    'type': 'user',
                    'id': 'sb2m1',
                    'roles': {
                        u'Publisher': False,
                        u'Administrator': False,
                        u'Editor': False,
                        u'Reader': False,
                        u'Contributor': False,
                        u'Reviewer': False
                    },
                    'title': 'Sachbearbeiter2 Mandant1'
                },
                {
                    'type': 'user',
                    'id': 'sb1m1',
                    'roles': {
                        u'Publisher': False,
                        u'Administrator': False,
                        u'Editor': False,
                        u'Reader': False,
                        u'Contributor': False,
                        u'Reviewer': False
                    },
                    'title': 'Sachbearbeiter1 Mandant1'
                },
                {
                    'type': 'user',
                    'id': 'sb1m2',
                    'roles': {
                        u'Publisher': False,
                        u'Administrator': False,
                        u'Editor': False,
                        u'Reader': False,
                        u'Contributor': False,
                        u'Reviewer': False
                    },
                    'title': 'Leitung1 Mandant1'
                },
                {
                    'type': 'user',
                    'id': 'sb2m2',
                    'roles': {
                        u'Publisher': False,
                        u'Administrator': False,
                        u'Editor': False,
                        u'Reader': False,
                        u'Contributor': False,
                        u'Reviewer': False
                    },
                    'title': 'Sekretariat1 Mandant1'
                },
                {
                    'type': 'group',
                    'id': 'other_group',
                    'roles': {
                        u'Publisher': False,
                        u'Administrator': False,
                        u'Editor': False,
                        u'Reader': False,
                        u'Contributor': False,
                        u'Reviewer': False
                    },
                    'title': 'Administrator1 Mandant1'
                },
                {
                    'type': 'group',
                    'id': 'og_ska-arch_users',
                    'roles': {
                        u'Publisher': False,
                        u'Administrator': False,
                        u'Editor': False,
                        u'Reader': False,
                        u'Contributor': False,
                        u'Reviewer': False
                    },
                    'title': 'Users of SKA ARCH'
                },
                {
                    'type': 'group',
                    'id': 'og_bd-arp_users',
                    'roles': {
                        u'Publisher': False,
                        u'Administrator': False,
                        u'Editor': False,
                        u'Reader': False,
                        u'Contributor': False,
                        u'Reviewer': False
                    },
                    'title': 'Users of BD.ARP'
                },
                {
                    'type': 'group',
                    'id': 'og_bd-arp_og_ska-arch-users',
                    'roles': {
                        u'Publisher': False,
                        u'Administrator': False,
                        u'Editor': False,
                        u'Reader': False,
                        u'Contributor': False,
                        u'Reviewer': False
                    },
                    'title': 'Users of BD.ARP'
                },
            ])

        self.replay()

        sharing = OpengeverSharingView(mock_context, mock_request)
        principals = sharing._principal_search_results(None, None, None, None,
                                                       None)

        # the wrapper shouldn't return the users wich aren't assigned to this client.
        # and also the groups from other og cliens shouldn't be returned.
        self.assertTrue([principal.get('id') for principal in principals],
                        ['sb2m1', 'sb1m1', 'other_group', 'og_ska-arch_users'])