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

Unified Diff: appengine/monorail/tracker/test/issuepeek_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/issuepeek_test.py
diff --git a/appengine/monorail/tracker/test/issuepeek_test.py b/appengine/monorail/tracker/test/issuepeek_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..b4dc3d4797c71b99a2905c4d2f37043ce4a8c8b3
--- /dev/null
+++ b/appengine/monorail/tracker/test/issuepeek_test.py
@@ -0,0 +1,119 @@
+# 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
+
+"""Unittests for monorail.tracker.issuepeek."""
+
+import unittest
+
+from google.appengine.ext import testbed
+
+from framework import permissions
+from proto import tracker_pb2
+from services import service_manager
+from testing import fake
+from testing import testing_helpers
+from tracker import issuepeek
+from tracker import tracker_bizobj
+
+
+class IssuePeekTest(unittest.TestCase):
+
+ def setUp(self):
+ self.testbed = testbed.Testbed()
+ self.testbed.activate()
+ self.testbed.init_user_stub()
+ self.testbed.init_memcache_stub()
+ self.testbed.init_datastore_v3_stub()
+ self.services = service_manager.Services(
+ project=fake.ProjectService(),
+ config=fake.ConfigService(),
+ issue=fake.IssueService(),
+ user=fake.UserService(),
+ spam=fake.SpamService())
+ self.proj = self.services.project.TestAddProject('proj', project_id=789)
+ self.cnxn = 'fake cnxn'
+ self.servlet = issuepeek.IssuePeek(
+ 'req', 'res', services=self.services)
+ self.local_id_1 = self.services.issue.CreateIssue(
+ self.cnxn, self.services,
+ 789, 'summary', 'status', 111L, [], [], [], [], 111L,
+ 'The screen is just dark when I press power on')
+
+ def testAssertBasePermission(self):
+ """Permit users who can view issues."""
+ mr = testing_helpers.MakeMonorailRequest(
+ project=self.proj,
+ perms=permissions.EMPTY_PERMISSIONSET)
+ mr.local_id = self.local_id_1
+ self.assertRaises(permissions.PermissionException,
+ self.servlet.AssertBasePermission, mr)
+ mr.perms = permissions.USER_PERMISSIONSET
+ self.servlet.AssertBasePermission(mr)
+
+ def testPaginateComments_NotVisible(self):
+ mr = testing_helpers.MakeMonorailRequest()
+ config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
+ issue = fake.MakeTestIssue(789, 1, 'summary', 'New', 111L)
+ issuecomment_list = [tracker_pb2.IssueComment()]
+
+ # No comments yet.
+ description, visible_comments, pagination = issuepeek.PaginateComments(
+ mr, issue, issuecomment_list, config)
+ self.assertEqual(issuecomment_list[0], description)
+ self.assertEqual(issuecomment_list[1:], visible_comments)
+ self.assertFalse(pagination.visible)
+
+ # 5 comments, none deleted.
+ for _ in range(5):
+ issuecomment_list.append(tracker_pb2.IssueComment())
+ description, visible_comments, pagination = issuepeek.PaginateComments(
+ mr, issue, issuecomment_list, config)
+ self.assertEqual(issuecomment_list[0], description)
+ self.assertEqual(issuecomment_list[1:], visible_comments)
+ self.assertFalse(pagination.visible)
+
+ # 5 comments, 1 of them deleted.
+ issuecomment_list[1].deleted_by = 123
+ description, visible_comments, pagination = issuepeek.PaginateComments(
+ mr, issue, issuecomment_list, config)
+ self.assertEqual(issuecomment_list[0], description)
+ self.assertEqual(issuecomment_list[2:], visible_comments)
+ self.assertFalse(pagination.visible)
+
+ def testPaginateComments_Visible(self):
+ mr = testing_helpers.MakeMonorailRequest()
+ config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
+ issue = fake.MakeTestIssue(789, 1, 'summary', 'New', 111L)
+ issuecomment_list = [tracker_pb2.IssueComment()]
+ # 500 comments, none deleted.
+ for _ in range(500):
+ issuecomment_list.append(tracker_pb2.IssueComment())
+ description, visible_comments, pagination = issuepeek.PaginateComments(
+ mr, issue, issuecomment_list, config)
+ self.assertEqual(issuecomment_list[0], description)
+ self.assertEqual(issuecomment_list[1:], visible_comments)
+ self.assertFalse(pagination.visible)
+
+ # 501 comments, none deleted.
+ issuecomment_list.append(tracker_pb2.IssueComment())
+ description, visible_comments, pagination = issuepeek.PaginateComments(
+ mr, issue, issuecomment_list, config)
+ self.assertEqual(issuecomment_list[0], description)
+ self.assertEqual(issuecomment_list[2:], visible_comments)
+ self.assertTrue(pagination.visible)
+ self.assertEqual(2, pagination.last)
+ self.assertEqual(501, pagination.start)
+
+ # 501 comments, 1 of them deleted.
+ issuecomment_list[1].deleted_by = 123
+ description, visible_comments, pagination = issuepeek.PaginateComments(
+ mr, issue, issuecomment_list, config)
+ self.assertEqual(issuecomment_list[0], description)
+ self.assertEqual(issuecomment_list[2:], visible_comments)
+ self.assertFalse(pagination.visible)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/tracker/test/issueoriginal_test.py ('k') | appengine/monorail/tracker/test/issuereindex_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698