Merge branch 'main' into avm99963-monorail

Merged commit cd4b3b336f1f14afa02990fdc2eec5d9467a827e

GitOrigin-RevId: e67bbf185d5538e1472bb42e0abb2a141f88bac1
diff --git a/tracker/test/issueattachmenttext_test.py b/tracker/test/issueattachmenttext_test.py
index 187aa42..f7dda8d 100644
--- a/tracker/test/issueattachmenttext_test.py
+++ b/tracker/test/issueattachmenttext_test.py
@@ -8,18 +8,15 @@
 from __future__ import division
 from __future__ import absolute_import
 
-import logging
+import mock
 import unittest
-from mock import patch
 
-from google.appengine.ext import testbed
-
-from third_party import cloudstorage
 import ezt
+from google.appengine.ext import testbed
+from google.cloud import storage
 
 import webapp2
 
-from framework import filecontent
 from framework import permissions
 from proto import tracker_pb2
 from services import service_manager
@@ -85,12 +82,18 @@
     services.issue.TestAddAttachment(
         self.attach1, self.comment1.id, self.issue.issue_id)
     # TODO(jrobbins): add tests for binary content
-    self._old_gcs_open = cloudstorage.open
-    cloudstorage.open = fake.gcs_open
+
+    self.client = mock.MagicMock()
+    self.bucket = mock.MagicMock()
+    self.blob = mock.MagicMock()
+    self.client.get_bucket = mock.MagicMock(return_value=self.bucket)
+    self.bucket.get_blob = mock.MagicMock(return_value=self.blob)
+    self.blob.download_as_bytes = mock.MagicMock()
+    mock.patch.object(storage, 'Client', return_value=self.client).start()
 
   def tearDown(self):
     self.testbed.deactivate()
-    cloudstorage.open = self._old_gcs_open
+    mock.patch.stopall()
 
   def testGatherPageData_CommentDeleted(self):
     """If the attachment's comment was deleted, give a 403."""
@@ -155,6 +158,9 @@
     self.assertEqual(404, cm.exception.code)
 
   def testGatherPageData_Normal(self):
+    self.blob.download_as_bytes = mock.MagicMock(
+        return_value='/app_default_bucket/pid/attachments/abcdefg')
+
     _request, mr = testing_helpers.GetRequestObjects(
         project=self.project,
         path='/p/proj/issues/attachmentText?id=1&aid=1234',
@@ -175,7 +181,7 @@
 
     self.assertEqual(None, page_data['code_reviews'])
 
-  @patch('framework.filecontent.DecodeFileContents')
+  @mock.patch('framework.filecontent.DecodeFileContents')
   def testGatherPageData_HugeFile(self, mock_DecodeFileContents):
     _request, mr = testing_helpers.GetRequestObjects(
         project=self.project,