diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,4 @@ pykolab/constants.py pykolab-[0-9]*.*/ src/ -test-* +./test-* diff --git a/pykolab/utils.py b/pykolab/utils.py --- a/pykolab/utils.py +++ b/pykolab/utils.py @@ -353,22 +353,29 @@ return result elif type(_object) == dict: - for key in _object.keys(): + def _strip(value): + try: + return value.strip() + except: + return value + + for key in _object: if type(_object[key]) == list: - if _object[key] == None: + if _object[key] is None: continue - if len(_object[key]) == 1: - result[key.lower()] = ''.join(_object[key]) + val = map(_strip, _object[key]) + + if len(val) == 1: + result[key.lower()] = ''.join(val) else: - result[key.lower()] = _object[key] + result[key.lower()] = val else: - if _object[key] == None: + if _object[key] is None: continue - # What the heck? - result[key.lower()] = _object[key] + result[key.lower()] = _strip(_object[key]) if result.has_key('objectsid') and not result['objectsid'][0] == "S": result['objectsid'] = sid_to_string(result['objectsid']) diff --git a/tests/unit/test-022-utils.py b/tests/unit/test-022-utils.py new file mode 100644 --- /dev/null +++ b/tests/unit/test-022-utils.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +import unittest + +from pykolab import utils + + +class TestTranslate(unittest.TestCase): + + def test_001_normalize(self): + attr = {"test1": " trim ", "test2": [" trim1 ", " trim2 "]} + result = utils.normalize(attr) + + self.assertEqual(result['test1'], "trim") + self.assertEqual(result['test2'][0], "trim1") + self.assertEqual(result['test2'][1], "trim2") + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/unit/test-030-recipientpolicy.py b/tests/unit/test-030-recipientpolicy.py new file mode 100644 --- /dev/null +++ b/tests/unit/test-030-recipientpolicy.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +import unittest + +from pykolab.plugins.recipientpolicy import KolabRecipientpolicy + +policy = KolabRecipientpolicy() + + +class TestRecipientPolicy(unittest.TestCase): + def test_001_primary_mail(self): + """ + The spaces in attributes used for mail generation. + """ + + entry = { + 'surname': ' sn ', + 'givenname': ' gn ', + } + + mail = policy.set_primary_mail( + primary_mail='%(givenname)s.%(surname)s@%(domain)s', + primary_domain='example.org', + entry=entry + ) + + self.assertEqual('gn.sn@example.org', mail) + +if __name__ == '__main__': + unittest.main()