]> err.no Git - dak/commitdiff
Factor Uploaders splitting into its own function.
authorTorsten Werner <twerner@debian.org>
Sun, 24 Jul 2011 12:45:00 +0000 (14:45 +0200)
committerTorsten Werner <twerner@debian.org>
Sun, 24 Jul 2011 12:45:00 +0000 (14:45 +0200)
+ Add a test for it.

Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/test_split_uploaders.py [new file with mode: 0755]

index 48dfd0d8b205c840188f9b5bb77d6336e13d0fb9..f314b3f7ef37a2defaf51c6b127c269265bac648 100755 (executable)
@@ -2635,6 +2635,14 @@ __all__.append('import_metadata_into_db')
 
 ################################################################################
 
+def split_uploaders(uploaders_list):
+    '''
+    Split the Uploaders field into the individual uploaders and yield each of
+    them. Beware: email addresses might contain commas.
+    '''
+    for uploader in uploaders_list.replace(">, ", ">\t").split("\t"):
+        yield uploader.strip()
+
 @session_wrapper
 def add_dsc_to_db(u, filename, session=None):
     entry = u.pkg.files[filename]
@@ -2725,8 +2733,7 @@ def add_dsc_to_db(u, filename, session=None):
     session.refresh(source)
     source.uploaders = [source.maintainer]
     if u.pkg.dsc.has_key("uploaders"):
-        for up in u.pkg.dsc["uploaders"].replace(">, ", ">\t").split("\t"):
-            up = up.strip()
+        for up in split_uploaders(u.pkg.dsc["uploaders"]):
             source.uploaders.append(get_or_set_maintainer(up, session))
 
     session.flush()
diff --git a/tests/test_split_uploaders.py b/tests/test_split_uploaders.py
new file mode 100755 (executable)
index 0000000..062fd35
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+from base_test import DakTestCase
+
+from daklib.dbconn import split_uploaders
+
+import unittest
+
+class SplitUploadersTestCase(DakTestCase):
+    def test_main(self):
+        expected = ['"A, B" <a@b.c>', 'D E <d@e.f>']
+        l = list(split_uploaders('"A, B" <a@b.c>, D E <d@e.f>'))
+        self.assertEqual(expected, l)
+
+if __name__ == '__main__':
+    unittest.main()