def search(self):
        """ A traversable method to search for users"""
        query = self.request.get('q', None)
        page = int(self.request.get('page', 1))
        pagesize = int(self.request.get('pagesize', 20))

        if not query:
            return json.dumps({})

        source = AllUsersSource(api.portal.get())
        batch = Batch.fromPagenumber(items=source.search(query),
                                     pagesize=pagesize,
                                     pagenumber=page)

        def _term_to_dict(term):
            return {'_resultId': term.token,
                    'id': term.token,
                    'text': term.title and term.title or term.token}

        return json.dumps(
            {
                'results': map(_term_to_dict, batch),
                'total_count': len(batch),
                'page': page,
                'pagination': {'more': (page * pagesize) < len(batch)}
            }
        )
Exemplo n.º 2
0
    def search(self):
        """ A traversable method to search for users"""
        query = self.request.get('q', None)
        page = int(self.request.get('page', 1))
        pagesize = int(self.request.get('pagesize', 20))

        if not query:
            return json.dumps({})

        source = AllUsersSource(api.portal.get())
        batch = Batch.fromPagenumber(items=source.search(query),
                                     pagesize=pagesize,
                                     pagenumber=page)

        def _term_to_dict(term):
            return {'_resultId': term.token,
                    'id': term.token,
                    'text': term.title and term.title or term.token}

        return json.dumps(
            {
                'results': map(_term_to_dict, batch),
                'total_count': len(batch),
                'page': page,
                'pagination': {'more': (page * pagesize) < len(batch)}
            }
        )
Exemplo n.º 3
0
    def test_users_without_orgunits_are_valid_and_found_by_search_if_requested(self):
        source = AllUsersSource(self.portal, only_active_orgunits=False)
        self.assertIn('without.orgunit', source)

        result = source.search('without')
        self.assertEquals(
            1, len(result),
            'Expected user Without Orgunit in result')

        self.assertEquals('without.orgunit', result[0].token)
Exemplo n.º 4
0
    def test_users_without_orgunits_are_valid_and_found_by_search_if_requested(
            self):
        source = AllUsersSource(self.portal, only_active_orgunits=False)
        self.assertIn('without.orgunit', source)

        result = source.search('without')
        self.assertEquals(1, len(result),
                          'Expected user Without Orgunit in result')

        self.assertEquals('without.orgunit', result[0].token)
