← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~nigelbabu/launchpad/spec-sub-sort into lp:launchpad

 

Nigel Babu has proposed merging lp:~nigelbabu/launchpad/spec-sub-sort into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #792129 in Launchpad itself: "Sorting of subscribers to blueprint is broken"
  https://bugs.launchpad.net/launchpad/+bug/792129

For more details, see:
https://code.launchpad.net/~nigelbabu/launchpad/spec-sub-sort/+merge/63315

Sort specification subscribers by lowercase
-- 
https://code.launchpad.net/~nigelbabu/launchpad/spec-sub-sort/+merge/63315
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~nigelbabu/launchpad/spec-sub-sort into lp:launchpad.
=== modified file 'lib/lp/blueprints/model/specification.py'
--- lib/lp/blueprints/model/specification.py	2011-05-23 20:00:39 +0000
+++ lib/lp/blueprints/model/specification.py	2011-06-02 23:34:27 +0000
@@ -221,7 +221,7 @@
     def subscriptions(self):
         """Sort the subscriptions"""
         return sorted(
-            self._subscriptions, key=lambda sub: sub.person.displayname)
+            self._subscriptions, key=lambda sub: sub.person.displayname.lower())
 
     @property
     def target(self):
@@ -559,7 +559,7 @@
         if 'subscription' in property_cache:
             property_cache.subscriptions.append(sub)
             property_cache.subscriptions.sort(
-                key=lambda sub: sub.person.displayname)
+                key=lambda sub: sub.person.displayname.lower())
         notify(ObjectCreatedEvent(sub, user=user))
         return sub
 

=== modified file 'lib/lp/blueprints/model/tests/test_specification.py'
--- lib/lp/blueprints/model/tests/test_specification.py	2011-03-14 08:09:23 +0000
+++ lib/lp/blueprints/model/tests/test_specification.py	2011-06-02 23:34:27 +0000
@@ -73,3 +73,20 @@
         self.assertThat(
             sorted(do_last.all_deps),
             Equals(sorted([do_first, do_next_lhs, do_next_rhs])))
+            
+class SpecificationSubscriptionSort(TestCaseWithFactory):
+    
+    layer = DatabaseFunctionalLayer
+    
+    def test_subscribers(self):
+        #Test the sorting of subscribers to be by displayname rather than name
+        spec = self.factory.makeBlueprint()
+        bob = self.factory.makePerson(name='zbob', displayname='Bob')
+        ced = self.factory.makePerson(name='xed', displayname='ced')
+        dave = self.factory.makePerson(name='wdave', displayname='Dave')
+        spec.subscribe(bob, bob, True)
+        spec.subscribe(ced, bob, True)
+        spec.subscribe(dave, bob, True)
+        attendances = [bob.displayname, ced.displayname, dave.displayname]
+        people = [sub.person.displayname for sub in spec.subscriptions]
+        self.assertEqual(attendances, people)