def test_post(self):
        request = webapp2.Request.blank('/blobstore',
                                        method='POST',
                                        POST=multidict.MultiDict([
                                            ('blob_key', 'a'),
                                            ('blob_key', 'b')
                                        ]))
        response = webapp2.Response()
        handler = blobstore_viewer.BlobstoreRequestHandler(request, response)

        self.mox.StubOutWithMock(blobstore, 'delete')
        blobstore.delete(['a', 'b'])

        self.mox.ReplayAll()
        handler.post()
        self.mox.VerifyAll()
        self.assertEqual(302, response.status_int)
        self.assertEqual('http://localhost/blobstore',
                         response.headers.get('Location'))
    def test_get_with_offset(self):
        request = webapp2.Request.blank('/blobstore?offset=40')
        response = webapp2.Response()
        handler = blobstore_viewer.BlobstoreRequestHandler(request, response)

        blob_infos = [object() for _ in range(10)]
        blobstore_viewer._get_blobs(40,
                                    BLOBS_PER_PAGE + 1).AndReturn(blob_infos)
        handler.render(
            'blobstore_viewer.html', {
                'previous': 20,
                'next': None,
                'blob_infos': blob_infos,
                'offset': 40,
                'return_to': 'http://localhost/blobstore?offset=40',
            })

        self.mox.ReplayAll()
        handler.get()
        self.mox.VerifyAll()
    def test_get_with_data_in_next_page(self):
        request = webapp2.Request.blank('/blobstore')
        response = webapp2.Response()
        handler = blobstore_viewer.BlobstoreRequestHandler(request, response)

        blob_infos = [object() for _ in range(BLOBS_PER_PAGE + 1)]
        blobstore_viewer._get_blobs(0,
                                    BLOBS_PER_PAGE + 1).AndReturn(blob_infos)
        admin_request_handler.AdminRequestHandler(handler).get()
        handler.render(
            'blobstore_viewer.html', {
                'previous': None,
                'next': 20,
                'blob_infos': blob_infos[:BLOBS_PER_PAGE],
                'offset': 0,
                'return_to': 'http://localhost/blobstore',
            })

        self.mox.ReplayAll()
        handler.get()
        self.mox.VerifyAll()