Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/websensors/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def unregister_participant(self, board_id, participant_id):
"""
if board_id in self.boards:
board = self.boards[board_id]
if participant_id in self.boards[board_id]:
if participant_id in board['handlers']:
board['handlers'].pop(participant_id, None)
self.bus.log("Unregistering participant %s from board %s" % (participant_id, board_id))

Expand Down
3 changes: 2 additions & 1 deletion requirements/py2kreqs.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
CherryPy>=5.5.0
Mako<1.2
tornado>=4.2.3
greenlet>=0.4.9
mock>=2.0.0
Cython>=0.22.1
gevent>=1.1.1
pytest>=3.0.7
pytest>=3.0.7
3 changes: 2 additions & 1 deletion requirements/py3kreqs.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
CherryPy>=5.5.0
Mako
tornado>=4.2.3
mock>=2.0.0
asyncio>=3.4.3
Cython>=0.22.1
gevent>=1.1.1
pytest>=3.0.4
pytest>=3.0.4
53 changes: 53 additions & 0 deletions test/test_drawingboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
import sys
import unittest

try:
from unittest.mock import patch
except ImportError:
from mock import patch

import cherrypy
from cherrypy.process.wspbus import Bus


example_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)),
'example', 'websensors')
sys.path.insert(0, example_dir)
try:
with patch.object(cherrypy.tools, 'render', create=True), \
patch.object(cherrypy.tools, 'websocket', create=True):
import app as drawingboard
finally:
sys.path.remove(example_dir)


class DrawingBoardTest(unittest.TestCase):
def setUp(self):
self.bus = Bus()
self.plugin = drawingboard.DrawingBoardWebSocketPlugin(self.bus)
self.bus.websockets = self.plugin
self.plugin.register_board('board')
self.alice = drawingboard.DrawingBoardWebSocketHandler(None)
self.bob = drawingboard.DrawingBoardWebSocketHandler(None)
self.plugin.register_participant('board', 'alice', self.alice)
self.plugin.register_participant('board', 'bob', self.bob)

def test_unregister_participant_preserves_other_handlers(self):
self.plugin.unregister_participant('board', 'alice')
self.assertEqual(self.plugin.boards['board']['handlers'],
{'bob': self.bob})

def test_closed_callback_unregisters_participant(self):
with patch.object(drawingboard, 'bus', self.bus):
self.alice.closed(1000, 'done')
self.assertEqual(self.plugin.boards['board']['handlers'],
{'bob': self.bob})

def test_unknown_and_repeated_unregistration_are_harmless(self):
self.plugin.unregister_participant('board', 'alice')
self.plugin.unregister_participant('board', 'alice')
self.plugin.unregister_participant('board', 'unknown')
self.plugin.unregister_participant('unknown', 'bob')
self.assertEqual(self.plugin.boards['board']['handlers'],
{'bob': self.bob})
Loading