summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArthur Vuillard <arthur.vuillard@gmail.com>2013-02-22 15:17:26 +0100
committerArthur Vuillard <arthur.vuillard@gmail.com>2013-02-22 15:17:26 +0100
commitd3d9538d0767ca3b74c19fff15432240f175f97d (patch)
tree697af5a069ce43153eea92f7b0a5998ce63314eb /tests
parent3298f4feda5e921fff4a6903c1e11da19bf16f7a (diff)
downloadwebtest-d3d9538d0767ca3b74c19fff15432240f175f97d.tar.gz
Test webtest.lint.check_environ and webtest.lint.IteratorWrapper and a little cleanup
Diffstat (limited to 'tests')
-rw-r--r--tests/test_lint.py107
1 files changed, 90 insertions, 17 deletions
diff --git a/tests/test_lint.py b/tests/test_lint.py
index 15720fd..38319a4 100644
--- a/tests/test_lint.py
+++ b/tests/test_lint.py
@@ -9,8 +9,13 @@ from webob import Request, Response
from webtest.lint import check_headers
from webtest.lint import check_content_type
+from webtest.lint import check_environ
+from webtest.lint import IteratorWrapper
from six import PY3
+from six import StringIO
+
+import warnings
def application(environ, start_response):
@@ -29,23 +34,6 @@ def application(environ, start_response):
return resp(environ, start_response)
-class TestCheckContentType(unittest.TestCase):
- def test_no_content(self):
- status = "204 No Content"
- headers = [
- ('Content-Type', 'text/plain; charset=utf-8'),
- ('Content-Length', '4')
- ]
- self.assertRaises(AssertionError, check_content_type, status, headers)
-
- def test_no_content_type(self):
- status = "200 OK"
- headers = [
- ('Content-Length', '4')
- ]
- self.assertRaises(AssertionError, check_content_type, status, headers)
-
-
class TestInputWrapper(unittest.TestCase):
def test_read(self):
app = webtest.TestApp(application)
@@ -63,6 +51,23 @@ class TestInputWrapper(unittest.TestCase):
self.assertEqual(resp.body, b'hello\n-t\n')
+class TestCheckContentType(unittest.TestCase):
+ def test_no_content(self):
+ status = "204 No Content"
+ headers = [
+ ('Content-Type', 'text/plain; charset=utf-8'),
+ ('Content-Length', '4')
+ ]
+ self.assertRaises(AssertionError, check_content_type, status, headers)
+
+ def test_no_content_type(self):
+ status = "200 OK"
+ headers = [
+ ('Content-Length', '4')
+ ]
+ self.assertRaises(AssertionError, check_content_type, status, headers)
+
+
class TestCheckHeaders(unittest.TestCase):
@unittest.skipIf(not PY3, 'Useless in Python2')
@@ -72,3 +77,71 @@ class TestCheckHeaders(unittest.TestCase):
@unittest.skipIf(not PY3, 'Useless in Python2')
def test_header_unicode_name(self):
self.assertRaises(AssertionError, check_headers, [('X-€', 'foo')])
+
+
+class TestCheckEnviron(unittest.TestCase):
+ def test_no_query_string(self):
+ environ = {
+ 'REQUEST_METHOD': str('GET'),
+ 'SERVER_NAME': str('localhost'),
+ 'SERVER_PORT': str('80'),
+ 'wsgi.version': (1, 0, 1),
+ 'wsgi.input': StringIO('test'),
+ 'wsgi.errors': StringIO(),
+ 'wsgi.multithread': None,
+ 'wsgi.multiprocess': None,
+ 'wsgi.run_once': None,
+ 'wsgi.url_scheme': 'http',
+ 'PATH_INFO': str('/'),
+ }
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ check_environ(environ)
+ assert len(w) == 1
+ assert "QUERY_STRING" in str(w[-1].message)
+
+ def test_no_valid_request(self):
+ environ = {
+ 'REQUEST_METHOD': str('PROPFIND'),
+ 'SERVER_NAME': str('localhost'),
+ 'SERVER_PORT': str('80'),
+ 'wsgi.version': (1, 0, 1),
+ 'wsgi.input': StringIO('test'),
+ 'wsgi.errors': StringIO(),
+ 'wsgi.multithread': None,
+ 'wsgi.multiprocess': None,
+ 'wsgi.run_once': None,
+ 'wsgi.url_scheme': 'http',
+ 'PATH_INFO': str('/'),
+ 'QUERY_STRING': str(''),
+ }
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ check_environ(environ)
+ assert len(w) == 1
+ assert "REQUEST_METHOD" in str(w[-1].message)
+
+
+class TestIteratorWrapper(unittest.TestCase):
+ def test_close(self):
+ class MockIterator(object):
+
+ def __init__(self):
+ self.closed = False
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ return None
+
+ next = __next__
+
+
+ def close(self):
+ self.closed = True
+ mock = MockIterator()
+ wrapper = IteratorWrapper(mock, None)
+ wrapper.close()
+
+ assert mock.closed, "Original iterator has not been closed"