You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/02/05 18:26:28 UTC
[6/7] git commit: [#5730] ticket:265 Set discussion_id on attachments
and fix tests
[#5730] ticket:265 Set discussion_id on attachments and fix 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/53180731
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/53180731
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/53180731
Branch: refs/heads/master
Commit: 5318073120a2334573439ff65d5e9531c2bd21a3
Parents: 8f09f6c
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Feb 4 12:47:36 2013 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Feb 5 17:26:08 2013 +0000
----------------------------------------------------------------------
ForgeTracker/forgetracker/model/ticket.py | 14 +++++---
.../forgetracker/tests/functional/test_root.py | 29 +++++++++------
2 files changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/53180731/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 2532b18..0f1ae3e 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -526,12 +526,16 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
attachment.filename, attachment.file,
content_type=attachment.type)
- def _move_attach(self, attachments, attach_metadata, app_config_id):
+ def _move_attach(self, attachments, attach_metadata, app_config):
for attach in attachments:
- attach.app_config_id = app_config_id
+ attach.app_config_id = app_config._id
+ if attach.attachment_type == 'DiscussionAttachment':
+ attach.discussion_id = app_config.discussion_id
attach_thumb = BaseAttachment.query.get(filename=attach.filename, **attach_metadata)
if attach_thumb:
- attach_thumb.app_config_id = app_config_id
+ if attach_thumb.attachment_type == 'DiscussionAttachment':
+ attach_thumb.discussion_id = app_config.discussion_id
+ attach_thumb.app_config_id = app_config._id
def move(self, app_config):
'''Move ticket from current tickets app to tickets app with given app_config'''
@@ -597,7 +601,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
continue
attach_metadata['type'] = 'thumbnail'
- self._move_attach(attachments, attach_metadata, app_config._id)
+ self._move_attach(attachments, attach_metadata, app_config)
# move ticket's discussion thread, thus all new commnets will go to a new ticket's feed
self.discussion_thread.app_config_id = app_config._id
@@ -605,10 +609,10 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
for post in self.discussion_thread.posts:
attach_metadata = BaseAttachment.metadata_for(post)
attach_metadata['type'] = 'thumbnail'
+ self._move_attach(post.attachments, attach_metadata, app_config)
post.app_config_id = app_config._id
post.app_id = app_config._id
post.discussion_id = app_config.discussion_id
- self._move_attach(post.attachments, attach_metadata, app_config._id)
session(self.discussion_thread).flush(self.discussion_thread)
# need this to reset app_config RelationProperty on ticket to a new one
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/53180731/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 dde9afc..0e9207f 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -1283,27 +1283,34 @@ class TestFunctionalController(TrackerTestController):
file_path = os.path.join(allura.__path__[0],'nf','allura','images',file_name)
file_data = file(file_path).read()
upload = ('attachment', file_name, file_data)
- ticket_view = self.new_ticket(summary='test move attachment').follow()
+ self.new_ticket(summary='test move attachment')
+
+ # attach an image to the ticket
self.app.post('/bugs/1/update_ticket',
{'summary':'test'},
upload_files=[upload])
+ # attach a txt file to the comment
r = self.app.get('/p/test/bugs/1/')
post_link = str(r.html.find('div', {'class': 'edit_post_form reply'}).find('form')['action'])
r = self.app.post(post_link + 'attach',
upload_files=[('file_info', 'test.txt', 'test')])
+ # move ticket
p = M.Project.query.get(shortname='test2')
- ac_id = p.app_instance('bugs2').config._id
+ bugs2 = p.app_instance('bugs2')
r = self.app.post('/p/test/bugs/1/move/',
- params={'tracker': str(ac_id)}).follow()
-
- app_config_id = tm.Ticket.query.find().first().app_config_id
- assert 'neo-icon-set-454545-256x350.png' in r
- assert 'test.txt' in r
- assert '/attachment/neo-icon-set-454545-256x350.png/thumb' in r
-
+ params={'tracker': str(bugs2.config._id)}).follow()
+
+ attachs = r.html.findAll('div', attrs={'class': 'attachment_thumb'})
+ ta = str(attachs[1]) # ticket's attachments
+ ca = str(attachs[2]) # comment's attachments
+ assert_in('<a href="/p/test2/bugs2/1/attachment/neo-icon-set-454545-256x350.png"', ta)
+ assert_in('<img src="/p/test2/bugs2/1/attachment/neo-icon-set-454545-256x350.png/thumb"', ta)
+ p = M.Post.query.find().sort('timestamp', 1).first()
+ assert_in('<a href="/p/test2/bugs2/_discuss/thread/%s/%s/attachment/test.txt"' % (p.thread_id, p.slug), ca)
for attach in M.BaseAttachment.query.find():
- assert attach.app_config_id == app_config_id
- assert attach.url() in r
+ assert_equal(attach.app_config_id, bugs2.config._id)
+ if attach.attachment_type == 'DiscussionAttachment':
+ assert_equal(attach.discussion_id, bugs2.config.discussion_id)
@td.with_tool('test', 'Tickets', 'dummy')
def test_move_ticket_comments(self):