Exemplo n.º 5
0
class TestAllUsersSource(FunctionalTestCase):
    use_default_fixture = False

    def setUp(self):
        super(TestAllUsersSource, self).setUp()

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

        user = create(Builder('ogds_user').having(firstname='Test',
                                                  lastname='User'))
        additional = create(Builder('admin_unit')
                            .id('additional')
                            .having(title='additional'))

        self.org_unit = create(Builder('org_unit').id('client1')
                               .having(title=u"Client 1",
                                       admin_unit=self.admin_unit)
                               .with_default_groups())

        org_unit_2 = create(Builder('org_unit').id('client2')
                            .having(title=u"Client 2",
                                    admin_unit=self.admin_unit)
                            .with_default_groups()
                            .assign_users([user])
                            .as_current_org_unit())

        org_unit_3 = create(Builder('org_unit')
                            .id('client3')
                            .having(title=u"Client 3", admin_unit=additional)
                            .with_default_groups())

        disabled_unit = create(Builder('org_unit')
                               .id('client4')
                               .having(title=u'Steueramt',
                                       enabled=False,
                                       admin_unit=self.admin_unit)
                               .with_default_groups())

        create(Builder('ogds_user').id('hugo.boss')
               .having(firstname='Test', lastname='User')
               .assign_to_org_units([self.org_unit]))

        create(Builder('ogds_user').id('peter.muster')
               .having(firstname='Peter', lastname='Muster')
               .assign_to_org_units([org_unit_2]))

        create(Builder('ogds_user').id('jamie.lannister')
               .having(firstname='Jamie', lastname='Lannister')
               .assign_to_org_units([self.org_unit, org_unit_2]))

        create(Builder('ogds_user').id('peter.meier')
               .having(firstname='Peter', lastname='Meier')
               .assign_to_org_units([org_unit_3]))

        create(Builder('ogds_user')
               .id('john.doe')
               .having(firstname='John', lastname='Doe', active=False)
               .assign_to_org_units([self.org_unit]))

        create(Builder('ogds_user').id('simon.says')
               .having(firstname='Simon', lastname='Says')
               .assign_to_org_units([disabled_unit]))

        create(Builder('ogds_user').id('without.orgunit')
               .having(firstname='User Without', lastname='Orgunit'))

        self.source = AllUsersSource(self.portal)

    def test_all_users_are_valid(self):
        self.assertIn('hugo.boss', self.source)
        self.assertIn('peter.muster', self.source)
        self.assertIn('jamie.lannister', self.source)
        self.assertIn(TEST_USER_ID, self.source)
        self.assertIn('peter.meier', self.source)
        self.assertIn('john.doe', self.source)
        self.assertIn('without.orgunit', self.source)

    def test_users_from_inactive_orgunits_are_valid_but_not_found_by_search(self):
        self.assertIn('simon.says', self.source)
        self.assertEquals([], self.source.search('simon'))

    def test_users_without_orgunits_are_valid_but_not_found_by_search(self):
        self.assertIn('without.orgunit', self.source)
        self.assertEquals([], self.source.search('without'))

    def test_users_without_orgunits_are_valid_and_found_by_search_if_requested(self):
        source = AllUsersSource(self.portal, only_active_orgunits=False)
        self.assertIn('without.orgunit', source)

        result = source.search('without')
        self.assertEquals(
            1, len(result),
            'Expected user Without Orgunit in result')

        self.assertEquals('without.orgunit', result[0].token)

    def test_users_assigned_to_other_admin_units_are_valid_and_found_by_search(self):
        self.assertIn('peter.meier', self.source)
        result = self.source.search('meier')
        self.assertEquals(
            1, len(result),
            'Expected user Peter Meier from other admin unit in result')

        self.assertEquals('peter.meier', result[0].token)

    def test_return_no_search_result_for_inactive_orgunits(self):
        result = self.source.search('Simon')
        self.assertFalse(result,
                         'Expect no result, since the Steueramt is disabled')

    def test_search_for_inactive_users_is_possible(self):
        result = self.source.search('Doe')
        self.assertEquals(1, len(result),
                          'Expect the inactive user John Doe in result')

        self.assertEquals('john.doe', result[0].token)
Exemplo n.º 6
0
class TestAllUsersSource(FunctionalTestCase):
    use_default_fixture = False

    def setUp(self):
        super(TestAllUsersSource, self).setUp()

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

        user = create(
            Builder('ogds_user').having(firstname='Test', lastname='User'))
        additional = create(
            Builder('admin_unit').id('additional').having(title='additional'))

        self.org_unit = create(
            Builder('org_unit').id('client1').having(
                title=u"Client 1",
                admin_unit=self.admin_unit).with_default_groups())

        org_unit_2 = create(
            Builder('org_unit').id('client2').having(
                title=u"Client 2",
                admin_unit=self.admin_unit).with_default_groups().assign_users(
                    [user]).as_current_org_unit())

        org_unit_3 = create(
            Builder('org_unit').id('client3').having(
                title=u"Client 3",
                admin_unit=additional).with_default_groups())

        disabled_unit = create(
            Builder('org_unit').id('client4').having(
                title=u'Steueramt', enabled=False,
                admin_unit=self.admin_unit).with_default_groups())

        create(
            Builder('ogds_user').id('hugo.boss').having(
                firstname='Test',
                lastname='User').assign_to_org_units([self.org_unit]))

        create(
            Builder('ogds_user').id('peter.muster').having(
                firstname='Peter',
                lastname='Muster').assign_to_org_units([org_unit_2]))

        create(
            Builder('ogds_user').id('jamie.lannister').having(
                firstname='Jamie', lastname='Lannister').assign_to_org_units(
                    [self.org_unit, org_unit_2]))

        create(
            Builder('ogds_user').id('peter.meier').having(
                firstname='Peter',
                lastname='Meier').assign_to_org_units([org_unit_3]))

        create(
            Builder('ogds_user').id('john.doe').having(
                firstname='John', lastname='Doe',
                active=False).assign_to_org_units([self.org_unit]))

        create(
            Builder('ogds_user').id('simon.says').having(
                firstname='Simon',
                lastname='Says').assign_to_org_units([disabled_unit]))

        create(
            Builder('ogds_user').id('without.orgunit').having(
                firstname='User Without', lastname='Orgunit'))

        self.source = AllUsersSource(self.portal)

    def test_all_users_are_valid(self):
        self.assertIn('hugo.boss', self.source)
        self.assertIn('peter.muster', self.source)
        self.assertIn('jamie.lannister', self.source)
        self.assertIn(TEST_USER_ID, self.source)
        self.assertIn('peter.meier', self.source)
        self.assertIn('john.doe', self.source)
        self.assertIn('without.orgunit', self.source)

    def test_users_from_inactive_orgunits_are_valid_but_not_found_by_search(
            self):
        self.assertIn('simon.says', self.source)
        self.assertEquals([], self.source.search('simon'))

    def test_users_without_orgunits_are_valid_but_not_found_by_search(self):
        self.assertIn('without.orgunit', self.source)
        self.assertEquals([], self.source.search('without'))

    def test_users_without_orgunits_are_valid_and_found_by_search_if_requested(
            self):
        source = AllUsersSource(self.portal, only_active_orgunits=False)
        self.assertIn('without.orgunit', source)

        result = source.search('without')
        self.assertEquals(1, len(result),
                          'Expected user Without Orgunit in result')

        self.assertEquals('without.orgunit', result[0].token)

    def test_users_assigned_to_other_admin_units_are_valid_and_found_by_search(
            self):
        self.assertIn('peter.meier', self.source)
        result = self.source.search('meier')
        self.assertEquals(
            1, len(result),
            'Expected user Peter Meier from other admin unit in result')

        self.assertEquals('peter.meier', result[0].token)

    def test_return_no_search_result_for_inactive_orgunits(self):
        result = self.source.search('Simon')
        self.assertFalse(result,
                         'Expect no result, since the Steueramt is disabled')

    def test_search_for_inactive_users_is_possible(self):
        result = self.source.search('Doe')
        self.assertEquals(1, len(result),
                          'Expect the inactive user John Doe in result')

        self.assertEquals('john.doe', result[0].token)
