From c318ac8e773e5ab3f03ba5fdcb8a56c24893a522 Mon Sep 17 00:00:00 2001 From: Kurt Griffiths Date: Wed, 2 Mar 2016 17:39:52 -0600 Subject: [PATCH] refactor(falcon.testing.Result): Rename data property to content --- falcon/testing/test_case.py | 14 +++++++------- tests/test_error_handlers.py | 2 +- tests/test_headers.py | 4 ++-- tests/test_hello.py | 16 ++++++++-------- tests/test_utils.py | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/falcon/testing/test_case.py b/falcon/testing/test_case.py index e809b8b..6b7db30 100644 --- a/falcon/testing/test_case.py +++ b/falcon/testing/test_case.py @@ -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 diff --git a/tests/test_error_handlers.py b/tests/test_error_handlers.py index 30d155a..595d22c 100644 --- a/tests/test_error_handlers.py +++ b/tests/test_error_handlers.py @@ -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) diff --git a/tests/test_headers.py b/tests/test_headers.py index fda337c..d44fe10 100644 --- a/tests/test_headers.py +++ b/tests/test_headers.py @@ -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) diff --git a/tests/test_hello.py b/tests/test_hello.py index f191916..a30ac4e 100644 --- a/tests/test_hello.py +++ b/tests/test_hello.py @@ -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) diff --git a/tests/test_utils.py b/tests/test_utils.py index 9ba7e0c..cd90ad6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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')