incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [9/16] git commit: [#4339] ticket:237 implement ticket move and add tests
Date Mon, 21 Jan 2013 21:53:16 GMT
[#4339] ticket:237 implement ticket move and add tests


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

Branch: refs/heads/tv/5336
Commit: 3eefd5da27506f9fec9425021dd37af49dce1d6f
Parents: a615d27
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Dec 18 11:45:54 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Fri Jan 18 21:53:18 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/model/ticket.py          |   47 ++++++++++++
 .../forgetracker/tests/functional/test_root.py     |    8 ++
 .../forgetracker/tests/unit/test_ticket_model.py   |   59 ++++++++++++++-
 ForgeTracker/forgetracker/tracker_main.py          |    3 +-
 4 files changed, 114 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3eefd5da/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index c5bdf8b..b1919b6 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -522,6 +522,53 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                 attachment.filename, attachment.file,
                 content_type=attachment.type)
 
+    def move(self, app_config):
+        '''Move ticket from current tickets app to tickets app with given app_config'''
+        self.globals.invalidate_bin_counts()
+        app = app_config.project.app_instance(app_config)
+        prior_url = self.url()
+        prior_app = self.app
+
+        # ensure unique ticket_num
+        while True:
+            with h.push_context(app_config.project_id, app_config_id=app_config._id):
+                ticket_num = app.globals.next_ticket_num()
+            self.ticket_num = ticket_num
+            self.app_config_id = app_config._id
+            try:
+                session(self).flush(self)
+                h.log_action(log, 'moved').info('Ticket %s moved to %s' % (prior_url, self.url()))
+                break
+            except OperationFailure, err:
+                if 'duplicate' in err.args[0]:
+                    log.warning('Try to create duplicate ticket %s when moving from %s' %
(self.url(), prior_url))
+                    session(self).expunge(self)
+                    continue
+
+        prior_cfs = [
+            (cf['name'], cf['type'], cf['label'])
+            for cf in prior_app.globals.custom_fields or []]
+        new_cfs = [
+            (cf['name'], cf['type'], cf['label'])
+            for cf in app.globals.custom_fields or []]
+        skipped_fields = []
+        for cf in prior_cfs:
+            if cf not in new_cfs:
+                skipped_fields.append(cf)
+
+        message = 'Ticket moved from %s' % prior_url
+        if skipped_fields:
+            message += '\n\nCan\'t be converted:\n'
+            for cf in skipped_fields:
+                name = cf[0]
+                message += '\n- **%s**: %s' % (name, self.custom_fields[name])
+        self.discussion_thread.post(text=message)
+
+        # need this to reset app_config RelationProperty on ticket to a new one
+        session(self).expunge(self)
+        return Ticket.query.find(dict(
+            app_config_id=app_config._id, ticket_num=self.ticket_num)).first()
+
     def __json__(self):
         return dict(super(Ticket,self).__json__(),
             created_date=self.created_date,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3eefd5da/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 2a01c0c..33c09a9 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -1068,6 +1068,14 @@ class TestFunctionalController(TrackerTestController):
         expected = set(['test/bugs', 'test/bugs2', 'test2/bugs', 'test2/bugs2'])
         assert trackers == expected, trackers
 
+        p = M.Project.query.get(shortname='test2')
+        tracker = p.app_instance('bugs2')
+        r = self.app.post('/p/test/bugs/1/move/',
+                params={'tracker': str(tracker.config._id)}).follow()
+        assert_equal(r.request.path, '/p/test2/bugs2/1/')
+        summary = r.html.findAll('h2', {'class': 'dark title'})[0].contents[0].strip()
+        assert_equal(summary, '#1 test')
+
     def test_move_ticket_bad_data(self):
         self.new_ticket(summary='test')
         r = self.app.post('/p/test/bugs/1/move').follow()  # empty POST

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3eefd5da/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
index 670236b..95c4d5e 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
@@ -7,7 +7,9 @@ from nose.tools import raises, assert_raises, assert_equal
 
 from forgetracker.model import Ticket
 from forgetracker.tests.unit import TrackerTestWithModel
-from allura.model import Feed
+from allura.model import Feed, Post
+from allura.lib import helpers as h
+from allura.tests import decorators as td
 
 
 class TestTicketModel(TrackerTestWithModel):
@@ -129,3 +131,58 @@ class TestTicketModel(TrackerTestWithModel):
         assert_equal(f.pubdate, datetime(2012, 10, 29, 9, 57, 21, 465000))
         assert_equal(f.title, 'test ticket')
         assert_equal(f.description, '<div class="markdown_content"><p>test description</p></div>')
+
+    @td.with_tool('test', 'Tickets', 'bugs', username='test-user')
+    @td.with_tool('test', 'Tickets', 'bugs2', username='test-user')
+    def test_ticket_move(self):
+        app1 = c.project.app_instance('bugs')
+        app2 = c.project.app_instance('bugs2')
+        with h.push_context(c.project._id, app_config_id=app1.config._id):
+            ticket = Ticket.new()
+            ticket.summary = 'test ticket'
+            ticket.description = 'test description'
+
+        assert_equal(Ticket.query.find({'app_config_id': app1.config._id}).count(), 1)
+        assert_equal(Ticket.query.find({'app_config_id': app2.config._id}).count(), 0)
+
+        t = ticket.move(app2.config)
+        assert_equal(Ticket.query.find({'app_config_id': app1.config._id}).count(), 0)
+        assert_equal(Ticket.query.find({'app_config_id': app2.config._id}).count(), 1)
+        assert_equal(t.summary, 'test ticket')
+        assert_equal(t.description, 'test description')
+        assert_equal(t.url(), '/p/test/bugs2/1/')
+
+        post = Post.query.find(dict(thread_id=ticket.discussion_thread._id)).first()
+        assert post is not None, 'No comment about ticket moving'
+        message = 'Ticket moved from /p/test/bugs/1/'
+        assert_equal(post.text, message)
+
+    @td.with_tool('test', 'Tickets', 'bugs', username='test-user')
+    @td.with_tool('test', 'Tickets', 'bugs2', username='test-user')
+    def test_ticket_move_with_different_custom_fields(self):
+        app1 = c.project.app_instance('bugs')
+        app2 = c.project.app_instance('bugs2')
+        app1.globals.custom_fields.extend([
+            {'name': '_test', 'type': 'string', 'label': 'Test field'},
+            {'name': '_test2', 'type': 'string', 'label': 'Test field 2'}])
+        app2.globals.custom_fields.append(
+            {'name': '_test', 'type': 'string', 'label': 'Test field'})
+        ThreadLocalORMSession.flush_all()
+        ThreadLocalORMSession.close_all()
+        with h.push_context(c.project._id, app_config_id=app1.config._id):
+            ticket = Ticket.new()
+            ticket.summary = 'test ticket'
+            ticket.description = 'test description'
+            ticket.custom_fields['_test'] = 'test val'
+            ticket.custom_fields['_test2'] = 'test val 2'
+
+        t = ticket.move(app2.config)
+        assert_equal(t.summary, 'test ticket')
+        assert_equal(t.description, 'test description')
+        assert_equal(t.custom_fields['_test'], 'test val')
+        post = Post.query.find(dict(thread_id=ticket.discussion_thread._id)).first()
+        assert post is not None, 'No comment about ticket moving'
+        message = 'Ticket moved from /p/test/bugs/1/'
+        message += '\n\nCan\'t be converted:\n'
+        message += '\n- **_test2**: test val 2'
+        assert_equal(post.text, message)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3eefd5da/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index e1db32b..e3650a5 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -1291,8 +1291,7 @@ class TicketController(BaseController):
                 flash('You should have admin access to destination tracker', 'error')
                 redirect(request.referer)
 
-            # new_ticket = self.ticket.move(tracker)
-            new_ticket = self.ticket
+            new_ticket = self.ticket.move(tracker)
             flash('Ticket successfully moved')
             redirect(new_ticket.url())
 


Mime
View raw message