Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/tracker/test/issueadmin_test.py b/tracker/test/issueadmin_test.py
index c36a495..c19a21d 100644
--- a/tracker/test/issueadmin_test.py
+++ b/tracker/test/issueadmin_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.
 
 """Tests for the issue admin pages."""
 from __future__ import print_function
@@ -12,13 +11,15 @@
   from mox3 import mox
 except ImportError:
   import mox
+import six
 import unittest
 
+import settings
 from mock import Mock, patch
 
 from framework import permissions
 from framework import urls
-from proto import tracker_pb2
+from mrproto import tracker_pb2
 from services import service_manager
 from services import template_svc
 from testing import fake
@@ -39,7 +40,7 @@
         issue=fake.IssueService(),
         template=Mock(spec=template_svc.TemplateService),
         features=fake.FeaturesService())
-    self.servlet = servlet_factory('req', 'res', services=self.services)
+    self.servlet = servlet_factory(services=self.services)
     self.project = self.services.project.TestAddProject(
         'proj', project_id=789, contrib_ids=[333])
     self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
@@ -47,6 +48,8 @@
     self.cnxn = fake.MonorailConnection()
     self.mr = testing_helpers.MakeMonorailRequest(
         path='/p/proj/admin', project=self.project)
+    # Default to admin perms given that most tests assume the user can edit.
+    self.mr.perms = permissions.ADMIN_PERMISSIONSET
     self.mox = mox.Mox()
     self.test_template = tracker_bizobj.MakeIssueTemplate(
         'Test Template', 'sum', 'New', 111, 'content', [], [], [], [])
@@ -58,6 +61,8 @@
     self.services.template.GetTemplateSetForProject\
         .return_value = [(12345, 'Test template', 0)]
 
+    settings.config_freeze_project_ids = {}
+
   def tearDown(self):
     self.mox.UnsetStubs()
     self.mox.ResetAll()
@@ -80,9 +85,11 @@
     page_data = self.servlet.GatherPageData(self.mr)
     self.mox.VerifyAll()
 
-    self.assertItemsEqual(
-        ['admin_tab_mode', 'config', 'open_text', 'closed_text', 'labels_text'],
-        list(page_data.keys()))
+    six.assertCountEqual(
+        self, [
+            'admin_tab_mode', 'config', 'open_text', 'closed_text',
+            'labels_text', 'can_edit_project'
+        ], list(page_data.keys()))
     config_view = page_data['config']
     self.assertEqual(789, config_view.project_id)
 
@@ -91,6 +98,7 @@
 
   def setUp(self):
     super(AdminStatusesTest, self).setUpServlet(issueadmin.AdminStatuses)
+    self.servlet.mr = self.mr
 
   @patch('framework.servlet.Servlet.PleaseCorrect')
   def testProcessSubtabForm_MissingInput(self, mock_pc):
@@ -143,10 +151,11 @@
     page_data = self.servlet.GatherPageData(self.mr)
     self.mox.VerifyAll()
 
-    self.assertItemsEqual(
-        ['admin_tab_mode', 'config', 'field_defs',
-         'open_text', 'closed_text', 'labels_text'],
-        list(page_data.keys()))
+    six.assertCountEqual(
+        self, [
+            'admin_tab_mode', 'config', 'field_defs', 'open_text',
+            'closed_text', 'labels_text', 'can_edit_project'
+        ], list(page_data.keys()))
     config_view = page_data['config']
     self.assertEqual(789, config_view.project_id)
     self.assertEqual([], page_data['field_defs'])
@@ -300,11 +309,12 @@
     self.mox.ReplayAll()
     page_data = self.servlet.GatherPageData(self.mr)
     self.mox.VerifyAll()
-    self.assertItemsEqual(
-        ['admin_tab_mode', 'failed_templ', 'component_defs', 'failed_perm',
-         'config', 'failed_subcomp',
-         'open_text', 'closed_text', 'labels_text'],
-        list(page_data.keys()))
+    six.assertCountEqual(
+        self, [
+            'admin_tab_mode', 'failed_templ', 'component_defs', 'failed_perm',
+            'config', 'failed_subcomp', 'open_text', 'closed_text',
+            'labels_text', 'can_edit_project'
+        ], list(page_data.keys()))
     config_view = page_data['config']
     self.assertEqual(789, config_view.project_id)
     self.assertEqual([], page_data['component_defs'])
@@ -367,11 +377,12 @@
     page_data = self.servlet.GatherPageData(self.mr)
     self.mox.VerifyAll()
 
-    self.assertItemsEqual(
-        ['canned_queries', 'admin_tab_mode', 'config', 'issue_notify',
-         'new_query_indexes', 'max_queries',
-         'open_text', 'closed_text', 'labels_text'],
-        list(page_data.keys()))
+    six.assertCountEqual(
+        self, [
+            'canned_queries', 'admin_tab_mode', 'config', 'issue_notify',
+            'new_query_indexes', 'max_queries', 'open_text', 'closed_text',
+            'labels_text', 'can_edit_project'
+        ], list(page_data.keys()))
     config_view = page_data['config']
     self.assertEqual(789, config_view.project_id)
 
@@ -424,8 +435,9 @@
     self.assertEqual('label1-sub1', y_attr)
 
     # Test that multibyte strings are not mangled.
-    spec = ('\xe7\xaa\xbf\xe8\x8b\xa5-\xe7\xb9\xb9 '
-            '\xe5\x9c\xb0\xe3\x81\xa6-\xe5\xbd\x93-\xe3\x81\xbe\xe3\x81\x99')
+    spec = (
+        b'\xe7\xaa\xbf\xe8\x8b\xa5-\xe7\xb9\xb9 '
+        b'\xe5\x9c\xb0\xe3\x81\xa6-\xe5\xbd\x93-\xe3\x81\xbe\xe3\x81\x99')
     spec = spec.decode('utf-8')
     (col_spec, sort_spec, x_attr, y_attr, member_default_query,
      ) = issueadmin._ParseListPreferences(
@@ -437,10 +449,10 @@
         )
     self.assertEqual(spec, col_spec)
     self.assertEqual(' '.join(spec.split()), sort_spec)
-    self.assertEqual('\xe7\xaa\xbf\xe8\x8b\xa5-\xe7\xb9\xb9'.decode('utf-8'),
-                     x_attr)
-    self.assertEqual('\xe7\xaa\xbf\xe8\x8b\xa5-\xe7\xb9\xb9'.decode('utf-8'),
-                     y_attr)
+    self.assertEqual(
+        b'\xe7\xaa\xbf\xe8\x8b\xa5-\xe7\xb9\xb9'.decode('utf-8'), x_attr)
+    self.assertEqual(
+        b'\xe7\xaa\xbf\xe8\x8b\xa5-\xe7\xb9\xb9'.decode('utf-8'), y_attr)
     self.assertEqual(spec, member_default_query)
 
 
@@ -455,10 +467,12 @@
     page_data = self.servlet.GatherPageData(self.mr)
     self.mox.VerifyAll()
 
-    self.assertItemsEqual(
-        ['admin_tab_mode', 'config', 'rules', 'new_rule_indexes',
-         'max_rules', 'open_text', 'closed_text', 'labels_text'],
-        list(page_data.keys()))
+    six.assertCountEqual(
+        self, [
+            'admin_tab_mode', 'config', 'rules', 'new_rule_indexes',
+            'max_rules', 'open_text', 'closed_text', 'labels_text',
+            'can_edit_project'
+        ], list(page_data.keys()))
     config_view = page_data['config']
     self.assertEqual(789, config_view.project_id)
     self.assertEqual([], page_data['rules'])