OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered by a BSD-style |
| 3 # license that can be found in the LICENSE file or at |
| 4 # https://developers.google.com/open-source/licenses/bsd |
| 5 |
| 6 """Unittests for monorail.features.commitlogcommands.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 import mox |
| 11 |
| 12 from features import commitlogcommands |
| 13 from features import notify |
| 14 from proto import tracker_pb2 |
| 15 from services import service_manager |
| 16 from testing import fake |
| 17 from testing import testing_helpers |
| 18 |
| 19 |
| 20 class InboundEmailTest(unittest.TestCase): |
| 21 |
| 22 def setUp(self): |
| 23 self.cnxn = 'fake cnxn' |
| 24 self.services = service_manager.Services( |
| 25 issue=fake.IssueService(), |
| 26 project=fake.ProjectService(), |
| 27 config=fake.ConfigService()) |
| 28 |
| 29 self.project = self.services.project.TestAddProject( |
| 30 'proj', project_id=987, process_inbound_email=True) |
| 31 self.issue = tracker_pb2.Issue() |
| 32 self.issue.project_id = 987 |
| 33 self.issue.summary = 'summary' |
| 34 self.issue.status = 'Assigned' |
| 35 self.services.issue.TestAddIssue(self.issue) |
| 36 |
| 37 self.uia = commitlogcommands.UpdateIssueAction(self.issue.local_id) |
| 38 self.mox = mox.Mox() |
| 39 |
| 40 def tearDown(self): |
| 41 self.mox.UnsetStubs() |
| 42 self.mox.ResetAll() |
| 43 |
| 44 def testParse_StripQuotedLines(self): |
| 45 self.uia.Parse(self.cnxn, self.project.project_name, 101, |
| 46 ['summary:something', '> line 1', 'line 2'], self.services, |
| 47 hostport=80, strip_quoted_lines=True) |
| 48 self.assertEquals('line 2', self.uia.description) |
| 49 self.assertEquals('summary:something\n> line 1\nline 2', |
| 50 self.uia.inbound_message) |
| 51 |
| 52 def testParse_NoStripQuotedLines(self): |
| 53 self.uia.Parse(self.cnxn, self.project.project_name, 101, |
| 54 ['summary:something', '> line 1', 'line 2'], self.services, |
| 55 hostport=80) |
| 56 self.assertEquals('> line 1\nline 2', self.uia.description) |
| 57 self.assertIsNone(self.uia.inbound_message) |
| 58 |
| 59 def setupAndCallRun(self, allow_edit): |
| 60 comments = ['comment 1', 'comment 2', 'comment 3'] |
| 61 |
| 62 self.mox.StubOutWithMock(self.services.issue, 'GetCommentsForIssue') |
| 63 self.services.issue.GetCommentsForIssue( |
| 64 self.cnxn, self.issue.issue_id).AndReturn(comments) |
| 65 self.mox.StubOutWithMock(notify, 'PrepareAndSendIssueChangeNotification') |
| 66 notify.PrepareAndSendIssueChangeNotification( |
| 67 self.project.project_id, self.issue.local_id, 80, 101, |
| 68 len(comments) - 1, old_owner_id=self.issue.owner_id) |
| 69 self.mox.ReplayAll() |
| 70 |
| 71 self.uia.Parse(self.cnxn, self.project.project_name, 101, |
| 72 ['summary:something', 'status:New', '> line 1', '> line 2'], |
| 73 self.services, hostport=80) |
| 74 self.uia.Run(self.cnxn, self.services, allow_edit=allow_edit) |
| 75 self.mox.VerifyAll() |
| 76 |
| 77 def testRun_AllowEdit(self): |
| 78 self.setupAndCallRun(allow_edit=True) |
| 79 |
| 80 self.assertEquals('> line 1\n> line 2', self.uia.description) |
| 81 # Assert that ammendments were made to the issue. |
| 82 self.assertEquals('something', self.issue.summary) |
| 83 self.assertEquals('New', self.issue.status) |
| 84 |
| 85 |
| 86 def testRun_NoAllowEdit(self): |
| 87 self.setupAndCallRun(allow_edit=False) |
| 88 |
| 89 self.assertEquals('> line 1\n> line 2', self.uia.description) |
| 90 # Assert that ammendments were *not* made to the issue. |
| 91 self.assertEquals('summary', self.issue.summary) |
| 92 self.assertEquals('Assigned', self.issue.status) |
| 93 |
| 94 |
| 95 if __name__ == '__main__': |
| 96 unittest.main() |
OLD | NEW |