allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [3/4] allura git commit: [#8003] ticket:877 Fix bug in unique_attachments
Date Tue, 05 Jan 2016 23:14:47 GMT
[#8003] ticket:877 Fix bug in unique_attachments


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/97a79361
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/97a79361
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/97a79361

Branch: refs/heads/master
Commit: 97a793617f8161c86c8081d29c14d0be2481149c
Parents: f75277c
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Dec 24 17:40:08 2015 +0200
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Thu Dec 24 17:40:08 2015 +0200

----------------------------------------------------------------------
 Allura/allura/lib/utils.py        | 2 ++
 Allura/allura/tests/test_utils.py | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/97a79361/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index d01e115..17721b0 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -650,6 +650,8 @@ def unique_attachments(attachments):
     if not attachments:
         return []
     result = []
+    # list passed to groupby should be sorted in order to avoid group key repetition
+    attachments = sorted(attachments, key=op.attrgetter('filename'))
     for _, atts in groupby(attachments, op.attrgetter('filename')):
         result.append(max(atts, key=op.attrgetter('_id')))
     return result

http://git-wip-us.apache.org/repos/asf/allura/blob/97a79361/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index afbd2ec..396acfb 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -340,6 +340,8 @@ class FakeAttachment(object):
     def __init__(self, filename):
         self._id = ObjectId()
         self.filename = filename
+    def __repr__(self):
+        return u'%s %s' % (self._id, self.filename)
 
 
 def unique_attachments():
@@ -352,6 +354,6 @@ def unique_attachments():
     file1 = FakeAttachment('file.txt')
     file2 = FakeAttachment('file.txt')
     other = FakeAttachment('other')
-    attachments = [pic1, pic2, file1, file2, other]
-    expected = [pic2, file2, other]
+    attachments = [pic1, file1, pic2, file2, pic2, other]
+    expected = [file2, other, pic2]
     assert_equal(expected, ua(attachments))


Mime
View raw message