From: Stephen Finucane Date: Fri, 5 Feb 2016 17:16:58 +0000 (+0000) Subject: py3: Ensure map is wrapped in list X-Git-Tag: v1.1.0~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16680f811b8cb6fcd7243aa1c883675b4b63539a;p=thirdparty%2Fpatchwork.git py3: Ensure map is wrapped in list 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 --- diff --git a/patchwork/tests/test_xmlrpc.py b/patchwork/tests/test_xmlrpc.py index e70ed30a..c69062ef 100644 --- a/patchwork/tests/test_xmlrpc.py +++ b/patchwork/tests/test_xmlrpc.py @@ -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) diff --git a/patchwork/views/xmlrpc.py b/patchwork/views/xmlrpc.py index 28fd03bd..86abd6db 100644 --- a/patchwork/views/xmlrpc.py +++ b/patchwork/views/xmlrpc.py @@ -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: