Skip to content

Instantly share code, notes, and snippets.

@groner
Created March 14, 2011 20:45
Show Gist options
  • Save groner/869840 to your computer and use it in GitHub Desktop.
Save groner/869840 to your computer and use it in GitHub Desktop.
webob tests to uncovered by the removal of test_response.txt doctests
diff -r 61ba052831fa _test_mlk.py
--- a/_test_mlk.py Mon Mar 14 15:21:45 2011 -0400
+++ b/_test_mlk.py Mon Mar 14 16:44:25 2011 -0400
@@ -13,12 +13,12 @@
from mext.test_suite import TestSuite
suite = TestSuite('tests', coverage=True, pkg='webob')
-doctests = ['test_dec', 'test_request', 'test_response']
-doctests += map('../docs/'.__add__, ['do-it-yourself', 'file-example', 'index', 'reference'])
-map(suite.add_doctest, doctests)
+#doctests = ['test_dec', 'test_request', 'test_response']
+#doctests += map('../docs/'.__add__, ['do-it-yourself', 'file-example', 'index', 'reference'])
+#map(suite.add_doctest, doctests)
suite.add_unittest('test_multidict')
map(suite.add_nosetest, [
- 'test_request', 'test_response', 'test_headers',
+ 'test_request', 'test_response', 'test_response_txt', 'test_headers',
'test_cookies', 'test_exc',
'test_misc', 'test_datetime_utils',
])
diff -r 61ba052831fa tests/test_response_txt.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_response_txt.py Mon Mar 14 16:44:25 2011 -0400
@@ -0,0 +1,61 @@
+from datetime import datetime
+
+from nose.tools import eq_, ok_, assert_raises
+
+from webob import Request, Response, UTC
+
+
+def test_cache_control():
+ # covers webob/response.py:721-734, 761
+ res = Response()
+ eq_(repr(res.cache_control), "<CacheControl ''>")
+ eq_(res.cache_control.max_age, None)
+
+ res.cache_control.properties['max-age'] = None
+ eq_(res.cache_control.max_age, -1)
+
+ res.cache_control.max_age = 10
+ eq_(repr(res.cache_control), "<CacheControl 'max-age=10'>")
+ eq_(res.headers['cache-control'], 'max-age=10')
+
+ assert_raises(AttributeError, setattr, res.cache_control, 'max_stale', 10)
+
+ res.cache_control = {}
+ eq_(repr(res.cache_control), "<CacheControl ''>")
+
+ res.cache_expires = True
+ eq_(repr(res.cache_control), "<CacheControl 'max-age=0, must-revalidate, no-cache, no-store'>")
+
+def test_location():
+ # covers webob/response.py:934-938
+ res = Response()
+ res.location = '/test.html'
+ eq_(res.location, '/test.html')
+ req = Request.blank('/')
+ eq_(req.get_response(res).location, 'http://localhost/test.html')
+ res.location = '/test2.html'
+ eq_(req.get_response(res).location, 'http://localhost/test2.html')
+
+def test_request_uri_http():
+ # covers webob/response.py:1152
+ from webob.response import _request_uri
+ environ = {
+ 'wsgi.url_scheme': 'http',
+ 'SERVER_NAME': 'test.com',
+ 'SERVER_PORT': '80',
+ 'SCRIPT_NAME': '/foobar',
+ }
+ eq_(_request_uri(environ), 'http://test.com/foobar')
+
+def test_request_uri_no_script_name2():
+ # covers webob/response.py:1160
+ # There is a test_request_uri_no_script_name in test_response.py, but it
+ # sets SCRIPT_NAME.
+ from webob.response import _request_uri
+ environ = {
+ 'wsgi.url_scheme': 'http',
+ 'HTTP_HOST': 'test.com',
+ 'PATH_INFO': '/foobar',
+ }
+ eq_(_request_uri(environ), 'http://test.com/foobar')
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment