Agreed, the word "always" is questionable in this context. But a comparison "before/after" is a test is a bit difficult, I think. OK, I could monkey patch the view_class attribute of BugAttachmentFileNavigation so that it is again StreamOrRedirectLibraryFileAliasView, but I think a better comment and an
assertIsInstance() is sufficient:
def test_content_disposition_of_restricted_file(self):
# The content of restricted Librarian files for bug attachments
# is served by instances of SafeStreamOrRedirectLibraryFileAliasView
# which set the content disposition header of the HTTP response for
# to "attachment". lfa_with_parent = getMultiAdapter( (self.bugattachment.libraryfile, self.bugattachment), ILibraryFileAliasWithParent) lfa_with_parent.restricted = True self.bug.setPrivate(True, self.bug_owner) transaction.commit()
request = LaunchpadTestRequest() request.setTraversalStack(['foo.txt'])
navigation = BugAttachmentFileNavigation(self.bugattachment, request)
view = navigation.publishTraverse(request, '+files')
next_view, traversal_path = view.browserDefault(request) self.assertIsInstance( next_view, SafeStreamOrRedirectLibraryFileAliasView)
next_view() self.assertEqual( 'attachment', request.response.getHeader('Content-Disposition'))
Hi Māris,
Agreed, the word "always" is questionable in this context. But a comparison "before/after" is a test is a bit difficult, I think. OK, I could monkey patch the view_class attribute of BugAttachmentFi leNavigation so that it is again StreamOrRedirec tLibraryFileAli asView, but I think a better comment and an
assertIsInstance() is sufficient:
def test_content_ disposition_ of_restricted_ file(self) : irectLibraryFil eAliasView
lfa_with_ parent = getMultiAdapter(
(self. bugattachment. libraryfile, self.bugattachm ent),
ILibraryFi leAliasWithPare nt)
lfa_with_ parent. restricted = True
self.bug. setPrivate( True, self.bug_owner)
transaction. commit( ) quest()
request. setTraversalSta ck(['foo. txt']) leNavigation( self.bugattachm ent, request) publishTraverse (request, '+files') ault(request)
self.assertIsI nstance(
next_ view, SafeStreamOrRed irectLibraryFil eAliasView)
self.assertEqu al(
'attachmen t', request. response. getHeader( 'Content- Disposition' ))
# The content of restricted Librarian files for bug attachments
# is served by instances of SafeStreamOrRed
# which set the content disposition header of the HTTP response for
# to "attachment".
request = LaunchpadTestRe
navigation = BugAttachmentFi
view = navigation.
next_view, traversal_path = view.browserDef
next_view()