summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorcce <devnull@localhost>2005-12-23 21:36:37 +0000
committercce <devnull@localhost>2005-12-23 21:36:37 +0000
commit370ba732f785cc211e850664ecfea6a62fea30b4 (patch)
treebbc6b3281820448e64ada2ae5c45e39a0170e15a /tests
parentdb53428a989dca0526d5f6a4bad5c91424424ea1 (diff)
downloadpaste-370ba732f785cc211e850664ecfea6a62fea30b4.tar.gz
- got rid of unnecessary trailing spaces in httpexceptions
- made error messages us \r\n rather than just \n in httpexceptions to comply with various browsers - added tests to check FileApp - added support for handling 100 Continue in httpserver - fixingup dumpenviron in wsgilib to dump message body - misc changes to fileapp (mostly documentation)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_exceptions/test_httpexceptions.py8
-rw-r--r--tests/test_fileapp.py71
2 files changed, 69 insertions, 10 deletions
diff --git a/tests/test_exceptions/test_httpexceptions.py b/tests/test_exceptions/test_httpexceptions.py
index 1c24a4a..60095ce 100644
--- a/tests/test_exceptions/test_httpexceptions.py
+++ b/tests/test_exceptions/test_httpexceptions.py
@@ -38,14 +38,14 @@ def test_template():
e.template = 'A %(ping)s and <b>%(pong)s</b> message.'
assert str(e).startswith("500 Internal Server Error")
assert e.plain({'ping': 'fun', 'pong': 'happy'}) == (
- '500 Internal Server Error\n'
- 'A fun and happy message.\n')
+ '500 Internal Server Error\r\n'
+ 'A fun and happy message.\r\n')
assert '<p>A fun and <b>happy</b> message.</p>' in \
e.html({'ping': 'fun', 'pong': 'happy'})
def test_iterator_application():
- """
- This tests to see that an iterator's exceptions are caught by
+ """
+ This tests to see that an iterator's exceptions are caught by
HTTPExceptionHandler
"""
def basic_found(environ, start_response):
diff --git a/tests/test_fileapp.py b/tests/test_fileapp.py
index ffb7143..8d8c1b3 100644
--- a/tests/test_fileapp.py
+++ b/tests/test_fileapp.py
@@ -3,6 +3,8 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
from paste.fileapp import *
from paste.fixture import *
+from rfc822 import parsedate_tz, mktime_tz
+import time
def test_data():
harness = TestApp(DataApp('mycontent'))
@@ -14,10 +16,28 @@ def test_data():
assert "<Response 200 OK 'bingles'>" == repr(harness.get("/"))
def test_cache():
- app = DataApp('mycontent')
- app.cache()
- harness = TestApp(app)
- res = harness.get("/")
+ def build(*args,**kwargs):
+ app = DataApp("SomeContent")
+ app.cache(*args,**kwargs)
+ return TestApp(app).get("/")
+ res = build()
+ assert 'public' == res.header('cache-control')
+ assert not res.header('expires',None)
+ res = build(private=True)
+ assert 'private' == res.header('cache-control')
+ assert mktime_tz(parsedate_tz(res.header('expires'))) < time.time()
+ res = build(no_cache=True)
+ assert 'no-cache' == res.header('cache-control')
+ assert mktime_tz(parsedate_tz(res.header('expires'))) < time.time()
+ res = build(max_age=60,s_maxage=30)
+ assert 'public, max-age=60, s-maxage=30' == res.header('cache-control')
+ expires = mktime_tz(parsedate_tz(res.header('expires')))
+ assert expires > time.time()+58 and expires < time.time()+61
+ res = build(private=True, max_age=60, no_transform=True, no_store=True)
+ reshead = res.header('cache-control')
+ assert 'private, no-store, no-transform, max-age=60' == reshead
+ expires = mktime_tz(parsedate_tz(res.header('expires')))
+ assert mktime_tz(parsedate_tz(res.header('expires'))) < time.time()
def test_modified():
harness = TestApp(DataApp('mycontent'))
@@ -28,8 +48,47 @@ def test_modified():
assert "<Response 304 Not Modified ''>" == repr(res)
res = harness.get("/",status=400,
headers={'if-modified-since': 'garbage'})
- assert 400 == res.status and "Bad Timestamp" in res.body
+ assert 400 == res.status and "ill-formed timestamp" in res.body
res = harness.get("/",status=400,
headers={'if-modified-since':
'Thu, 22 Dec 2030 01:01:01 GMT'})
- assert 400 == res.status and "Clock Time In Future" in res.body
+ assert 400 == res.status and "check your system clock" in res.body
+
+def test_file():
+ import random, string, os
+ tempfile = "test_fileapp.%s.txt" % (random.random())
+ content = string.letters * 20
+ file = open(tempfile,"w")
+ file.write(content)
+ file.close()
+ try:
+ from paste import fileapp
+ app = fileapp.FileApp(tempfile)
+ res = TestApp(app).get("/")
+ assert len(content) == int(res.header('content-length'))
+ assert 'text/plain' == res.header('content-type')
+ assert content == res.body
+ assert [content] == app.content # this is cashed
+ lastmod = res.header('last-modified')
+ print "updating", tempfile
+ file = open(tempfile,"a+")
+ file.write("0123456789")
+ file.close()
+ res = TestApp(app).get("/")
+ assert len(content)+10 == int(res.header('content-length'))
+ assert 'text/plain' == res.header('content-type')
+ assert content + "0123456789" == res.body
+ assert app.content # we are still cached
+ file = open(tempfile,"a+")
+ file.write("X" * fileapp.CACHE_SIZE) # exceed the cashe size
+ file.close()
+ res = TestApp(app).get("/")
+ newsize = fileapp.CACHE_SIZE + len(content)+10
+ assert newsize == int(res.header('content-length'))
+ assert newsize == len(res.body)
+ assert res.body.startswith(content) and res.body.endswith('X')
+ assert not app.content # we are no longer cached
+ finally:
+ import os
+ os.unlink(tempfile)
+