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.tracker.issuepeek.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 from google.appengine.ext import testbed |
| 11 |
| 12 from framework import permissions |
| 13 from proto import tracker_pb2 |
| 14 from services import service_manager |
| 15 from testing import fake |
| 16 from testing import testing_helpers |
| 17 from tracker import issuepeek |
| 18 from tracker import tracker_bizobj |
| 19 |
| 20 |
| 21 class IssuePeekTest(unittest.TestCase): |
| 22 |
| 23 def setUp(self): |
| 24 self.testbed = testbed.Testbed() |
| 25 self.testbed.activate() |
| 26 self.testbed.init_user_stub() |
| 27 self.testbed.init_memcache_stub() |
| 28 self.testbed.init_datastore_v3_stub() |
| 29 self.services = service_manager.Services( |
| 30 project=fake.ProjectService(), |
| 31 config=fake.ConfigService(), |
| 32 issue=fake.IssueService(), |
| 33 user=fake.UserService(), |
| 34 spam=fake.SpamService()) |
| 35 self.proj = self.services.project.TestAddProject('proj', project_id=789) |
| 36 self.cnxn = 'fake cnxn' |
| 37 self.servlet = issuepeek.IssuePeek( |
| 38 'req', 'res', services=self.services) |
| 39 self.local_id_1 = self.services.issue.CreateIssue( |
| 40 self.cnxn, self.services, |
| 41 789, 'summary', 'status', 111L, [], [], [], [], 111L, |
| 42 'The screen is just dark when I press power on') |
| 43 |
| 44 def testAssertBasePermission(self): |
| 45 """Permit users who can view issues.""" |
| 46 mr = testing_helpers.MakeMonorailRequest( |
| 47 project=self.proj, |
| 48 perms=permissions.EMPTY_PERMISSIONSET) |
| 49 mr.local_id = self.local_id_1 |
| 50 self.assertRaises(permissions.PermissionException, |
| 51 self.servlet.AssertBasePermission, mr) |
| 52 mr.perms = permissions.USER_PERMISSIONSET |
| 53 self.servlet.AssertBasePermission(mr) |
| 54 |
| 55 def testPaginateComments_NotVisible(self): |
| 56 mr = testing_helpers.MakeMonorailRequest() |
| 57 config = tracker_bizobj.MakeDefaultProjectIssueConfig(789) |
| 58 issue = fake.MakeTestIssue(789, 1, 'summary', 'New', 111L) |
| 59 issuecomment_list = [tracker_pb2.IssueComment()] |
| 60 |
| 61 # No comments yet. |
| 62 description, visible_comments, pagination = issuepeek.PaginateComments( |
| 63 mr, issue, issuecomment_list, config) |
| 64 self.assertEqual(issuecomment_list[0], description) |
| 65 self.assertEqual(issuecomment_list[1:], visible_comments) |
| 66 self.assertFalse(pagination.visible) |
| 67 |
| 68 # 5 comments, none deleted. |
| 69 for _ in range(5): |
| 70 issuecomment_list.append(tracker_pb2.IssueComment()) |
| 71 description, visible_comments, pagination = issuepeek.PaginateComments( |
| 72 mr, issue, issuecomment_list, config) |
| 73 self.assertEqual(issuecomment_list[0], description) |
| 74 self.assertEqual(issuecomment_list[1:], visible_comments) |
| 75 self.assertFalse(pagination.visible) |
| 76 |
| 77 # 5 comments, 1 of them deleted. |
| 78 issuecomment_list[1].deleted_by = 123 |
| 79 description, visible_comments, pagination = issuepeek.PaginateComments( |
| 80 mr, issue, issuecomment_list, config) |
| 81 self.assertEqual(issuecomment_list[0], description) |
| 82 self.assertEqual(issuecomment_list[2:], visible_comments) |
| 83 self.assertFalse(pagination.visible) |
| 84 |
| 85 def testPaginateComments_Visible(self): |
| 86 mr = testing_helpers.MakeMonorailRequest() |
| 87 config = tracker_bizobj.MakeDefaultProjectIssueConfig(789) |
| 88 issue = fake.MakeTestIssue(789, 1, 'summary', 'New', 111L) |
| 89 issuecomment_list = [tracker_pb2.IssueComment()] |
| 90 # 500 comments, none deleted. |
| 91 for _ in range(500): |
| 92 issuecomment_list.append(tracker_pb2.IssueComment()) |
| 93 description, visible_comments, pagination = issuepeek.PaginateComments( |
| 94 mr, issue, issuecomment_list, config) |
| 95 self.assertEqual(issuecomment_list[0], description) |
| 96 self.assertEqual(issuecomment_list[1:], visible_comments) |
| 97 self.assertFalse(pagination.visible) |
| 98 |
| 99 # 501 comments, none deleted. |
| 100 issuecomment_list.append(tracker_pb2.IssueComment()) |
| 101 description, visible_comments, pagination = issuepeek.PaginateComments( |
| 102 mr, issue, issuecomment_list, config) |
| 103 self.assertEqual(issuecomment_list[0], description) |
| 104 self.assertEqual(issuecomment_list[2:], visible_comments) |
| 105 self.assertTrue(pagination.visible) |
| 106 self.assertEqual(2, pagination.last) |
| 107 self.assertEqual(501, pagination.start) |
| 108 |
| 109 # 501 comments, 1 of them deleted. |
| 110 issuecomment_list[1].deleted_by = 123 |
| 111 description, visible_comments, pagination = issuepeek.PaginateComments( |
| 112 mr, issue, issuecomment_list, config) |
| 113 self.assertEqual(issuecomment_list[0], description) |
| 114 self.assertEqual(issuecomment_list[2:], visible_comments) |
| 115 self.assertFalse(pagination.visible) |
| 116 |
| 117 |
| 118 if __name__ == '__main__': |
| 119 unittest.main() |
OLD | NEW |