Adjust streaming tests
This commit is contained in:
pare
08a0e5ff67
commit
18543648a6
S'han modificat 2 arxius amb 13 adicions i 2 eliminacions
|
@ -56,7 +56,7 @@ class StreamListener(object):
|
||||||
line = raw_line.decode('utf-8')
|
line = raw_line.decode('utf-8')
|
||||||
except UnicodeDecodeError as err:
|
except UnicodeDecodeError as err:
|
||||||
six.raise_from(
|
six.raise_from(
|
||||||
MastodonMalformedEventError("Malformed UTF-8", line),
|
MastodonMalformedEventError("Malformed UTF-8"),
|
||||||
err
|
err
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,18 @@ class Listener(StreamListener):
|
||||||
|
|
||||||
def handle_stream_(self, lines):
|
def handle_stream_(self, lines):
|
||||||
"""Test helper to avoid littering all tests with six.b()."""
|
"""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():
|
def test_heartbeat():
|
||||||
|
|
Loading…
Referencia en una nova incidència