Adjust streaming tests

This commit is contained in:
Lorenz Diener 2017-12-21 11:06:13 +01:00
pare 08a0e5ff67
commit 18543648a6
S'han modificat 2 arxius amb 13 adicions i 2 eliminacions

Veure arxiu

@ -56,7 +56,7 @@ class StreamListener(object):
line = raw_line.decode('utf-8')
except UnicodeDecodeError as err:
six.raise_from(
MastodonMalformedEventError("Malformed UTF-8", line),
MastodonMalformedEventError("Malformed UTF-8"),
err
)

Veure arxiu

@ -30,7 +30,18 @@ class Listener(StreamListener):
def handle_stream_(self, lines):
"""Test helper to avoid littering all tests with six.b()."""
return self.handle_stream(map(six.b, lines))
class MockResponse():
def __init__(self, data):
self.data = data
def iter_content(self, chunk_size):
for line in self.data:
for byte in line:
bytearr = bytearray()
bytearr.append(byte)
yield(bytearr)
yield(b'\n')
return self.handle_stream(MockResponse(map(six.b, lines)))
def test_heartbeat():