diff options
author | Aljoscha Rittner <[email protected]> | 2022-06-24 18:11:23 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-06-24 18:11:23 +0200 |
commit | c7fdcf3faec29040d32b5a9afa81859cc2195d99 (patch) | |
tree | 5f7c2a66e063b80e77b7be1fe2c24be986e70e1d /tests | |
parent | c9008a1cdcd31ba47c10d7b6f35cc7aceffe81f5 (diff) | |
parent | a987af8a0d20db59f1531492e2313ac8cce81f48 (diff) | |
download | mastodon.py-c7fdcf3faec29040d32b5a9afa81859cc2195d99.tar.gz |
Merge pull request #235 from arittner/stream-unknown-handler
Support of processing unknown events and event names with dots.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_streaming.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/test_streaming.py b/tests/test_streaming.py index cddb79a..8912b9c 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py | |||
@@ -61,6 +61,8 @@ class Listener(StreamListener): | |||
61 | self.notifications = [] | 61 | self.notifications = [] |
62 | self.deletes = [] | 62 | self.deletes = [] |
63 | self.heartbeats = 0 | 63 | self.heartbeats = 0 |
64 | self.bla_called = False | ||
65 | self.do_something_called = False | ||
64 | 66 | ||
65 | def on_update(self, status): | 67 | def on_update(self, status): |
66 | self.updates.append(status) | 68 | self.updates.append(status) |
@@ -72,6 +74,11 @@ class Listener(StreamListener): | |||
72 | self.deletes.append(status_id) | 74 | self.deletes.append(status_id) |
73 | 75 | ||
74 | def on_blahblah(self, data): | 76 | def on_blahblah(self, data): |
77 | self.bla_called = True | ||
78 | pass | ||
79 | |||
80 | def on_do_something(self, data): | ||
81 | self.do_something_called = True | ||
75 | pass | 82 | pass |
76 | 83 | ||
77 | def handle_heartbeat(self): | 84 | def handle_heartbeat(self): |
@@ -158,6 +165,37 @@ def test_unknown_event(): | |||
158 | 'data: {}', | 165 | 'data: {}', |
159 | '', | 166 | '', |
160 | ]) | 167 | ]) |
168 | assert listener.bla_called == True | ||
169 | assert listener.updates == [] | ||
170 | assert listener.notifications == [] | ||
171 | assert listener.deletes == [] | ||
172 | assert listener.heartbeats == 0 | ||
173 | |||
174 | def test_unknown_handled_event(): | ||
175 | """Be tolerant of new unknown event types, if on_unknown_event is available""" | ||
176 | listener = Listener() | ||
177 | listener.on_unknown_event = lambda name, payload: None | ||
178 | |||
179 | listener.handle_stream_([ | ||
180 | 'event: complete.new.event', | ||
181 | 'data: {"k": "v"}', | ||
182 | '', | ||
183 | ]) | ||
184 | |||
185 | assert listener.updates == [] | ||
186 | assert listener.notifications == [] | ||
187 | assert listener.deletes == [] | ||
188 | assert listener.heartbeats == 0 | ||
189 | |||
190 | def test_dotted_unknown_event(): | ||
191 | """Be tolerant of new event types with dots in the event-name""" | ||
192 | listener = Listener() | ||
193 | listener.handle_stream_([ | ||
194 | 'event: do.something', | ||
195 | 'data: {}', | ||
196 | '', | ||
197 | ]) | ||
198 | assert listener.do_something_called == True | ||
161 | assert listener.updates == [] | 199 | assert listener.updates == [] |
162 | assert listener.notifications == [] | 200 | assert listener.notifications == [] |
163 | assert listener.deletes == [] | 201 | assert listener.deletes == [] |
@@ -169,7 +207,7 @@ def test_invalid_event(): | |||
169 | with pytest.raises(MastodonMalformedEventError): | 207 | with pytest.raises(MastodonMalformedEventError): |
170 | listener.handle_stream_([ | 208 | listener.handle_stream_([ |
171 | 'event: whatup', | 209 | 'event: whatup', |
172 | 'data: {}', | 210 | 'data: {"k": "v"}', |
173 | '', | 211 | '', |
174 | ]) | 212 | ]) |
175 | 213 | ||