[PATCH 1/2] filters: Re-add mistakenly removed method

Stephen Finucane stephen.finucane at intel.com
Fri Feb 19 04:34:25 AEDT 2016


Removing this method resulted in an issue whereby a user could not
access their "TODO list". Add tests to ensure this doesn't happen
again.

Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/filters.py         |  9 +++++++++
 patchwork/tests/test_user.py | 33 ++++++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/patchwork/filters.py b/patchwork/filters.py
index 7d0d03c..5650014 100644
--- a/patchwork/filters.py
+++ b/patchwork/filters.py
@@ -390,6 +390,15 @@ class DelegateFilter(Filter):
             return self.delegate.id
         return self.delegate_match
 
+    def set_status(self, *args, **kwargs):
+        if 'delegate' in kwargs:
+            self.applied = self.forced = True
+            self.delegate = kwargs['delegate']
+        if self.AnyDelegate in args:
+            self.applied = False
+            self.forced = True
+
+
 filterclasses = [SubmitterFilter,
                  StateFilter,
                  SearchFilter,
diff --git a/patchwork/tests/test_user.py b/patchwork/tests/test_user.py
index c27328e..bd97eb7 100644
--- a/patchwork/tests/test_user.py
+++ b/patchwork/tests/test_user.py
@@ -23,7 +23,8 @@ from django.core import mail
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 
-from patchwork.models import EmailConfirmation, Person, Bundle, UserProfile
+from patchwork.models import (EmailConfirmation, Person, Bundle, UserProfile,
+                              Patch)
 from patchwork.tests.utils import defaults, error_strings
 
 
@@ -136,11 +137,30 @@ class UserLoginRedirectTest(TestCase):
 
 class UserProfileTest(TestCase):
 
+    fixtures = ['default_states']
+
     def setUp(self):
         self.user = TestUser()
         self.client.login(username=self.user.username,
                           password=self.user.password)
 
+    # FIXME(stephenfin) Remove duplication from this and test_xmlrpc
+    def _createPatches(self, count=1):
+        defaults.project.save()
+        defaults.patch_author_person.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 testUserProfile(self):
         response = self.client.get('/user/')
         self.assertContains(response, 'User Profile: %s' % self.user.username)
@@ -162,6 +182,17 @@ class UserProfileTest(TestCase):
         self.assertContains(response, 'You have the following bundle')
         self.assertContains(response, bundle.get_absolute_url())
 
+    def testUserProfileTodos(self):
+        patches = self._createPatches(5)
+        for patch in patches:
+            patch.delegate = self.user.user
+            patch.save()
+
+        response = self.client.get('/user/')
+
+        self.assertContains(response, 'contains 5')
+        self.assertContains(response, reverse('user-todos'))
+
     def testUserProfileValidPost(self):
         user_profile = UserProfile.objects.get(user=self.user.user.id)
         old_ppp = user_profile.patches_per_page
-- 
2.0.0



More information about the Patchwork mailing list