def test_008_unicode_ru_RU(self):
        from pykolab import utils
        givenname = u'Юлия'
        surname = u'Ёлкина'

        preferredlanguage = 'ru_RU'

        self.assertEqual('Yuliya', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Yolkina', utils.translate(surname, preferredlanguage))
    def test_006_unicode_ru_RU(self):
        from pykolab import utils
        givenname = u'Николай'
        surname = u'Римский-Корсаков'

        preferredlanguage = 'ru_RU'

        self.assertEqual('Nikolaj', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Rimskij-Korsakov', utils.translate(surname, preferredlanguage))
Example #3
0
def createUsersList(client):
    bfp = open(os.path.join(os.path.dirname(__file__), 'data/de-boys.txt'),
               'r')
    gfp = open(os.path.join(os.path.dirname(__file__), 'data/de-girls.txt'),
               'r')
    sfp = open(os.path.join(os.path.dirname(__file__), 'data/de-surnames.txt'),
               'r')

    boys = [x.strip() for x in bfp.readlines()]
    girls = [x.strip() for x in gfp.readlines()]
    surnames = [x.strip() for x in sfp.readlines()]

    bfp.close()
    gfp.close()
    sfp.close()

    ulist = []

    for g in range(0, (len(girls) - 1)):
        if g >= max_multiplier and not max_multiplier < 0:
            break

        for s in range(0, (len(surnames) - 1)):
            if s >= max_multiplier and not max_multiplier < 0:
                break

            # Contact or Kolab User?
            contact = random.randint(0, ratio_contacts)
            givenname = girls[random.randint(0, (len(girls) - 1))]
            sn = surnames[random.randint(0, (len(surnames) - 1))]

            if contact > 0:
                type_key = 'contact'
                attrs = {
                    'ou':
                    "ou=Contacts,%s" % client.conf.get('ldap', 'user_base_dn'),
                    'mail':
                    '*****@*****.**' % (utils.translate(
                        givenname, 'de_DE'), utils.translate(sn, 'de_DE'))
                }

            else:
                type_key = 'kolab'
                ou_info = client.random_ou(params={'ou': 'People'})
                attrs = {'ou': ou_info['entrydn']}

            ulist.append({
                'givenname': givenname,
                'sn': sn,
                'preferredlanguage': 'de_DE',
                'type_key': type_key,
                'attrs': attrs
            })

    return ulist
Example #4
0
    def test_007_raw_ru_RU(self):
        from pykolab import utils
        givenname = r'Юлия'
        surname = r'Ёлкина'

        preferredlanguage = 'ru_RU'

        self.assertEqual('Yuliya', utils.translate(givenname,
                                                   preferredlanguage))
        self.assertEqual('Yolkina', utils.translate(surname,
                                                    preferredlanguage))
Example #5
0
    def test_006_unicode_ru_RU(self):
        from pykolab import utils
        givenname = u'Николай'
        surname = u'Римский-Корсаков'

        preferredlanguage = 'ru_RU'

        self.assertEqual('Nikolaj',
                         utils.translate(givenname, preferredlanguage))
        self.assertEqual('Rimskij-Korsakov',
                         utils.translate(surname, preferredlanguage))
Example #6
0
def createUsersList(client):
    bfp = open(os.path.join(os.path.dirname(__file__), 'data/de-boys.txt'), 'r')
    gfp = open(os.path.join(os.path.dirname(__file__), 'data/de-girls.txt'), 'r')
    sfp = open(os.path.join(os.path.dirname(__file__), 'data/de-surnames.txt'), 'r')

    boys = [x.strip() for x in bfp.readlines()]
    girls = [x.strip() for x in gfp.readlines()]
    surnames = [x.strip() for x in sfp.readlines()]

    bfp.close()
    gfp.close()
    sfp.close()

    ulist=[]

    for g in range(0, (len(girls)-1)):
        if g >= max_multiplier and not max_multiplier < 0:
            break

        for s in range(0, (len(surnames)-1)):
            if s >= max_multiplier and not max_multiplier < 0:
                break

            # Contact or Kolab User?
            contact = random.randint(0,ratio_contacts)
            givenname = girls[random.randint(0,(len(girls)-1))]
            sn = surnames[random.randint(0,(len(surnames)-1))]

            if contact > 0:
                type_key = 'contact'
                attrs = {
                        'ou': "ou=Contacts,%s" % client.conf.get('ldap','user_base_dn'),
                        'mail': '*****@*****.**' % (
                                utils.translate(givenname, 'de_DE'),
                                utils.translate(sn, 'de_DE')
                            )
                    }

            else:
                type_key = 'kolab'
                ou_info = client.random_ou(params={'ou': 'People'})
                attrs = {
                        'ou': ou_info['entrydn']
                    }

            ulist.append({
                'givenname':givenname,
                'sn':sn,
                'preferredlanguage': 'de_DE',
                'type_key': type_key,
                'attrs': attrs
                })

    return ulist
    def test_001_raw_fr_FR(self):
        """
            The special thing about this case is that the givenname starts with
            a special character.
        """
        from pykolab import utils
        givenname = r'Étienne-Nicolas'
        surname = r'Méhul'

        preferredlanguage = 'fr_FR'

        self.assertEqual('Etienne-Nicolas', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Mehul', utils.translate(surname, preferredlanguage))
    def test_004_unicode_es_ES(self):
        """
            The special thing about this case is that the givenname starts with
            a special character.
        """
        from pykolab import utils
        givenname = 'Álvaro'
        surname = 'Fuentes'

        preferredlanguage = 'es_ES'

        self.assertEqual('Alvaro', utils.translate(givenname, preferredlanguage))
        self.assertEqual('Fuentes', utils.translate(surname, preferredlanguage))
Example #9
0
    def test_001_raw_fr_FR(self):
        """
            The special thing about this case is that the givenname starts with
            a special character.
        """
        from pykolab import utils
        givenname = r'Étienne-Nicolas'
        surname = r'Méhul'

        preferredlanguage = 'fr_FR'

        self.assertEqual('Etienne-Nicolas',
                         utils.translate(givenname, preferredlanguage))
        self.assertEqual('Mehul', utils.translate(surname, preferredlanguage))
Example #10
0
    def test_004_unicode_es_ES(self):
        """
            The special thing about this case is that the givenname starts with
            a special character.
        """
        from pykolab import utils
        givenname = 'Álvaro'
        surname = 'Fuentes'

        preferredlanguage = 'es_ES'

        self.assertEqual('Alvaro', utils.translate(givenname,
                                                   preferredlanguage))
        self.assertEqual('Fuentes', utils.translate(surname,
                                                    preferredlanguage))
Example #11
0
    def set_primary_mail(self, *args, **kw):
        """
            The arguments passed to the 'set_user_attrs_mail' hook:

            primary_mail - the policy
            user_attrs - the current user attributes
            primary_domain - the domain to use in the primary mail attribute
            secondary_domains - the secondary domains that are aliases

            Return the new primary mail address
        """

        user_attrs = utils.normalize(kw['entry'])

        if not user_attrs.has_key('domain'):
            user_attrs['domain'] = kw['primary_domain']
        elif not user_attrs['domain'] == kw['primary_domain']:
            user_attrs['domain'] = kw['primary_domain']

        if not user_attrs.has_key('preferredlanguage'):
            default_locale = conf.get(user_attrs['domain'], 'default_locale')
            if default_locale == None:
                default_locale = conf.get('kolab', 'default_locale')
            if default_locale == None:
                default_locale = 'en_US'

            user_attrs['preferredlanguage'] = default_locale

        try:
            mail = kw['primary_mail'] % user_attrs
            mail = utils.translate(mail, user_attrs['preferredlanguage'])
            mail = mail.lower()
            return mail
        except KeyError, e:
            log.warning(
                _("Attribute substitution for 'mail' failed in Recipient Policy"
                  ))
            if user_attrs.has_key('mail'):
                return user_attrs['mail']
            else:
                return None
Example #12
0
    def set_primary_mail(self, *args, **kw):
        """
            The arguments passed to the 'set_user_attrs_mail' hook:

            primary_mail - the policy
            user_attrs - the current user attributes
            primary_domain - the domain to use in the primary mail attribute
            secondary_domains - the secondary domains that are aliases

            Return the new primary mail address
        """

        user_attrs = utils.normalize(kw['entry'])

        if not user_attrs.has_key('domain'):
            user_attrs['domain'] = kw['primary_domain']
        elif not user_attrs['domain'] == kw['primary_domain']:
            user_attrs['domain'] = kw['primary_domain']

        if not user_attrs.has_key('preferredlanguage'):
            default_locale = conf.get(user_attrs['domain'], 'default_locale')
            if default_locale == None:
                default_locale = conf.get('kolab', 'default_locale')
            if default_locale == None:
                default_locale = 'en_US'

            user_attrs['preferredlanguage'] = default_locale

        try:
            mail = kw['primary_mail'] % user_attrs
            mail = utils.translate(mail, user_attrs['preferredlanguage'])
            mail = mail.lower()
            return mail
        except KeyError, e:
            log.warning(_("Attribute substitution for 'mail' failed in Recipient Policy"))
            if user_attrs.has_key('mail'):
                return user_attrs['mail']
            else:
                return None
Example #13
0
        try:
            exec("alternative_mail_routines = %s" % kw['secondary_mail'])
        except Exception, e:
            log.error(_("Could not parse the alternative mail routines"))

        alternative_mail = []

        log.debug(_("Alternative mail routines: %r") %
                  (alternative_mail_routines),
                  level=8)
        _domains = [kw['primary_domain']] + kw['secondary_domains']

        for attr in ['givenname', 'sn', 'surname']:
            try:
                user_attrs[attr] = utils.translate(
                    user_attrs[attr], user_attrs['preferredlanguage'])
            except Exception, errmsg:
                log.error(
                    _("An error occurred in composing the secondary mail attribute for entry %r"
                      ) % (user_attrs['id']))
                if conf.debuglevel > 8:
                    import traceback
                    traceback.print_exc()
                return []

        for number in alternative_mail_routines.keys():
            for routine in alternative_mail_routines[number].keys():
                try:
                    exec("retval = '%s'.%s" %
                         (routine, alternative_mail_routines[number][routine] %
                          user_attrs))
Example #14
0
            user_attrs['preferredlanguage'] = default_locale

        try:
            exec("alternative_mail_routines = %s" % kw['secondary_mail'])
        except Exception, e:
            log.error(_("Could not parse the alternative mail routines"))

        alternative_mail = []

        log.debug(_("Alternative mail routines: %r") % (alternative_mail_routines), level=8)
        _domains = [ kw['primary_domain'] ] + kw['secondary_domains']

        for attr in [ 'givenname', 'sn', 'surname' ]:
            try:
                user_attrs[attr] = utils.translate(user_attrs[attr], user_attrs['preferredlanguage'])
            except Exception, errmsg:
                log.error(_("An error occurred in composing the secondary mail attribute for entry %r") % (user_attrs['id']))
                if conf.debuglevel > 8:
                    import traceback
                    traceback.print_exc()
                return []

        for number in alternative_mail_routines.keys():
            for routine in alternative_mail_routines[number].keys():
                try:
                    exec("retval = '%s'.%s" % (routine,alternative_mail_routines[number][routine] % user_attrs))

                    log.debug(_("Appending additional mail address: %s") % (retval), level=8)
                    alternative_mail.append(retval)