aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/test_streaming.py17
2 files changed, 9 insertions, 8 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/test_streaming.py b/tests/test_streaming.py
index c79a8e9..1f8d75f 100644
--- a/tests/test_streaming.py
+++ b/tests/test_streaming.py
@@ -24,9 +24,10 @@ class Listener(StreamListener):
24 self.heartbeats += 1 24 self.heartbeats += 1
25 25
26 def handle_stream_(self, lines): 26 def handle_stream_(self, lines):
27 '''Test helper to avoid littering all tests with six.b().''' 27 """Test helper to avoid littering all tests with six.b()."""
28 return self.handle_stream(map(six.b, lines)) 28 return self.handle_stream(map(six.b, lines))
29 29
30
30def test_heartbeat(): 31def test_heartbeat():
31 listener = Listener() 32 listener = Listener()
32 listener.handle_stream_([':one', ':two']) 33 listener.handle_stream_([':one', ':two'])
@@ -85,7 +86,7 @@ def test_many(events):
85 86
86 87
87def test_unknown_event(): 88def test_unknown_event():
88 '''Be tolerant of new event types''' 89 """Be tolerant of new event types"""
89 listener = Listener() 90 listener = Listener()
90 listener.handle_stream_([ 91 listener.handle_stream_([
91 'event: blahblah', 92 'event: blahblah',
@@ -137,11 +138,11 @@ def test_sse_order_doesnt_matter():
137 138
138 139
139def test_extra_keys_ignored(): 140def test_extra_keys_ignored():
140 ''' 141 """
141 https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format 142 https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format
142 defines 'id' and 'retry' keys which the Mastodon streaming API doesn't use, 143 defines 'id' and 'retry' keys which the Mastodon streaming API doesn't use,
143 and alleges that "All other field names are ignored". 144 and alleges that "All other field names are ignored".
144 ''' 145 """
145 listener = Listener() 146 listener = Listener()
146 listener.handle_stream_([ 147 listener.handle_stream_([
147 'event: update', 148 'event: update',
@@ -155,7 +156,7 @@ def test_extra_keys_ignored():
155 156
156 157
157def test_valid_utf8(): 158def test_valid_utf8():
158 '''Snowman Cat Face With Tears Of Joy''' 159 """Snowman Cat Face With Tears Of Joy"""
159 listener = Listener() 160 listener = Listener()
160 listener.handle_stream_([ 161 listener.handle_stream_([
161 'event: update', 162 'event: update',
@@ -166,7 +167,7 @@ def test_valid_utf8():
166 167
167 168
168def test_invalid_utf8(): 169def test_invalid_utf8():
169 '''Cat Face With Tears O''' 170 """Cat Face With Tears O"""
170 listener = Listener() 171 listener = Listener()
171 with pytest.raises(MalformedEventError): 172 with pytest.raises(MalformedEventError):
172 listener.handle_stream_([ 173 listener.handle_stream_([
@@ -177,13 +178,13 @@ def test_invalid_utf8():
177 178
178 179
179def test_multiline_payload(): 180def test_multiline_payload():
180 ''' 181 """
181 https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Data-only_messages 182 https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Data-only_messages
182 says that newlines in the 'data' field can be encoded by sending the field 183 says that newlines in the 'data' field can be encoded by sending the field
183 twice! This would be really pathological for Mastodon because the payload 184 twice! This would be really pathological for Mastodon because the payload
184 is JSON, but technically literal newlines are permissible (outside strings) 185 is JSON, but technically literal newlines are permissible (outside strings)
185 so let's handle this case. 186 so let's handle this case.
186 ''' 187 """
187 listener = Listener() 188 listener = Listener()
188 listener.handle_stream_([ 189 listener.handle_stream_([
189 'event: update', 190 'event: update',
Powered by cgit v1.2.3 (git 2.41.0)