Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F118533627
D136.1775877042.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D136.1775877042.diff
View Options
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()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 11, 3:10 AM (14 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18848202
Default Alt Text
D136.1775877042.diff (2 KB)
Attached To
Mode
D136: Trim spaces in surname/givenname/sn when generating mail/alias (#5360)
Attached
Detach File
Event Timeline