aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAljoscha Rittner <[email protected]>2022-06-20 12:23:37 +0200
committerAljoscha Rittner <[email protected]>2022-06-20 12:23:37 +0200
commit2c06de91dd18b5f551606fe6cec13dbfa6b15e4f (patch)
tree115da083dca9875eac1bffcaf4a1b9462c298373 /tests
parente9d2c3d53f7b1d371e5dc5bf47e5fe335b698c85 (diff)
downloadmastodon.py-2c06de91dd18b5f551606fe6cec13dbfa6b15e4f.tar.gz
Support of processing unknown events and event names with dots.
#Fixes 234
Diffstat (limited to 'tests')
-rw-r--r--tests/test_streaming.py40
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
174def 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
190def 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
Powered by cgit v1.2.3 (git 2.41.0)