diff options
Diffstat (limited to 'test/test_sendfile.py')
-rwxr-xr-x | test/test_sendfile.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/test/test_sendfile.py b/test/test_sendfile.py index 6872e4d..622d992 100755 --- a/test/test_sendfile.py +++ b/test/test_sendfile.py @@ -13,23 +13,29 @@ basename2 = os.path.basename(bottle.__file__) root2 = os.path.dirname(bottle.__file__) +weekday_full = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] +weekday_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] +month_abbr = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] + class TestDateParser(unittest.TestCase): def test_rfc1123(self): """DateParser: RFC 1123 format""" ts = time.time() - rs = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(ts)) + rs = bottle.http_date(ts) self.assertEqual(int(ts), int(parse_date(rs))) def test_rfc850(self): """DateParser: RFC 850 format""" ts = time.time() - rs = time.strftime("%A, %d-%b-%y %H:%M:%S GMT", time.gmtime(ts)) + t = time.gmtime(ts) + rs = time.strftime("%%s, %d-%%s-%y %H:%M:%S GMT", t) % (weekday_full[t.tm_wday], month_abbr[t.tm_mon]) self.assertEqual(int(ts), int(parse_date(rs))) def test_asctime(self): """DateParser: asctime format""" ts = time.time() - rs = time.strftime("%a %b %d %H:%M:%S %Y", time.gmtime(ts)) + t = time.gmtime(ts) + rs = time.strftime("%%s %%s %d %H:%M:%S %Y", t) % (weekday_abbr[t.tm_wday], month_abbr[t.tm_mon]) self.assertEqual(int(ts), int(parse_date(rs))) def test_bad(self): @@ -81,12 +87,12 @@ class TestSendFile(unittest.TestCase): def test_ims(self): """ SendFile: If-Modified-Since""" - request.environ['HTTP_IF_MODIFIED_SINCE'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()) + 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'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(100)) + request.environ['HTTP_IF_MODIFIED_SINCE'] = bottle.http_date(100) self.assertEqual(open(__file__,'rb').read(), static_file(basename, root=root).body.read()) def test_etag(self): @@ -116,7 +122,7 @@ class TestSendFile(unittest.TestCase): f = static_file(basename, root=root, download=True) self.assertEqual('attachment; filename="%s"' % basename, f.headers['Content-Disposition']) - request.environ['HTTP_IF_MODIFIED_SINCE'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(100)) + 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()) |