Merge branch 'main' into avm99963-monorail
Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266
GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/tracker/test/issuebulkedit_test.py b/tracker/test/issuebulkedit_test.py
index 89d9bc3..c7bd1ca 100644
--- a/tracker/test/issuebulkedit_test.py
+++ b/tracker/test/issuebulkedit_test.py
@@ -1,7 +1,6 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file or at
-# https://developers.google.com/open-source/licenses/bsd
+# Copyright 2016 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
"""Unittests for monorail.tracker.issuebulkedit."""
from __future__ import print_function
@@ -11,14 +10,15 @@
import mock
import os
import unittest
-import webapp2
+import flask
from google.appengine.api import memcache
from google.appengine.ext import testbed
from framework import exceptions
from framework import permissions
-from proto import tracker_pb2
+from mrproto import project_pb2
+from mrproto import tracker_pb2
from services import service_manager
from services import tracker_fulltext
from testing import fake
@@ -45,8 +45,7 @@
issue_star=fake.IssueStarService(),
user=fake.UserService(),
usergroup=fake.UserGroupService())
- self.servlet = issuebulkedit.IssueBulkEdit(
- 'req', 'res', services=self.services)
+ self.servlet = issuebulkedit.IssueBulkEdit(services=self.services)
self.mr = testing_helpers.MakeMonorailRequest(
perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
self.project = self.services.project.TestAddProject(
@@ -177,8 +176,7 @@
project=self.project)
mr.local_id_list = [local_id_1]
- self.assertRaises(webapp2.HTTPException,
- self.servlet.GatherPageData, mr)
+ self.assertRaises(Exception, self.servlet.GatherPageData, mr)
def testGatherPageData_TypeLabels(self):
"""Test that GPD displays a custom field for appropriate issues."""
@@ -226,6 +224,38 @@
url = self.servlet.ProcessFormData(mr, post_data)
self.assertTrue('list?can=1&q=&saved=1' in url)
+ def testProcessFormData_FreezeLabels(self):
+ """Test that PFD works in a normal no-corner-cases case."""
+ created_issue_1 = fake.MakeTestIssue(
+ 789, 1, 'issue summary', 'New', 111, reporter_id=111)
+ self.services.issue.TestAddIssue(created_issue_1)
+ local_id_1 = created_issue_1.local_id
+
+ mr = testing_helpers.MakeMonorailRequest(
+ project=self.project,
+ perms=permissions.OWNER_ACTIVE_PERMISSIONSET,
+ user_info={'user_id': 111})
+ mr.local_id_list = [local_id_1]
+
+ post_data = fake.PostData(
+ owner=['owner@example.com'],
+ can=[1],
+ q=[''],
+ colspec=[''],
+ sort=[''],
+ groupby=[''],
+ start=[0],
+ num=[100],
+ label=['freeze_new_label'])
+ self._MockMethods()
+ self.servlet.response = flask.Response()
+ self.servlet.ProcessFormData(mr, post_data)
+ self.assertEqual(
+ (
+ "The creation of new labels is blocked for the Chromium project"
+ " in Monorail. To continue with editing your issue, please"
+ " remove: freeze_new_label label(s)."), mr.errors.labels)
+
def testProcessFormData_NoIssues(self):
"""Test PFD when no issues are specified."""
mr = testing_helpers.MakeMonorailRequest(
@@ -233,10 +263,10 @@
perms=permissions.OWNER_ACTIVE_PERMISSIONSET,
user_info={'user_id': 111})
post_data = fake.PostData()
- self.servlet.response = Response()
+ self.servlet.response = flask.Response()
self.servlet.ProcessFormData(mr, post_data)
# 400 == bad request
- self.assertEqual(400, self.servlet.response.status)
+ self.assertEqual(400, self.servlet.response.status_code)
def testProcessFormData_NoUser(self):
"""Test PFD when the user is not logged in."""
@@ -244,10 +274,10 @@
project=self.project)
mr.local_id_list = [99999]
post_data = fake.PostData()
- self.servlet.response = Response()
+ self.servlet.response = flask.Response()
self.servlet.ProcessFormData(mr, post_data)
# 400 == bad request
- self.assertEqual(400, self.servlet.response.status)
+ self.assertEqual(400, self.servlet.response.status_code)
def testProcessFormData_CantComment(self):
"""Test PFD when the user can't comment on any of the issues."""
@@ -257,10 +287,10 @@
user_info={'user_id': 111})
mr.local_id_list = [99999]
post_data = fake.PostData()
- self.servlet.response = Response()
+ self.servlet.response = flask.Response()
self.servlet.ProcessFormData(mr, post_data)
# 400 == bad request
- self.assertEqual(400, self.servlet.response.status)
+ self.assertEqual(400, self.servlet.response.status_code)
def testProcessFormData_CantEdit(self):
"""Test PFD when the user can't edit any issue metadata."""
@@ -270,10 +300,10 @@
user_info={'user_id': 111})
mr.local_id_list = [99999]
post_data = fake.PostData()
- self.servlet.response = Response()
+ self.servlet.response = flask.Response()
self.servlet.ProcessFormData(mr, post_data)
# 400 == bad request
- self.assertEqual(400, self.servlet.response.status)
+ self.assertEqual(400, self.servlet.response.status_code)
def testProcessFormData_CantMove(self):
"""Test PFD when the user can't move issues."""
@@ -283,10 +313,10 @@
user_info={'user_id': 111})
mr.local_id_list = [99999]
post_data = fake.PostData(move_to=['proj'])
- self.servlet.response = Response()
+ self.servlet.response = flask.Response()
self.servlet.ProcessFormData(mr, post_data)
# 400 == bad request
- self.assertEqual(400, self.servlet.response.status)
+ self.assertEqual(400, self.servlet.response.status_code)
created_issue_1 = fake.MakeTestIssue(
789, 1, 'issue summary', 'New', 111, reporter_id=111)
@@ -699,7 +729,7 @@
# Verify CC lists and owner were merged to the merge_into issue.
self.assertEqual(
- [113, 120, 114, 115, 118, 111], merge_into_issue.cc_ids)
+ [113, 120, 111, 114, 115, 118], merge_into_issue.cc_ids)
# Verify new starrers were added to the merge_into issue.
self.assertEqual(4,
self.services.issue_star.CountItemStars(
@@ -801,7 +831,7 @@
self.assertEqual('Invalid issue ID 54321', mr.errors.blocking)
def testProcessFormData_BlockIssuesOnItself(self):
- """Test PFD processes invalid blocked_on and blocking values."""
+ """Test PFD processes same issue blocked_on and blocking values."""
created_issue_1 = fake.MakeTestIssue(
789, 1, 'issue summary', 'New', 111, reporter_id=111)
self.services.issue.TestAddIssue(created_issue_1)
@@ -828,6 +858,49 @@
self.assertEqual('Cannot block an issue on itself.', mr.errors.blocked_on)
self.assertEqual('Cannot block an issue on itself.', mr.errors.blocking)
+ def testProcessFormData_BlockIssuesOnArchivedProject(self):
+ """Test PFD processes blocked_on and blocking issues without permissions."""
+ created_issue_1 = fake.MakeTestIssue(
+ 789, 1, 'issue summary', 'New', 111, reporter_id=111)
+ self.services.issue.TestAddIssue(created_issue_1)
+ local_id_1 = created_issue_1.local_id
+ # Add issue to archived project.
+ archived_proj = self.services.project.TestAddProject(
+ name='archived-proj', project_id=789987, owner_ids=[111])
+ archived_proj.state = project_pb2.ProjectState.ARCHIVED
+ archived_iid = 2
+ created_issue_2 = fake.MakeTestIssue(
+ 789987, archived_iid, 'issue summary', 'New', 111, reporter_id=111)
+ self.services.issue.TestAddIssue(created_issue_2)
+ mr = testing_helpers.MakeMonorailRequest(
+ project=self.project,
+ perms=permissions.OWNER_ACTIVE_PERMISSIONSET,
+ user_info={'user_id': 111})
+ mr.project_name = 'proj'
+ mr.local_id_list = [local_id_1]
+
+ global_id = 'archived-proj:2'
+ self._MockMethods()
+ post_data = fake.PostData(
+ op_blockedonenter=['append'],
+ blocked_on=[global_id],
+ op_blockingenter=['append'],
+ blocking=[global_id],
+ can=[1],
+ q=[''],
+ colspec=[''],
+ sort=[''],
+ groupby=[''],
+ start=[0],
+ num=[100])
+ self.servlet.ProcessFormData(mr, post_data)
+
+ self.assertEqual(
+ 'Target issue %s cannot be modified' % archived_iid,
+ mr.errors.blocked_on)
+ self.assertEqual(
+ 'Target issue %s cannot be modified' % archived_iid, mr.errors.blocking)
+
@mock.patch('framework.cloud_tasks_helpers.create_task')
def testProcessFormData_NormalBlockIssues(self, _create_task_mock):
"""Test PFD processes blocked_on and blocking values."""