Пример #1
0
 def test_ims(self):
     """ SendFile: If-Modified-Since"""
     request.environ['HTTP_IF_MODIFIED_SINCE'] = bottle.http_date(time.time())
     res = static_file(basename, root=root)
     self.assertEqual(304, res.status_code)
     self.assertEqual(int(os.stat(__file__).st_mtime), parse_date(res.headers['Last-Modified']))
     self.assertAlmostEqual(int(time.time()), parse_date(res.headers['Date']))
     request.environ['HTTP_IF_MODIFIED_SINCE'] = bottle.http_date(100)
     self.assertEqual(open(__file__,'rb').read(), static_file(basename, root=root).body.read())
Пример #2
0
    def test_download(self):
        """ SendFile: Download as attachment """
        f = static_file(basename, root=root, download="foo.mp3")
        self.assertEqual('audio/mpeg', f.headers['Content-Type'])

        f = static_file(basename, root=root, download=True)
        self.assertEqual('attachment; filename="%s"' % basename, f.headers['Content-Disposition'])
        request.environ['HTTP_IF_MODIFIED_SINCE'] = bottle.http_date(100)

        f = static_file(basename, root=root)
        self.assertEqual(open(__file__,'rb').read(), f.body.read())
Пример #3
0
 def test_rfc1123(self):
     """DateParser: RFC 1123 format"""
     ts = time.time()
     rs = bottle.http_date(ts)
     self.assertEqual(int(ts), int(parse_date(rs)))