Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1609)

Unified Diff: appengine/monorail/tracker/test/issueoriginal_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/monorail/tracker/test/issueoriginal_test.py
diff --git a/appengine/monorail/tracker/test/issueoriginal_test.py b/appengine/monorail/tracker/test/issueoriginal_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..aa179543a300fcfaf9811cd4a4e39e1d5742e6b4
--- /dev/null
+++ b/appengine/monorail/tracker/test/issueoriginal_test.py
@@ -0,0 +1,220 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Tests for the issueoriginal module."""
+
+import unittest
+
+import webapp2
+
+from framework import framework_helpers
+from framework import permissions
+from services import service_manager
+from testing import fake
+from testing import testing_helpers
+from tracker import issueoriginal
+
+
+STRIPPED_MSG = 'Are you sure that it is plugged in?\n'
+ORIG_MSG = ('Are you sure that it is plugged in?\n'
+ '\n'
+ '> Issue 1 entered by user foo:\n'
+ '> http://blah blah\n'
+ '> The screen is just dark when I press power on\n')
+XXX_GOOD_UNICODE_MSG = u'Thanks,\n\342\230\206*username*'.encode('utf-8')
+GOOD_UNICODE_MSG = u'Thanks,\n XXX *username*'
+XXX_BAD_UNICODE_MSG = ORIG_MSG + ('\xff' * 1000)
+BAD_UNICODE_MSG = ORIG_MSG + 'XXX'
+GMAIL_CRUFT_MSG = ORIG_MSG # XXX .replace(' ', ' \xa0 ')
+
+
+class IssueOriginalTest(unittest.TestCase):
+
+ def setUp(self):
+ self.services = service_manager.Services(
+ project=fake.ProjectService(),
+ config=fake.ConfigService(),
+ issue=fake.IssueService(),
+ user=fake.UserService())
+ self.servlet = issueoriginal.IssueOriginal(
+ 'req', 'res', services=self.services)
+
+ self.proj = self.services.project.TestAddProject('proj', project_id=789)
+ summary = 'System wont boot'
+ status = 'New'
+ cnxn = 'fake connection'
+ self.local_id_1 = self.services.issue.CreateIssue(
+ cnxn, self.services,
+ 789, summary, status, 111L, [], [], [], [], 111L,
+ 'The screen is just dark when I press power on')
+ _amendments, comment_0 = self.services.issue.ApplyIssueComment(
+ cnxn, self.services, 222L, 789, 1,
+ summary, status, 222L, [], [], [], [], [], [], [], [], 0,
+ comment=STRIPPED_MSG, inbound_message=ORIG_MSG)
+ _amendments, comment_1 = self.services.issue.ApplyIssueComment(
+ cnxn, self.services, 222L, 789, 1,
+ summary, status, 222L, [], [], [], [], [], [], [], [], None,
+ comment=STRIPPED_MSG, inbound_message=BAD_UNICODE_MSG)
+ _amendments, comment_2 = self.services.issue.ApplyIssueComment(
+ cnxn, self.services, 222L, 789, 1,
+ summary, status, 222L, [], [], [], [], [], [], [], [], 0,
+ comment=STRIPPED_MSG, inbound_message=GMAIL_CRUFT_MSG)
+ _amendments, comment_3 = self.services.issue.ApplyIssueComment(
+ cnxn, self.services, 222L, 789, 1,
+ summary, status, 222L, [], [], [], [], [], [], [], [], 0,
+ comment=STRIPPED_MSG, inbound_message=GOOD_UNICODE_MSG)
+ self.issue_1 = self.services.issue.GetIssueByLocalID(
+ cnxn, 789, self.local_id_1)
+ self.comments = [comment_0, comment_1, comment_2, comment_3]
+
+ def testAssertBasePermission(self):
+ """Permit users who can view issue, view inbound message and delete."""
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1&seq=1',
+ project=self.proj)
+ mr.perms = permissions.EMPTY_PERMISSIONSET
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+ mr.perms = permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+ mr.perms = permissions.OWNER_ACTIVE_PERMISSIONSET
+ self.servlet.AssertBasePermission(mr)
+
+ def testGatherPageData_Normal(self):
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1&seq=1',
+ project=self.proj)
+ page_data = self.servlet.GatherPageData(mr)
+ self.assertEqual(1, page_data['local_id'])
+ self.assertEqual(1, page_data['seq'])
+ self.assertFalse(page_data['is_binary'])
+ self.assertEqual(ORIG_MSG, page_data['message_body'])
+
+ def testGatherPageData_GoodUnicode(self):
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1&seq=4',
+ project=self.proj)
+ page_data = self.servlet.GatherPageData(mr)
+ self.assertEqual(1, page_data['local_id'])
+ self.assertEqual(4, page_data['seq'])
+ self.assertEqual(GOOD_UNICODE_MSG, page_data['message_body'])
+ self.assertFalse(page_data['is_binary'])
+
+ def testGatherPageData_BadUnicode(self):
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1&seq=2',
+ project=self.proj)
+ page_data = self.servlet.GatherPageData(mr)
+ self.assertEqual(1, page_data['local_id'])
+ self.assertEqual(2, page_data['seq'])
+ # xxx: should be true if cruft was there.
+ # self.assertTrue(page_data['is_binary'])
+
+ def testGatherPageData_GmailCruft(self):
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1&seq=3',
+ project=self.proj)
+ page_data = self.servlet.GatherPageData(mr)
+ self.assertEqual(1, page_data['local_id'])
+ self.assertEqual(3, page_data['seq'])
+ self.assertFalse(page_data['is_binary'])
+ self.assertEqual(ORIG_MSG, page_data['message_body'])
+
+ def testGatherPageData_404(self):
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original',
+ project=self.proj)
+ try:
+ self.servlet.GatherPageData(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1&seq=999',
+ project=self.proj)
+ try:
+ self.servlet.GatherPageData(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=999&seq=1',
+ project=self.proj)
+ try:
+ self.servlet.GatherPageData(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ def testGetIssueAndComment_Normal(self):
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1&seq=1',
+ project=self.proj)
+ issue, comment = self.servlet._GetIssueAndComment(mr)
+ self.assertEqual(self.issue_1, issue)
+ self.assertEqual(self.comments[1].content, comment.content)
+
+ def testGetIssueAndComment_NoSuchComment(self):
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1&seq=99',
+ project=self.proj)
+ try:
+ self.servlet._GetIssueAndComment(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ def testGetIssueAndComment_Malformed(self):
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original',
+ project=self.proj)
+ try:
+ self.servlet._GetIssueAndComment(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=1',
+ project=self.proj)
+ try:
+ self.servlet._GetIssueAndComment(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?seq=1',
+ project=self.proj)
+ try:
+ self.servlet._GetIssueAndComment(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?id=abc',
+ project=self.proj)
+ try:
+ self.servlet._GetIssueAndComment(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+ _request, mr = testing_helpers.GetRequestObjects(
+ path='/p/proj/issues/original?seq=abc',
+ project=self.proj)
+ try:
+ self.servlet._GetIssueAndComment(mr)
+ self.fail()
+ except webapp2.HTTPException as e:
+ self.assertEquals(404, e.code)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/tracker/test/issueoptions_test.py ('k') | appengine/monorail/tracker/test/issuepeek_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698