Merge branch 'main' into avm99963-monorail
Merged commit cd4b3b336f1f14afa02990fdc2eec5d9467a827e
GitOrigin-RevId: e67bbf185d5538e1472bb42e0abb2a141f88bac1
diff --git a/tracker/test/issueattachment_test.py b/tracker/test/issueattachment_test.py
index 8c65014..9fccba5 100644
--- a/tracker/test/issueattachment_test.py
+++ b/tracker/test/issueattachment_test.py
@@ -10,7 +10,6 @@
import unittest
-from google.appengine.api import images
from google.appengine.ext import testbed
import mox
@@ -18,16 +17,12 @@
from framework import gcs_helpers
from framework import permissions
-from framework import servlet
from proto import tracker_pb2
from services import service_manager
from testing import fake
from testing import testing_helpers
from tracker import attachment_helpers
from tracker import issueattachment
-from tracker import tracker_helpers
-
-from third_party import cloudstorage
class IssueattachmentTest(unittest.TestCase):
@@ -41,9 +36,6 @@
self.testbed.init_urlfetch_stub()
self.attachment_data = ""
- self._old_gcs_open = cloudstorage.open
- cloudstorage.open = fake.gcs_open
-
services = service_manager.Services(
project=fake.ProjectService(),
config=fake.ConfigService(),
@@ -74,7 +66,6 @@
self.mox.UnsetStubs()
self.mox.ResetAll()
self.testbed.deactivate()
- cloudstorage.open = self._old_gcs_open
attachment_helpers.SignAttachmentID = self.orig_sign_attachment_id
def testGatherPageData_NotFound(self):
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,