incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [3/3] git commit: [#6646] ticket:456 Small fixes and refactoring
Date Thu, 24 Oct 2013 18:58:16 GMT
[#6646] ticket:456 Small fixes and refactoring

- Rename check_labels to append_new_labels
- Fix list values handling in get_change_text


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

Branch: refs/heads/master
Commit: 9e35b6f857efedfd4cac82b9e1fb657ce619794c
Parents: 4efe798
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Oct 24 13:37:11 2013 +0300
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Thu Oct 24 18:57:13 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/model/ticket.py               | 12 +++++-------
 ForgeTracker/forgetracker/tests/functional/test_root.py |  4 ++--
 .../forgetracker/tests/unit/test_globals_model.py       | 10 +++++-----
 .../forgetracker/tests/unit/test_root_controller.py     |  5 +++++
 ForgeTracker/forgetracker/tracker_main.py               |  4 ++++
 5 files changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e35b6f8/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 9dff7a4..d580c43 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -344,7 +344,7 @@ class Globals(MappedClass):
         for ticket in tickets:
             message = ''
             if labels:
-                values['labels'] = self.check_labels(ticket.labels[:], labels.split(','))
+                values['labels'] = self.append_new_labels(ticket.labels, labels.split(','))
             for k, v in sorted(values.iteritems()):
                 if k == 'assigned_to_id':
                     new_user = User.query.get(_id=v)
@@ -461,12 +461,10 @@ class Globals(MappedClass):
                 user.add(tickets_index_id[subscription.artifact_index_id])
         return filtered
 
-    def check_labels(self, old_labels, new_labels):
-        for label in new_labels:
-            label = label.strip()
-            if label not in old_labels:
-                old_labels.append(label)
-        return old_labels
+    def append_new_labels(self, old_labels, new_labels):
+        old_labels = set(old_labels)
+        new_labels = set(l.strip() for l in new_labels)
+        return list(old_labels | new_labels)
 
 
 class TicketHistory(Snapshot):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e35b6f8/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 04aae18..ef53280 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -357,8 +357,8 @@ class TestFunctionalController(TrackerTestController):
         assert_equal(ticket1.labels, ['tag2', 'tag3'])
         assert_equal(ticket2.labels, ['tag1', 'tag2', 'tag3'])
         assert_equal(ticket3.labels, ['tag1', 'tag2', 'tag3'])
-        r = self.app.get('/p/test/bugs/2/')
-        assert '<li><strong>Labels</strong>: tag1 --&gt; tag1tag2tag3</li>'
in r
+        r = self.app.get('/p/test/bugs/3/')
+        assert '<li><strong>Labels</strong>: tag1, tag2 --&gt; tag1,
tag2, tag3</li>' in r
 
     def test_mass_edit_custom_fields(self):
         params = dict(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e35b6f8/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_globals_model.py b/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
index 4732d7b..ada2120 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_globals_model.py
@@ -116,12 +116,12 @@ class TestGlobalsModel(TrackerTestWithModel):
         assert_equal(gbl._bin_counts_expire, now + timedelta(minutes=60))
         assert_equal(gbl._bin_counts_invalidated, None)
 
-    def test_check_labels(self):
+    def test_append_new_labels(self):
         gbl = Globals()
-        assert_equal(gbl.check_labels([], ['tag1']), ['tag1'])
-        assert_equal(gbl.check_labels(['tag1', 'tag2'], ['tag2']), ['tag1', 'tag2'])
-        assert_equal(gbl.check_labels(['tag1', 'tag2'], ['tag3']), ['tag1', 'tag2', 'tag3'])
-        assert_equal(gbl.check_labels(['tag1', 'tag2', 'tag3'], ['tag2']), ['tag1', 'tag2',
'tag3'])
+        assert_equal(gbl.append_new_labels([], ['tag1']), ['tag1'])
+        assert_equal(gbl.append_new_labels(['tag1', 'tag2'], ['tag2']), ['tag1', 'tag2'])
+        assert_equal(gbl.append_new_labels(['tag1', 'tag2'], ['tag3']), ['tag1', 'tag2',
'tag3'])
+        assert_equal(gbl.append_new_labels(['tag1', 'tag2', 'tag3'], ['tag2']), ['tag1',
'tag2', 'tag3'])
 
 
 class TestCustomFields(TrackerTestWithModel):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e35b6f8/ForgeTracker/forgetracker/tests/unit/test_root_controller.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_root_controller.py b/ForgeTracker/forgetracker/tests/unit/test_root_controller.py
index c6c3dc1..f952aba 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_root_controller.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_root_controller.py
@@ -116,3 +116,8 @@ class test_change_text(unittest.TestCase):
         self.assertEqual(
             '- **test**: value2 --> value1\n',
             tracker_main.get_change_text('test', 'value1', 'value2'))
+
+    def test_get_change_text_for_lists(self):
+        self.assertEqual(
+            '- **test**: v1, v2 --> v3, v4, v5\n',
+            tracker_main.get_change_text('test', ['v3', 'v4', 'v5'], ['v1', 'v2']))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e35b6f8/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 19dc1b8..b772e06 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -130,6 +130,10 @@ def get_label(name):
 
 def get_change_text(name, new_value, old_value):
     changes = changelog()
+    if isinstance(old_value, list):
+        old_value = ', '.join(old_value)
+    if isinstance(new_value, list):
+        new_value = ', '.join(new_value)
     changes[name] = old_value
     changes[name] = new_value
     tpl_fn = pkg_resources.resource_filename(


Mime
View raw message