feat: Add __repr__ for Request, Response, and HTTPError (#1041)
Closes #1025
This commit is contained in:
parent
403170fbb4
commit
c2a6999186
|
@ -129,6 +129,9 @@ class HTTPError(Exception):
|
|||
else:
|
||||
self.link = None
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self.status)
|
||||
|
||||
@property
|
||||
def has_representation(self):
|
||||
return True
|
||||
|
|
|
@ -421,6 +421,9 @@ class Request(object):
|
|||
else:
|
||||
self.context = self.context_type()
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s %r>' % (self.__class__.__name__, self.method, self.url)
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
# Properties
|
||||
# ------------------------------------------------------------------------
|
||||
|
|
|
@ -153,6 +153,9 @@ class Response(object):
|
|||
else:
|
||||
self.context = self.context_type()
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self.status)
|
||||
|
||||
def set_stream(self, stream, stream_len):
|
||||
"""Convenience method for setting both `stream` and `stream_len`.
|
||||
|
||||
|
|
|
@ -382,3 +382,8 @@ class TestError(testtools.TestCase):
|
|||
self.assertEqual('Test', e.title, 'Title should be "Test"')
|
||||
self.assertEqual('Testdescription', e.description,
|
||||
'Description should be "Testdescription"')
|
||||
|
||||
def test_http_error_repr(self):
|
||||
error = falcon.HTTPBadRequest()
|
||||
_repr = '<%s: %s>' % (error.__class__.__name__, error.status)
|
||||
self.assertEqual(error.__repr__(), _repr)
|
||||
|
|
|
@ -72,7 +72,6 @@ class TestRequestBody(testing.TestBase):
|
|||
# each time the property is called. Also ensures branch
|
||||
# coverage of the property implementation.
|
||||
assert bounded_stream is req.bounded_stream
|
||||
|
||||
data = bounded_stream.read()
|
||||
self.assertEqual(len(data), 0)
|
||||
|
||||
|
@ -142,3 +141,9 @@ class TestRequestBody(testing.TestBase):
|
|||
body = request_helpers.Body(stream, expected_len)
|
||||
for i, line in enumerate(body):
|
||||
self.assertEqual(line, expected_lines[i])
|
||||
|
||||
def test_request_repr(self):
|
||||
environ = testing.create_environ()
|
||||
req = falcon.Request(environ)
|
||||
_repr = '<%s: %s %r>' % (req.__class__.__name__, req.method, req.url)
|
||||
self.assertEquals(req.__repr__(), _repr)
|
||||
|
|
|
@ -15,3 +15,8 @@ class TestResponseBody(testing.TestBase):
|
|||
resp.body += ' '
|
||||
|
||||
self.assertEqual(resp.body, text)
|
||||
|
||||
def test_response_repr(self):
|
||||
resp = falcon.Response()
|
||||
_repr = '<%s: %s>' % (resp.__class__.__name__, resp.status)
|
||||
self.assertEqual(resp.__repr__(), _repr)
|
||||
|
|
Loading…
Reference in New Issue