Skip to content

Commit 65977d6

Browse files
committed
Added unit tests and updated integration tests for annotations
1 parent b32ddd9 commit 65977d6

2 files changed

Lines changed: 341 additions & 12 deletions

File tree

test/ably/realtime/realtimeannotations_test.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import pytest
77

8-
from ably import AblyException
98
from ably.types.annotation import Annotation, AnnotationAction
109
from ably.types.channelmode import ChannelMode
1110
from ably.types.channeloptions import ChannelOptions
@@ -34,7 +33,7 @@ async def setup(self, transport):
3433
)
3534

3635
async def test_publish_and_subscribe_annotations(self):
37-
"""Test publishing and subscribing to annotations"""
36+
"""RTAN1/RTAN4: Publish and subscribe to annotations via realtime and REST"""
3837
channel_options = ChannelOptions(modes=[
3938
ChannelMode.PUBLISH,
4039
ChannelMode.SUBSCRIBE,
@@ -112,7 +111,7 @@ async def on_annotation2(annotation):
112111
assert annotation.serial > annotation.message_serial
113112

114113
async def test_get_all_annotations_for_a_message(self):
115-
"""Test retrieving all annotations with pagination"""
114+
"""RTAN3: Retrieve all annotations for a message"""
116115
channel_options = ChannelOptions(modes=[
117116
ChannelMode.PUBLISH,
118117
ChannelMode.SUBSCRIBE,
@@ -158,7 +157,7 @@ async def check_annotations():
158157
assert annotations[2].serial > annotations[1].serial
159158

160159
async def test_subscribe_by_annotation_type(self):
161-
"""Test subscribing to specific annotation types"""
160+
"""RTAN4c: Subscribe to annotations filtered by type"""
162161
channel_options = ChannelOptions(modes=[
163162
ChannelMode.PUBLISH,
164163
ChannelMode.SUBSCRIBE,
@@ -203,7 +202,7 @@ async def on_reaction(annotation):
203202
assert annotation.name == '👍'
204203

205204
async def test_unsubscribe_annotations(self):
206-
"""Test unsubscribing from annotations"""
205+
"""RTAN5: Unsubscribe from annotation events"""
207206
channel_options = ChannelOptions(modes=[
208207
ChannelMode.PUBLISH,
209208
ChannelMode.SUBSCRIBE,
@@ -254,7 +253,7 @@ async def on_annotation(annotation):
254253
assert len(annotations_received) == 1
255254

256255
async def test_delete_annotation(self):
257-
"""Test deleting annotations"""
256+
"""RTAN2: Delete an annotation via realtime"""
258257
channel_options = ChannelOptions(modes=[
259258
ChannelMode.PUBLISH,
260259
ChannelMode.SUBSCRIBE,
@@ -311,8 +310,13 @@ async def on_annotation(annotation):
311310
assert len(annotations_received) == 2
312311
assert annotations_received[1].action == AnnotationAction.ANNOTATION_DELETE
313312

314-
async def test_subscribe_without_annotation_mode_fails(self):
315-
"""Test that subscribing without annotation_subscribe mode raises an error"""
313+
async def test_subscribe_without_annotation_mode_warns(self, caplog):
314+
"""RTAN4e: Subscribing without ANNOTATION_SUBSCRIBE mode logs a warning.
315+
316+
Per spec, the library should log a warning indicating that the user has tried
317+
to add an annotation listener without having requested the ANNOTATION_SUBSCRIBE
318+
channel mode.
319+
"""
316320
# Create channel without annotation_subscribe mode
317321
channel_options = ChannelOptions(modes=[
318322
ChannelMode.PUBLISH,
@@ -327,9 +331,13 @@ async def test_subscribe_without_annotation_mode_fails(self):
327331
async def on_annotation(annotation):
328332
pass
329333

330-
# Should raise error about missing annotation_subscribe mode
331-
with pytest.raises(AblyException) as exc_info:
334+
# RTAN4e: Should log a warning (not raise), and still register the listener
335+
with caplog.at_level(logging.WARNING, logger='ably.realtime.annotations'):
332336
await channel.annotations.subscribe(on_annotation)
333337

334-
assert exc_info.value.status_code == 400
335-
assert 'annotation_subscribe' in str(exc_info.value).lower()
338+
# Verify warning was logged mentioning the missing mode
339+
assert any('ANNOTATION_SUBSCRIBE' in record.message for record in caplog.records)
340+
341+
# Listener should still be registered (subscribe didn't fail)
342+
# Unsubscribe to clean up
343+
channel.annotations.unsubscribe(on_annotation)

0 commit comments

Comments
 (0)