Fix error on to big change id on websocket connection

This commit is contained in:
Oskar Hahn 2018-11-02 05:10:49 +01:00
parent 4f7d860280
commit b97e643b33
2 changed files with 19 additions and 2 deletions

View File

@ -41,9 +41,15 @@ class SiteConsumer(ProtocollAsyncJsonWebsocketConsumer):
await self.channel_layer.group_add('autoupdate', self.channel_name)
await self.accept()
if change_id is not None:
data = await get_element_data(self.scope['user'], change_id)
await self.send_json(type='autoupdate', content=data)
try:
data = await get_element_data(self.scope['user'], change_id)
except ValueError:
# When the change_id is to big, do nothing
pass
else:
await self.send_json(type='autoupdate', content=data)
async def disconnect(self, close_code: int) -> None:
"""

View File

@ -101,6 +101,17 @@ async def test_connection_with_invalid_change_id(get_communicator):
assert connected is False
@pytest.mark.asyncio
async def test_connection_with_to_big_change_id(get_communicator):
await set_config('general_system_enable_anonymous', True)
communicator = get_communicator('change_id=1000000000000')
connected, __ = await communicator.connect()
assert connected is True
assert await communicator.receive_nothing()
@pytest.mark.asyncio
async def test_changed_data_autoupdate_off(communicator):
await set_config('general_system_enable_anonymous', True)