diff options
author | Gabriel Falcão <gabriel@nacaolivre.org> | 2020-03-10 01:51:29 +0100 |
---|---|---|
committer | Gabriel Falcão <gabriel@nacaolivre.org> | 2020-03-10 01:51:29 +0100 |
commit | b4c34e7075778579ebf4e320c4ab70e9e9dff96b (patch) | |
tree | a46dc6efa698e7f47b5c738a5181254c9fd07662 | |
parent | 818cd1b45bd3863799b25005da68b6a8a0cd1373 (diff) | |
download | httpretty-b4c34e7075778579ebf4e320c4ab70e9e9dff96b.tar.gz |
fix failing test
-rw-r--r-- | httpretty/compat.py | 3 | ||||
-rw-r--r-- | httpretty/core.py | 12 | ||||
-rw-r--r-- | tests/functional/test_requests.py | 14 |
3 files changed, 17 insertions, 12 deletions
diff --git a/httpretty/compat.py b/httpretty/compat.py index a68d62b..bf4d135 100644 --- a/httpretty/compat.py +++ b/httpretty/compat.py @@ -48,8 +48,6 @@ class BaseClass(object): return self.__str__() -ClassTypes = (type,) - __all__ = [ 'BaseClass', 'BaseHTTPRequestHandler', @@ -59,5 +57,4 @@ __all__ = [ 'urlunsplit', 'urlsplit', 'parse_qs', - 'ClassTypes', ] diff --git a/httpretty/core.py b/httpretty/core.py index 1133d98..c6f5153 100644 --- a/httpretty/core.py +++ b/httpretty/core.py @@ -30,6 +30,7 @@ import hashlib import inspect import itertools import json +import types import re import socket import tempfile @@ -50,7 +51,6 @@ from .compat import ( urlsplit, parse_qs, unquote_utf8, - ClassTypes, ) from .http import ( STATUSES, @@ -1370,10 +1370,10 @@ class httpretty(HttpBaseClass): response.method = method entries_for_this_uri = responses else: - headers[str('body')] = body - headers[str('adding_headers')] = adding_headers - headers[str('forcing_headers')] = forcing_headers - headers[str('status')] = status + headers['body'] = body + headers['adding_headers'] = adding_headers + headers['forcing_headers'] = forcing_headers + headers['status'] = status entries_for_this_uri = [ cls.Response(method=method, uri=uri, **headers), @@ -1722,7 +1722,7 @@ def httprettified(test=None, allow_net_connect=True): return test(*args, **kw) return wrapper - if isinstance(test, ClassTypes): + if isinstance(test, type): return decorate_class(test) elif callable(test): return decorate_callable(test) diff --git a/tests/functional/test_requests.py b/tests/functional/test_requests.py index 80d8591..93771ca 100644 --- a/tests/functional/test_requests.py +++ b/tests/functional/test_requests.py @@ -273,7 +273,6 @@ def test_httpretty_ignores_querystrings_from_registered_uri(now): expect(HTTPretty.last_request.path).to.equal('/?id=123') -@skip('TODO: fix me') @httprettified @within(five=microseconds) def test_streaming_responses(now): @@ -310,17 +309,21 @@ def test_streaming_responses(now): streaming=True) # taken from the requests docs + + # test iterating by line # Http://docs.python-requests.org/en/latest/user/advanced/# streaming-requests response = requests.post(TWITTER_STREAMING_URL, data={'track': 'requests'}, auth=('username', 'password'), stream=True) - # test iterating by line line_iter = response.iter_lines() with in_time(0.01, 'Iterating by line is taking forever!'): for i in range(len(twitter_response_lines)): expect(next(line_iter).strip()).to.equal( twitter_response_lines[i].strip()) + HTTPretty.register_uri(HTTPretty.POST, TWITTER_STREAMING_URL, + body=(l for l in twitter_response_lines), + streaming=True) # test iterating by line after a second request response = requests.post( TWITTER_STREAMING_URL, @@ -338,6 +341,9 @@ def test_streaming_responses(now): expect(next(line_iter).strip()).to.equal( twitter_response_lines[i].strip()) + HTTPretty.register_uri(HTTPretty.POST, TWITTER_STREAMING_URL, + body=(l for l in twitter_response_lines), + streaming=True) # test iterating by char response = requests.post( TWITTER_STREAMING_URL, @@ -355,7 +361,9 @@ def test_streaming_responses(now): expect(twitter_body).to.equal(twitter_expected_response_body) # test iterating by chunks larger than the stream - + HTTPretty.register_uri(HTTPretty.POST, TWITTER_STREAMING_URL, + body=(l for l in twitter_response_lines), + streaming=True) response = requests.post(TWITTER_STREAMING_URL, data={'track': 'requests'}, auth=('username', 'password'), stream=True) |