Merge branch 'main' into avm99963-monorail
Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266
GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/tracker/test/issueattachment_test.py b/tracker/test/issueattachment_test.py
index f782f22..0330e19 100644
--- a/tracker/test/issueattachment_test.py
+++ b/tracker/test/issueattachment_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 monorail.tracker.issueattachment."""
from __future__ import print_function
@@ -16,11 +15,10 @@
from mox3 import mox
except ImportError:
import mox
-import webapp2
-from framework import gcs_helpers
+from framework import exceptions, gcs_helpers
from framework import permissions
-from proto import tracker_pb2
+from mrproto import tracker_pb2
from services import service_manager
from testing import fake
from testing import testing_helpers
@@ -45,8 +43,7 @@
issue=fake.IssueService(),
user=fake.UserService())
self.project = services.project.TestAddProject('proj')
- self.servlet = issueattachment.AttachmentPage(
- 'req', webapp2.Response(), services=services)
+ self.servlet = issueattachment.AttachmentPage(services=services)
services.user.TestAddUser('commenter@example.com', 111)
self.issue = fake.MakeTestIssue(
self.project.project_id, 1, 'summary', 'New', 111)
@@ -79,7 +76,7 @@
_request, mr = testing_helpers.GetRequestObjects(
project=self.project, path=path,
perms=permissions.EMPTY_PERMISSIONSET)
- with self.assertRaises(webapp2.HTTPException) as cm:
+ with self.assertRaises(Exception) as cm:
self.servlet.GatherPageData(mr)
self.assertEqual(404, cm.exception.code)
@@ -125,18 +122,17 @@
'app_default_bucket',
'/pid/attachments/object_id-download'
).AndReturn('googleusercontent.com/...-download...')
- self.mox.StubOutWithMock(self.servlet, 'redirect')
path = '/p/proj/issues/attachment?aid=%s&signed_aid=signed_%d' % (
aid, aid)
_request, mr = testing_helpers.GetRequestObjects(
project=self.project, path=path,
perms=permissions.READ_ONLY_PERMISSIONSET) # includes VIEW
- self.servlet.redirect(
- mox.And(mox.StrContains('googleusercontent.com'),
- mox.StrContains('-download')), abort=True)
self.mox.ReplayAll()
- self.servlet.GatherPageData(mr)
+ with self.assertRaises(exceptions.RedirectException) as e:
+ self.servlet.GatherPageData(mr)
self.mox.VerifyAll()
+ self.assertIn('googleusercontent.com', str(e.exception))
+ self.assertIn('-download', str(e.exception))
def testGatherPageData_Download_WithoutDisposition(self):
aid = self.attachment.attachment_id
@@ -152,16 +148,15 @@
'app_default_bucket',
'/pid/attachments/object_id'
).AndReturn('googleusercontent.com/...')
- self.mox.StubOutWithMock(self.servlet, 'redirect')
_request, mr = testing_helpers.GetRequestObjects(
project=self.project, path=path,
perms=permissions.READ_ONLY_PERMISSIONSET) # includes VIEW
- self.servlet.redirect(
- mox.And(mox.StrContains('googleusercontent.com'),
- mox.Not(mox.StrContains('-download'))), abort=True)
self.mox.ReplayAll()
- self.servlet.GatherPageData(mr)
+ with self.assertRaises(exceptions.RedirectException) as e:
+ self.servlet.GatherPageData(mr)
self.mox.VerifyAll()
+ self.assertIn('googleusercontent.com', str(e.exception))
+ self.assertNotIn('-download', str(e.exception))
def testGatherPageData_DownloadBadFilename(self):
aid = self.attachment.attachment_id
@@ -179,14 +174,12 @@
'app_default_bucket',
'/pid/attachments/object_id-download'
).AndReturn('googleusercontent.com/...-download...')
- self.mox.StubOutWithMock(self.servlet, 'redirect')
_request, mr = testing_helpers.GetRequestObjects(
project=self.project,
path=path,
perms=permissions.READ_ONLY_PERMISSIONSET) # includes VIEW
- self.servlet.redirect(mox.And(
- mox.Not(mox.StrContains(self.attachment.filename)),
- mox.StrContains('googleusercontent.com')), abort=True)
self.mox.ReplayAll()
- self.servlet.GatherPageData(mr)
+ with self.assertRaises(exceptions.RedirectException) as e:
+ self.servlet.GatherPageData(mr)
self.mox.VerifyAll()
+ self.assertIn('googleusercontent.com', str(e.exception))