You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/12/25 10:37:02 UTC
[3/4] allura git commit: [#8003] ticket:877 Fix bug in
unique_attachments
[#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/ib/8003
Commit: 97a793617f8161c86c8081d29c14d0be2481149c
Parents: f75277c
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Dec 24 17:40:08 2015 +0200
Committer: Igor Bondarenko <je...@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))