Exemplo n.º 7
0
class TestAllUsersSource(FunctionalTestCase):
    use_default_fixture = False

    def setUp(self):
        super(TestAllUsersSource, self).setUp()

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

        user = create(
            Builder('ogds_user').having(firstname='Test', lastname='User'))
        additional = create(
            Builder('admin_unit').id('additional').having(title='additional'))

        self.org_unit = create(
            Builder('org_unit').id('client1').having(
                title=u"Client 1",
                admin_unit=self.admin_unit).with_default_groups())

        org_unit_2 = create(
            Builder('org_unit').id('client2').having(
                title=u"Client 2",
                admin_unit=self.admin_unit).with_default_groups().assign_users(
                    [user]).as_current_org_unit())

        org_unit_3 = create(
            Builder('org_unit').id('client3').having(
                title=u"Client 3",
                admin_unit=additional).with_default_groups())

        create(
            Builder('ogds_user').id('hugo.boss').having(
                firstname='Test',
                lastname='User').assign_to_org_units([self.org_unit]))

        create(
            Builder('ogds_user').id('peter.muster').having(
                firstname='Peter',
                lastname='Muster').assign_to_org_units([org_unit_2]))

        create(
            Builder('ogds_user').id('jamie.lannister').having(
                firstname='Jamie', lastname='Lannister').assign_to_org_units(
                    [self.org_unit, org_unit_2]))

        create(
            Builder('ogds_user').id('peter.meier').having(
                firstname='Peter',
                lastname='Meier').assign_to_org_units([org_unit_3]))

        create(
            Builder('ogds_user').id('john.doe').having(
                firstname='John', lastname='Doe',
                active=False).assign_to_org_units([self.org_unit]))

        self.source = AllUsersSource(self.portal)

    def test_all_users_are_valid(self):

        self.assertIn('hugo.boss', self.source)
        self.assertIn('peter.muster', self.source)
        self.assertIn('jamie.lannister', self.source)
        self.assertIn(TEST_USER_ID, self.source)
        self.assertIn('peter.meier', self.source)
        self.assertIn('john.doe', self.source)

    def test_search_for_inactive_users_is_possible(self):
        result = self.source.search('Doe')
        self.assertEquals(1, len(result),
                          'Expect the inactive user John Doe in result')

        self.assertEquals('john.doe', result[0].token)