blob: b2a7536f80f80ae506da19ddbd8b9e0959892929 [file] [log] [blame]
# 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 the issueentry servlet."""
import mox
import unittest
from framework import framework_views
from framework import permissions
from services import service_manager
from testing import fake
from testing import testing_helpers
from tracker import issueentry
from google.appengine.ext import testbed
class IssueEntryTest(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_taskqueue_stub()
self.testbed.init_memcache_stub()
self.testbed.init_datastore_v3_stub()
self.services = service_manager.Services(
config=fake.ConfigService(),
issue=fake.IssueService(),
user=fake.UserService(),
project=fake.ProjectService())
self.project = self.services.project.TestAddProject('proj', project_id=987)
self.servlet = issueentry.IssueEntry(
'req', 'res', services=self.services)
self.mox = mox.Mox()
def tearDown(self):
self.mox.UnsetStubs()
self.mox.ResetAll()
def testAssertBasePermission(self):
"""Permit users with CREATE_ISSUE."""
mr = testing_helpers.MakeMonorailRequest(
path='/p/proj/issues/entry', services=self.services,
perms=permissions.EMPTY_PERMISSIONSET)
self.assertRaises(permissions.PermissionException,
self.servlet.AssertBasePermission, mr)
mr = testing_helpers.MakeMonorailRequest(
path='/p/proj/issues/entry', services=self.services,
perms=permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET)
self.servlet.AssertBasePermission(mr)
def testDiscardUnusedTemplateLabelPrefixes(self):
labels = ['pre-val', 'other-value', 'oneword', 'x', '-y', '-w-z', '', '-']
self.assertEqual(labels,
issueentry._DiscardUnusedTemplateLabelPrefixes(labels))
labels = ['prefix-value', 'other-?', 'third-', '', '-', '-?']
self.assertEqual(['prefix-value', 'third-', '', '-'],
issueentry._DiscardUnusedTemplateLabelPrefixes(labels))
def testGatherPageData(self):
mr = testing_helpers.MakeMonorailRequest(
path='/p/proj/issues/entry', services=self.services)
mr.auth.user_view = framework_views.UserView(100, 'user@invalid', True)
user = self.services.user.TestAddUser('user@invalid', 100)
self.mox.StubOutWithMock(self.services.user, 'GetUser')
self.services.user.GetUser(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(user)
self.mox.ReplayAll()
page_data = self.servlet.GatherPageData(mr)
self.mox.VerifyAll()
self.assertEqual(page_data['initial_owner'], 'user@invalid')
self.assertEqual(page_data['initial_status'], 'New')
self.assertTrue(page_data['clear_summary_on_click'])
self.assertTrue(page_data['must_edit_summary'])
def testGatherPageData_TemplateAllowsKeepingSummary(self):
mr = testing_helpers.MakeMonorailRequest(
path='/p/proj/issues/entry', services=self.services)
mr.auth.user_view = framework_views.UserView(100, 'user@invalid', True)
user = self.services.user.TestAddUser('user@invalid', 100)
self.mox.StubOutWithMock(self.services.user, 'GetUser')
self.services.user.GetUser(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(user)
self.mox.ReplayAll()
config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id)
self.services.config.StoreConfig(mr.cnxn, config)
config.templates[1].summary_must_be_edited = False
page_data = self.servlet.GatherPageData(mr)
self.mox.VerifyAll()
self.assertEqual(page_data['initial_owner'], 'user@invalid')
self.assertEqual(page_data['initial_status'], 'New')
self.assertFalse(page_data['clear_summary_on_click'])
self.assertFalse(page_data['must_edit_summary'])
def testGatherPageData_DeepLinkSetsSummary(self):
mr = testing_helpers.MakeMonorailRequest(
path='/p/proj/issues/entry?summary=foo', services=self.services)
mr.auth.user_view = framework_views.UserView(100, 'user@invalid', True)
user = self.services.user.TestAddUser('user@invalid', 100)
self.mox.StubOutWithMock(self.services.user, 'GetUser')
self.services.user.GetUser(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(user)
self.mox.ReplayAll()
page_data = self.servlet.GatherPageData(mr)
self.mox.VerifyAll()
self.assertEqual(page_data['initial_owner'], 'user@invalid')
self.assertEqual(page_data['initial_status'], 'New')
self.assertFalse(page_data['clear_summary_on_click'])
self.assertTrue(page_data['must_edit_summary'])
def testProcessFormData(self):
mr = testing_helpers.MakeMonorailRequest(
path='/p/proj/issues/entry')
mr.auth.user_view = framework_views.UserView(100, 'user@invalid', True)
mr.perms = []
post_data = fake.PostData(
summary=['fake summary'],
comment=['fake comment'],
status=['New'])
url = self.servlet.ProcessFormData(mr, post_data)
self.assertTrue('/p/proj/issues/detail?id=' in url)
def test_SelectTemplate(self):
mr = testing_helpers.MakeMonorailRequest(
path='/p/proj/issues/entry')
config = self.services.config.GetProjectConfig(mr.cnxn, mr.project_id)
templ = issueentry._SelectTemplate(None, config, False)
self.assertEquals('Defect report from user', templ.name)
templ = issueentry._SelectTemplate(None, config, True)
self.assertEquals('Defect report from developer', templ.name)
if __name__ == '__main__':
unittest.main()