Merge pull request #720 from kgriffs/wsgi-testcase
refactor(falcon.testing.Result): Rename data property to content
This commit is contained in:
@@ -45,8 +45,8 @@ class Result(object):
|
||||
containing all the headers in the response
|
||||
encoding (str): Text encoding of the response body, or ``None``
|
||||
if the encoding can not be determined.
|
||||
data (bytes): Raw response body, or ``bytes`` if the response
|
||||
body was empty.
|
||||
content (bytes): Raw response body, or ``bytes`` if the
|
||||
response body was empty.
|
||||
text (str): Decoded response body of type ``unicode``
|
||||
under Python 2.6 and 2.7, and of type ``str`` otherwise.
|
||||
Raises an error if the response encoding can not be
|
||||
@@ -58,7 +58,7 @@ class Result(object):
|
||||
def __init__(self, iterable, status, headers):
|
||||
self._text = None
|
||||
|
||||
self._data = b''.join(iterable)
|
||||
self._content = b''.join(iterable)
|
||||
if hasattr(iterable, 'close'):
|
||||
iterable.close()
|
||||
|
||||
@@ -85,20 +85,20 @@ class Result(object):
|
||||
return self._encoding
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
def content(self):
|
||||
return self._content
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
if self._text is None:
|
||||
if not self.data:
|
||||
if not self.content:
|
||||
self._text = u''
|
||||
else:
|
||||
if self.encoding is None:
|
||||
msg = 'Response did not specify a content encoding'
|
||||
raise RuntimeError(msg)
|
||||
|
||||
self._text = self.data.decode(self.encoding)
|
||||
self._text = self.content.decode(self.encoding)
|
||||
|
||||
return self._text
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class TestErrorHandler(testing.TestCase):
|
||||
|
||||
result = self.simulate_head()
|
||||
self.assertEqual(result.status_code, 723)
|
||||
self.assertFalse(result.data)
|
||||
self.assertFalse(result.content)
|
||||
|
||||
def test_uncaught_error(self):
|
||||
self.api.add_error_handler(CustomException, capture_error)
|
||||
|
||||
@@ -201,7 +201,7 @@ class TestHeaders(testing.TestCase):
|
||||
|
||||
result = self.simulate_get('/xxx')
|
||||
self.assertNotIn('Content-Length', result.headers)
|
||||
self.assertFalse(result.data)
|
||||
self.assertFalse(result.content)
|
||||
|
||||
def test_content_header_missing(self):
|
||||
environ = testing.create_environ()
|
||||
@@ -274,7 +274,7 @@ class TestHeaders(testing.TestCase):
|
||||
self.api.add_route('/', testing.SimpleTestResource(body=body))
|
||||
result = self.simulate_get()
|
||||
|
||||
self.assertEqual(result.data, body)
|
||||
self.assertEqual(result.content, body)
|
||||
self.assertRaises(RuntimeError, lambda: result.text)
|
||||
self.assertRaises(RuntimeError, lambda: result.json)
|
||||
|
||||
|
||||
@@ -114,13 +114,13 @@ class TestHelloWorld(testing.TestCase):
|
||||
self.assertEqual(result.status, resource.sample_status)
|
||||
self.assertEqual(resp.status, resource.sample_status)
|
||||
self.assertEqual(get_body(resp), resource.sample_utf8)
|
||||
self.assertEqual(result.data, resource.sample_utf8)
|
||||
self.assertEqual(result.content, resource.sample_utf8)
|
||||
|
||||
def test_no_body_on_head(self):
|
||||
self.api.add_route('/body', HelloResource('body'))
|
||||
result = self.simulate_head('/body')
|
||||
|
||||
self.assertFalse(result.data)
|
||||
self.assertFalse(result.content)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_stream_chunked(self):
|
||||
@@ -129,7 +129,7 @@ class TestHelloWorld(testing.TestCase):
|
||||
|
||||
result = self.simulate_get('/chunked-stream')
|
||||
|
||||
self.assertEqual(result.data, resource.sample_utf8)
|
||||
self.assertEqual(result.content, resource.sample_utf8)
|
||||
self.assertNotIn('content-length', result.headers)
|
||||
|
||||
def test_stream_known_len(self):
|
||||
@@ -142,8 +142,8 @@ class TestHelloWorld(testing.TestCase):
|
||||
expected_len = resource.resp.stream_len
|
||||
actual_len = int(result.headers['content-length'])
|
||||
self.assertEqual(actual_len, expected_len)
|
||||
self.assertEqual(len(result.data), expected_len)
|
||||
self.assertEqual(result.data, resource.sample_utf8)
|
||||
self.assertEqual(len(result.content), expected_len)
|
||||
self.assertEqual(result.content, resource.sample_utf8)
|
||||
|
||||
def test_filelike(self):
|
||||
resource = HelloResource('stream, stream_len, filelike')
|
||||
@@ -156,7 +156,7 @@ class TestHelloWorld(testing.TestCase):
|
||||
expected_len = resource.resp.stream_len
|
||||
actual_len = int(result.headers['content-length'])
|
||||
self.assertEqual(actual_len, expected_len)
|
||||
self.assertEqual(len(result.data), expected_len)
|
||||
self.assertEqual(len(result.content), expected_len)
|
||||
|
||||
def test_filelike_using_helper(self):
|
||||
resource = HelloResource('stream, stream_len, filelike, use_helper')
|
||||
@@ -168,12 +168,12 @@ class TestHelloWorld(testing.TestCase):
|
||||
expected_len = resource.resp.stream_len
|
||||
actual_len = int(result.headers['content-length'])
|
||||
self.assertEqual(actual_len, expected_len)
|
||||
self.assertEqual(len(result.data), expected_len)
|
||||
self.assertEqual(len(result.content), expected_len)
|
||||
|
||||
def test_status_not_set(self):
|
||||
self.api.add_route('/nostatus', NoStatusResource())
|
||||
|
||||
result = self.simulate_get('/nostatus')
|
||||
|
||||
self.assertFalse(result.data)
|
||||
self.assertFalse(result.content)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
@@ -339,7 +339,7 @@ class TestFalconTestCase(testing.TestCase):
|
||||
|
||||
def test_wsgi_iterable_not_closeable(self):
|
||||
result = testing.Result([], falcon.HTTP_200, [])
|
||||
self.assertFalse(result.data)
|
||||
self.assertFalse(result.content)
|
||||
|
||||
def test_path_must_start_with_slash(self):
|
||||
self.assertRaises(ValueError, self.simulate_get, 'foo')
|
||||
|
||||
Reference in New Issue
Block a user