66import pytest
77
88from ably import AblyException
9- from ably .types .annotation import AnnotationAction
9+ from ably .types .annotation import Annotation , AnnotationAction
1010from ably .types .channelmode import ChannelMode
1111from ably .types .channeloptions import ChannelOptions
1212from ably .types .message import MessageAction
@@ -71,10 +71,10 @@ def on_message(msg):
7171 await channel .subscribe ('message' , on_message )
7272
7373 # Publish annotation using realtime
74- await channel .annotations .publish (publish_result .serials [0 ], {
75- ' type' : 'reaction:distinct.v1' ,
76- ' name' : '👍'
77- } )
74+ await channel .annotations .publish (publish_result .serials [0 ], Annotation (
75+ type = 'reaction:distinct.v1' ,
76+ name = '👍'
77+ ) )
7878
7979 # Wait for annotation
8080 annotation = await annotation_future
@@ -88,6 +88,7 @@ def on_message(msg):
8888 summary = await message_summary
8989 assert summary .action == MessageAction .MESSAGE_SUMMARY
9090 assert summary .serial == publish_result .serials [0 ]
91+ assert summary .annotations .summary ['reaction:distinct.v1' ]['👍' ]['total' ] == 1
9192
9293 # Try again but with REST publish
9394 annotation_future2 = asyncio .Future ()
@@ -98,10 +99,10 @@ async def on_annotation2(annotation):
9899
99100 await channel .annotations .subscribe (on_annotation2 )
100101
101- await rest_channel .annotations .publish (publish_result .serials [0 ], {
102- ' type' : 'reaction:distinct.v1' ,
103- ' name' : '😕'
104- } )
102+ await rest_channel .annotations .publish (publish_result .serials [0 ], Annotation (
103+ type = 'reaction:distinct.v1' ,
104+ name = '😕'
105+ ) )
105106
106107 annotation = await annotation_future2
107108 assert annotation .action == AnnotationAction .ANNOTATION_CREATE
@@ -130,10 +131,10 @@ async def test_get_all_annotations_for_a_message(self):
130131 # Publish multiple annotations
131132 emojis = ['👍' , '😕' , '👎' ]
132133 for emoji in emojis :
133- await channel .annotations .publish (publish_result .serials [0 ], {
134- ' type' : 'reaction:distinct.v1' ,
135- ' name' : emoji
136- } )
134+ await channel .annotations .publish (publish_result .serials [0 ], Annotation (
135+ type = 'reaction:distinct.v1' ,
136+ name = emoji
137+ ) )
137138
138139 # Wait for all annotations to appear
139140 annotations = []
@@ -191,10 +192,10 @@ async def on_reaction(annotation):
191192 # Publish message and annotation
192193 publish_result = await channel .publish ('message' , 'test' )
193194
194- await channel .annotations .publish (publish_result .serials [0 ], {
195- ' type' : 'reaction:distinct.v1' ,
196- ' name' : '👍'
197- } )
195+ await channel .annotations .publish (publish_result .serials [0 ], Annotation (
196+ type = 'reaction:distinct.v1' ,
197+ name = '👍'
198+ ) )
198199
199200 # Should receive the annotation
200201 annotation = await reaction_future
@@ -227,10 +228,10 @@ async def on_annotation(annotation):
227228 # Publish message and first annotation
228229 publish_result = await channel .publish ('message' , 'test' )
229230
230- await channel .annotations .publish (publish_result .serials [0 ], {
231- ' type' : 'reaction:distinct.v1' ,
232- ' name' : '👍'
233- } )
231+ await channel .annotations .publish (publish_result .serials [0 ], Annotation (
232+ type = 'reaction:distinct.v1' ,
233+ name = '👍'
234+ ) )
234235
235236 # Wait for the first annotation to appear
236237 await annotation_future .get ()
@@ -242,10 +243,10 @@ async def on_annotation(annotation):
242243 await channel .annotations .subscribe (lambda annotation : annotation_future .set_result (annotation ))
243244
244245 # Publish another annotation
245- await channel .annotations .publish (publish_result .serials [0 ], {
246- ' type' : 'reaction:distinct.v1' ,
247- ' name' : '😕'
248- } )
246+ await channel .annotations .publish (publish_result .serials [0 ], Annotation (
247+ type = 'reaction:distinct.v1' ,
248+ name = '😕'
249+ ) )
249250
250251 # Wait for the second annotation to appear in another listener
251252 await annotation_future .get ()
@@ -287,10 +288,10 @@ async def on_annotation(annotation):
287288 await channel .publish ('message' , 'test' )
288289 message = await message_future
289290
290- await channel .annotations .publish (message .serial , {
291- ' type' : 'reaction:distinct.v1' ,
292- ' name' : '👍'
293- } )
291+ await channel .annotations .publish (message .serial , Annotation (
292+ type = 'reaction:distinct.v1' ,
293+ name = '👍'
294+ ) )
294295
295296 await annotation_future .get ()
296297
@@ -299,10 +300,10 @@ async def on_annotation(annotation):
299300 assert annotations_received [0 ].action == AnnotationAction .ANNOTATION_CREATE
300301
301302 # Delete the annotation
302- await channel .annotations .delete (message .serial , {
303- ' type' : 'reaction:distinct.v1' ,
304- ' name' : '👍'
305- } )
303+ await channel .annotations .delete (message .serial , Annotation (
304+ type = 'reaction:distinct.v1' ,
305+ name = '👍'
306+ ) )
306307
307308 # Wait for delete annotation
308309 await annotation_future .get ()
0 commit comments