]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
py3: Ensure map is wrapped in list
authorStephen Finucane <stephen.finucane@intel.com>
Fri, 5 Feb 2016 17:16:58 +0000 (17:16 +0000)
committerStephen Finucane <stephen.finucane@intel.com>
Mon, 8 Feb 2016 17:57:57 +0000 (17:57 +0000)
The map function doesn't return a list in Python 3, which means it
can't be used like one. Many of these issues were previously resolved
but there were some uncovered code paths. Resolve these, adding tests
to ensure it doesn't regress.

In addition, change what's serialized and returned. Instead of
returning a subset of the serialized values, only serialize a subset
of the original values. This means n items are serialized instead of
max.

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
patchwork/tests/test_xmlrpc.py
patchwork/views/xmlrpc.py

index e70ed30ae0b28e05fca8e4aff9d99cbcb096be1e..c69062efbd1d956d805deca7e78edd0a34bd2d78 100644 (file)
@@ -17,6 +17,7 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from email.utils import make_msgid
 import unittest
 
 from django.conf import settings
@@ -43,15 +44,35 @@ class XMLRPCTest(LiveServerTestCase):
         self.assertRedirects(response,
                              reverse('help', kwargs={'path': 'pwclient/'}))
 
-    def testList(self):
+    def _createPatches(self, count=1):
         defaults.project.save()
         defaults.patch_author_person.save()
-        patch = Patch(project=defaults.project,
-                      submitter=defaults.patch_author_person,
-                      msgid=defaults.patch_name,
-                      content=defaults.patch)
-        patch.save()
 
+        patches = []
+
+        for _ in range(0, count):
+            patch = Patch(project=defaults.project,
+                          submitter=defaults.patch_author_person,
+                          msgid=make_msgid(),
+                          content=defaults.patch)
+            patch.save()
+            patches.append(patch)
+
+        return patches
+
+    def testListSingle(self):
+        patch_objs = self._createPatches()
         patches = self.rpc.patch_list()
         self.assertEqual(len(patches), 1)
-        self.assertEqual(patches[0]['id'], patch.id)
+        self.assertEqual(patches[0]['id'], patch_objs[0].id)
+
+    def testListMultiple(self):
+        self._createPatches(5)
+        patches = self.rpc.patch_list()
+        self.assertEqual(len(patches), 5)
+
+    def testListMaxCount(self):
+        patch_objs = self._createPatches(5)
+        patches = self.rpc.patch_list({'max_count': 2})
+        self.assertEqual(len(patches), 2)
+        self.assertEqual(patches[0]['id'], patch_objs[0].id)
index 28fd03bddbaa9c00a9348c5b987469196f35406b..86abd6dbcf1946ca3fba987e29c9a8db76411306 100644 (file)
@@ -406,7 +406,7 @@ def project_list(search_str=None, max_count=0):
             projects = Project.objects.all()
 
         if max_count > 0:
-            return map(project_to_dict, projects)[:max_count]
+            return list(map(project_to_dict, projects[:max_count]))
         else:
             return list(map(project_to_dict, projects))
     except Project.DoesNotExist:
@@ -458,7 +458,7 @@ def person_list(search_str=None, max_count=0):
             people = Person.objects.all()
 
         if max_count > 0:
-            return map(person_to_dict, people)[:max_count]
+            return list(map(person_to_dict, people[:max_count]))
         else:
             return list(map(person_to_dict, people))
     except Person.DoesNotExist:
@@ -601,9 +601,9 @@ def patch_list(filt=None):
         patches = Patch.objects.filter(**dfilter)
 
         if max_count > 0:
-            return [patch_to_dict(patch) for patch in patches[:max_count]]
+            return list(map(patch_to_dict, patches[:max_count]))
         else:
-            return [patch_to_dict(patch) for patch in patches]
+            return list(map(patch_to_dict, patches))
     except Patch.DoesNotExist:
         return []
 
@@ -794,7 +794,7 @@ def state_list(search_str=None, max_count=0):
             states = State.objects.all()
 
         if max_count > 0:
-            return map(state_to_dict, states)[:max_count]
+            return list(map(state_to_dict, states[:max_count]))
         else:
             return list(map(state_to_dict, states))
     except State.DoesNotExist: