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 the issueentry servlet.""" |
| 7 |
| 8 import mox |
| 9 import unittest |
| 10 |
| 11 from framework import framework_views |
| 12 from framework import permissions |
| 13 from services import service_manager |
| 14 from testing import fake |
| 15 from testing import testing_helpers |
| 16 from tracker import issueentry |
| 17 |
| 18 from google.appengine.ext import testbed |
| 19 |
| 20 class IssueEntryTest(unittest.TestCase): |
| 21 def setUp(self): |
| 22 self.testbed = testbed.Testbed() |
| 23 self.testbed.activate() |
| 24 self.testbed.init_taskqueue_stub() |
| 25 self.testbed.init_memcache_stub() |
| 26 self.testbed.init_datastore_v3_stub() |
| 27 self.services = service_manager.Services( |
| 28 config=fake.ConfigService(), |
| 29 issue=fake.IssueService(), |
| 30 user=fake.UserService(), |
| 31 project=fake.ProjectService()) |
| 32 self.project = self.services.project.TestAddProject('proj', project_id=987) |
| 33 self.servlet = issueentry.IssueEntry( |
| 34 'req', 'res', services=self.services) |
| 35 self.mox = mox.Mox() |
| 36 |
| 37 def tearDown(self): |
| 38 self.mox.UnsetStubs() |
| 39 self.mox.ResetAll() |
| 40 |
| 41 def testAssertBasePermission(self): |
| 42 """Permit users with CREATE_ISSUE.""" |
| 43 mr = testing_helpers.MakeMonorailRequest( |
| 44 path='/p/proj/issues/entry', services=self.services, |
| 45 perms=permissions.EMPTY_PERMISSIONSET) |
| 46 self.assertRaises(permissions.PermissionException, |
| 47 self.servlet.AssertBasePermission, mr) |
| 48 mr = testing_helpers.MakeMonorailRequest( |
| 49 path='/p/proj/issues/entry', services=self.services, |
| 50 perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET) |
| 51 self.servlet.AssertBasePermission(mr) |
| 52 |
| 53 def testDiscardUnusedTemplateLabelPrefixes(self): |
| 54 labels = ['pre-val', 'other-value', 'oneword', 'x', '-y', '-w-z', '', '-'] |
| 55 self.assertEqual(labels, |
| 56 issueentry._DiscardUnusedTemplateLabelPrefixes(labels)) |
| 57 |
| 58 labels = ['prefix-value', 'other-?', 'third-', '', '-', '-?'] |
| 59 self.assertEqual(['prefix-value', 'third-', '', '-'], |
| 60 issueentry._DiscardUnusedTemplateLabelPrefixes(labels)) |
| 61 |
| 62 def testGatherPageData(self): |
| 63 mr = testing_helpers.MakeMonorailRequest( |
| 64 path='/p/proj/issues/entry', services=self.services) |
| 65 mr.auth.user_view = framework_views.UserView(100, 'user@invalid', True) |
| 66 user = self.services.user.TestAddUser('user@invalid', 100) |
| 67 |
| 68 self.mox.StubOutWithMock(self.services.user, 'GetUser') |
| 69 self.services.user.GetUser( |
| 70 mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(user) |
| 71 self.mox.ReplayAll() |
| 72 |
| 73 page_data = self.servlet.GatherPageData(mr) |
| 74 self.mox.VerifyAll() |
| 75 self.assertEqual(page_data['initial_owner'], 'user@invalid') |
| 76 self.assertEqual(page_data['initial_status'], 'New') |
| 77 self.assertTrue(page_data['clear_summary_on_click']) |
| 78 self.assertTrue(page_data['must_edit_summary']) |
| 79 |
| 80 def testGatherPageData_TemplateAllowsKeepingSummary(self): |
| 81 mr = testing_helpers.MakeMonorailRequest( |
| 82 path='/p/proj/issues/entry', services=self.services) |
| 83 mr.auth.user_view = framework_views.UserView(100, 'user@invalid', True) |
| 84 user = self.services.user.TestAddUser('user@invalid', 100) |
| 85 |
| 86 self.mox.StubOutWithMock(self.services.user, 'GetUser') |
| 87 self.services.user.GetUser( |
| 88 mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(user) |
| 89 self.mox.ReplayAll() |
| 90 config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id) |
| 91 self.services.config.StoreConfig(mr.cnxn, config) |
| 92 config.templates[1].summary_must_be_edited = False |
| 93 |
| 94 page_data = self.servlet.GatherPageData(mr) |
| 95 self.mox.VerifyAll() |
| 96 self.assertEqual(page_data['initial_owner'], 'user@invalid') |
| 97 self.assertEqual(page_data['initial_status'], 'New') |
| 98 self.assertFalse(page_data['clear_summary_on_click']) |
| 99 self.assertFalse(page_data['must_edit_summary']) |
| 100 |
| 101 def testGatherPageData_DeepLinkSetsSummary(self): |
| 102 mr = testing_helpers.MakeMonorailRequest( |
| 103 path='/p/proj/issues/entry?summary=foo', services=self.services) |
| 104 mr.auth.user_view = framework_views.UserView(100, 'user@invalid', True) |
| 105 user = self.services.user.TestAddUser('user@invalid', 100) |
| 106 |
| 107 self.mox.StubOutWithMock(self.services.user, 'GetUser') |
| 108 self.services.user.GetUser( |
| 109 mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(user) |
| 110 self.mox.ReplayAll() |
| 111 |
| 112 page_data = self.servlet.GatherPageData(mr) |
| 113 self.mox.VerifyAll() |
| 114 self.assertEqual(page_data['initial_owner'], 'user@invalid') |
| 115 self.assertEqual(page_data['initial_status'], 'New') |
| 116 self.assertFalse(page_data['clear_summary_on_click']) |
| 117 self.assertTrue(page_data['must_edit_summary']) |
| 118 |
| 119 def testProcessFormData(self): |
| 120 mr = testing_helpers.MakeMonorailRequest( |
| 121 path='/p/proj/issues/entry') |
| 122 mr.auth.user_view = framework_views.UserView(100, 'user@invalid', True) |
| 123 mr.perms = [] |
| 124 post_data = fake.PostData( |
| 125 summary=['fake summary'], |
| 126 comment=['fake comment'], |
| 127 status=['New']) |
| 128 url = self.servlet.ProcessFormData(mr, post_data) |
| 129 self.assertTrue('/p/proj/issues/detail?id=' in url) |
| 130 |
| 131 |
| 132 def test_SelectTemplate(self): |
| 133 mr = testing_helpers.MakeMonorailRequest( |
| 134 path='/p/proj/issues/entry') |
| 135 config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id) |
| 136 |
| 137 templ = issueentry._SelectTemplate(None, config, False) |
| 138 self.assertEquals('Defect report from user', templ.name) |
| 139 |
| 140 templ = issueentry._SelectTemplate(None, config, True) |
| 141 self.assertEquals('Defect report from developer', templ.name) |
| 142 |
| 143 |
| 144 if __name__ == '__main__': |
| 145 unittest.main() |
OLD | NEW |