def setUp(self): self.mox = mox.Mox() self.mock_index = self.mox.CreateMockAnything() self.mox.StubOutWithMock(search, 'Index') self.docs = None self.cnxn = 'fake connection' self.user_service = fake.UserService() self.user_service.TestAddUser('*****@*****.**', 111) self.issue_service = fake.IssueService() self.config_service = fake.ConfigService() self.issue = fake.MakeTestIssue(123, 1, 'test summary', 'New', 111) self.issue_service.TestAddIssue(self.issue) self.comment = tracker_pb2.IssueComment( project_id=789, issue_id=self.issue.issue_id, user_id=111, content='comment content', attachments=[ tracker_pb2.Attachment(filename='hello.c'), tracker_pb2.Attachment(filename='hello.h') ]) self.issue_service.TestAddComment(self.comment, 1) self.users_by_id = framework_views.MakeAllUserViews( self.cnxn, self.user_service, [111])
def setUp(self): self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_app_identity_stub() services = service_manager.Services(project=fake.ProjectService(), config=fake.ConfigService(), issue=fake.IssueService(), user=fake.UserService()) self.project = services.project.TestAddProject('proj') self.servlet = issueattachmenttext.AttachmentText('req', 'res', services=services) self.issue = tracker_pb2.Issue() self.issue.local_id = 1 self.issue.issue_id = 1 self.issue.summary = 'sum' self.issue.project_name = 'proj' self.issue.project_id = self.project.project_id services.issue.TestAddIssue(self.issue) self.comment0 = tracker_pb2.IssueComment() self.comment0.content = 'this is the description' self.comment1 = tracker_pb2.IssueComment() self.comment1.content = 'this is a comment' self.attach0 = tracker_pb2.Attachment( attachment_id=4567, filename='b.txt', mimetype='text/plain', gcs_object_id='/pid/attachments/abcd') self.comment0.attachments.append(self.attach0) self.attach1 = tracker_pb2.Attachment( attachment_id=1234, filename='a.txt', mimetype='text/plain', gcs_object_id='/pid/attachments/abcdefg') self.comment0.attachments.append(self.attach1) self.bin_attach = tracker_pb2.Attachment( attachment_id=2468, mimetype='application/octets', gcs_object_id='/pid/attachments/\0\0\0\0\0\1\2\3') self.comment1.attachments.append(self.bin_attach) self.comment0.project_id = self.project.project_id services.issue.TestAddComment(self.comment0, self.issue.local_id) self.comment1.project_id = self.project.project_id services.issue.TestAddComment(self.comment1, self.issue.local_id) services.issue.TestAddAttachment(self.attach0, self.comment0.id, self.issue.issue_id) services.issue.TestAddAttachment(self.attach1, self.comment1.id, self.issue.issue_id) # TODO(jrobbins): add tests for binary content self._old_gcs_open = cloudstorage.open cloudstorage.open = fake.gcs_open
def testGetViewURL(self): """The view URL may add &inline=1, or use our text attachment servlet.""" attach = tracker_pb2.Attachment( attachment_id=1, mimetype='see below', filesize=1000) download_url = 'attachment?aid=1&signed_aid=2' # Viewable image. attach.mimetype = 'image/jpeg' self.assertEqual( download_url + '&inline=1', attachment_helpers.GetViewURL(attach, download_url, 'proj')) # Viewable video. attach.mimetype = 'video/mpeg' self.assertEqual( download_url + '&inline=1', attachment_helpers.GetViewURL(attach, download_url, 'proj')) # Viewable text file. attach.mimetype = 'text/html' self.assertEqual( '/p/proj/issues/attachmentText?aid=1', attachment_helpers.GetViewURL(attach, download_url, 'proj')) # Something we don't support. attach.mimetype = 'audio/mp3' self.assertIsNone( attachment_helpers.GetViewURL(attach, download_url, 'proj'))
def _ParseAttachment(self, attachment_json, _event_log): attachment = tracker_pb2.Attachment( filename=attachment_json['name'], filesize=attachment_json['size'], mimetype=attachment_json['mimetype'], gcs_object_id=attachment_json['gcs_object_id']) return attachment
def setUp(self): self.mox = mox.Mox() self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_memcache_stub() self.testbed.init_app_identity_stub() self.testbed.init_urlfetch_stub() self.attachment_data = "" self._old_gcs_open = cloudstorage.open cloudstorage.open = fake.gcs_open services = service_manager.Services( project=fake.ProjectService(), config=fake.ConfigService(), issue=fake.IssueService(), user=fake.UserService()) self.project = services.project.TestAddProject('proj') self.servlet = issueattachment.AttachmentPage( 'req', webapp2.Response(), services=services) self.issue = fake.MakeTestIssue( self.project.project_id, 1, 'summary', 'New', 111L) services.issue.TestAddIssue(self.issue) self.comment = tracker_pb2.IssueComment( id=123, issue_id=self.issue.issue_id, project_id=self.project.project_id, user_id=111L, content='this is a comment') services.issue.TestAddComment(self.comment, self.issue.local_id) self.attachment = tracker_pb2.Attachment( attachment_id=54321, filename='hello.txt', filesize=23432, mimetype='text/plain', gcs_object_id='/pid/attachments/hello.txt') services.issue.TestAddAttachment( self.attachment, self.comment.id, self.issue.issue_id)
def testViewableText(self): name = 'hello.c' attach_pb = tracker_pb2.Attachment() attach_pb.filesize = 1234 attach_pb.attachment_id = 12345 attach_pb.filename = name attach_pb.mimetype = 'text/plain' view = tracker_views.AttachmentView(attach_pb, 'proj') view_url = '/p/proj/issues/attachmentText?aid=12345' self.assertEqual(view_url, view.url)
def testGetVideoURL(self): """The video URL is the same as the view URL for actual videos.""" attach = tracker_pb2.Attachment( attachment_id=1, mimetype='see below', filesize=1000) download_url = 'attachment?aid=1&signed_aid=2' # Viewable video. attach.mimetype = 'video/mpeg' self.assertEqual( download_url + '&inline=1', attachment_helpers.GetVideoURL(attach, download_url)) # Anything that is not a video. attach.mimetype = 'audio/mp3' self.assertIsNone(attachment_helpers.GetVideoURL(attach, download_url))
def testConvertAttachment(self): """Test convert_attachment.""" attachment = tracker_pb2.Attachment(attachment_id=1, filename='stats.txt', filesize=12345, mimetype='text/plain', deleted=False) result = api_pb2_v1_helpers.convert_attachment(attachment) self.assertEquals(attachment.attachment_id, result.attachmentId) self.assertEquals(attachment.filename, result.fileName) self.assertEquals(attachment.filesize, result.fileSize) self.assertEquals(attachment.mimetype, result.mimetype) self.assertEquals(attachment.deleted, result.isDeleted)
def MakeViewAndVerifyFields( self, size, name, mimetype, expected_size_str, expect_viewable): attach_pb = tracker_pb2.Attachment() attach_pb.filesize = size attach_pb.attachment_id = 12345 attach_pb.filename = name attach_pb.mimetype = mimetype view = tracker_views.AttachmentView(attach_pb, 'proj') self.assertEqual('/images/paperclip.png', view.iconurl) self.assertEqual(expected_size_str, view.filesizestr) dl = 'attachment?aid=12345' self.assertEqual(dl, view.downloadurl) if expect_viewable: self.assertEqual(dl + '&inline=1', view.url) self.assertEqual(dl + '&inline=1&thumb=1', view.thumbnail_url) else: self.assertEqual(None, view.url) self.assertEqual(None, view.thumbnail_url)
def testGetThumbnailURL(self): """The thumbnail URL may add param thumb=1 or not.""" attach = tracker_pb2.Attachment( attachment_id=1, mimetype='see below', filesize=1000) download_url = 'attachment?aid=1&signed_aid=2' # Viewable image. attach.mimetype = 'image/jpeg' self.assertEqual( download_url + '&inline=1&thumb=1', attachment_helpers.GetThumbnailURL(attach, download_url)) # Viewable video. attach.mimetype = 'video/mpeg' self.assertIsNone( # Video thumbs are displayed via GetVideoURL rather than this. attachment_helpers.GetThumbnailURL(attach, download_url)) # Something that we don't thumbnail. attach.mimetype = 'audio/mp3' self.assertIsNone(attachment_helpers.GetThumbnailURL(attach, download_url))
def testNotifyApprovalChangeTask_Normal(self): config = self.services.config.GetProjectConfig('cnxn', 12345) config.field_defs = [ # issue's User field with any_comment is notified. tracker_bizobj.MakeFieldDef( 121, 12345, 'TL', tracker_pb2.FieldTypes.USER_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.ANY_COMMENT, 'no_action', 'TL, notified on everything', False), # issue's User field with never is not notified. tracker_bizobj.MakeFieldDef( 122, 12345, 'silentTL', tracker_pb2.FieldTypes.USER_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'TL, notified on nothing', False), # approval's User field with any_comment is notified. tracker_bizobj.MakeFieldDef(123, 12345, 'otherapprovalTL', tracker_pb2.FieldTypes.USER_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.ANY_COMMENT, 'no_action', 'TL on the approvers team', False, approval_id=3), # another approval's User field with any_comment is not notified. tracker_bizobj.MakeFieldDef(124, 12345, 'otherapprovalTL', tracker_pb2.FieldTypes.USER_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.ANY_COMMENT, 'no_action', 'TL on another approvers team', False, approval_id=4), tracker_bizobj.MakeFieldDef(3, 12345, 'Goat-Approval', tracker_pb2.FieldTypes.APPROVAL_TYPE, '', '', False, False, False, None, None, None, False, '', None, tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'Get Approval from Goats', False) ] self.services.config.StoreConfig('cnxn', config) # Custom user_type field TLs self.services.user.TestAddUser('*****@*****.**', 111) self.services.user.TestAddUser('*****@*****.**', 222) self.services.user.TestAddUser('*****@*****.**', 333) self.services.user.TestAddUser('*****@*****.**', 444) # Approvers self.services.user.TestAddUser('*****@*****.**', 777) self.services.user.TestAddUser('*****@*****.**', 888) self.services.user.TestAddUser('*****@*****.**', 999) self.services.user.TestAddUser('*****@*****.**', 666) self.services.user.TestAddUser('*****@*****.**', 661) self.services.user.TestAddUser('*****@*****.**', 662) self.services.user.TestAddUser('*****@*****.**', 663) self.services.usergroup.TestAddGroupSettings( 666, '*****@*****.**') self.services.usergroup.TestAddMembers(666, [661, 662, 663]) canary_phase = tracker_pb2.Phase(name='Canary', phase_id=1, rank=1) approval_values = [ tracker_pb2.ApprovalValue(approval_id=3, approver_ids=[888, 999, 666, 661]) ] approval_issue = MakeTestIssue(project_id=12345, local_id=2, owner_id=2, reporter_id=1, is_spam=True) approval_issue.phases = [canary_phase] approval_issue.approval_values = approval_values approval_issue.field_values = [ tracker_bizobj.MakeFieldValue(121, None, None, 111, None, None, False), tracker_bizobj.MakeFieldValue(122, None, None, 222, None, None, False), tracker_bizobj.MakeFieldValue(123, None, None, 333, None, None, False), tracker_bizobj.MakeFieldValue(124, None, None, 444, None, None, False), ] self.services.issue.TestAddIssue(approval_issue) amend = tracker_bizobj.MakeApprovalApproversAmendment([888], [777]) comment = tracker_pb2.IssueComment(project_id=12345, user_id=999, issue_id=approval_issue.issue_id, amendments=[amend], timestamp=1234567890, content='just a comment.') attach = tracker_pb2.Attachment(attachment_id=4567, filename='sploot.jpg', mimetype='image/png', gcs_object_id='/pid/attachments/abcd', filesize=(1024 * 1023)) comment.attachments.append(attach) self.services.issue.TestAddComment(comment, approval_issue.local_id) self.services.issue.TestAddAttachment(attach, comment.id, approval_issue.issue_id) task = notify.NotifyApprovalChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_id': approval_issue.issue_id, 'approval_id': 3, 'comment_id': comment.id, } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.assertTrue('just a comment' in result['tasks'][0]['body']) self.assertTrue('Approvers: -approver' in result['tasks'][0]['body']) self.assertTrue('sploot.jpg' in result['tasks'][0]['body']) self.assertTrue( '/issues/attachment?aid=4567' in result['tasks'][0]['body']) self.assertItemsEqual([ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ], result['notified']) # Test no approvers/groups notified # Status change to NEED_INFO does not email approvers. amend2 = tracker_bizobj.MakeApprovalStatusAmendment( tracker_pb2.ApprovalStatus.NEED_INFO) comment2 = tracker_pb2.IssueComment(project_id=12345, user_id=999, issue_id=approval_issue.issue_id, amendments=[amend2], timestamp=1234567891, content='') self.services.issue.TestAddComment(comment2, approval_issue.local_id) task = notify.NotifyApprovalChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_id': approval_issue.issue_id, 'approval_id': 3, 'comment_id': comment2.id, } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.assertTrue('Status: need_info' in result['tasks'][0]['body']) self.assertItemsEqual( ['*****@*****.**', '*****@*****.**', '*****@*****.**'], result['notified'])