Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit ff3e353

Browse files
author
Tom Galloway
committed
Further listener tests.
1 parent 7b8426d commit ff3e353

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

market/listeners.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def notify(self, plaintext, signature):
4848
self.ws.push(json.dumps(sanitize_html(message_json), indent=4))
4949
except Exception as e:
5050
self.log.error('Market.Listener.notify Exception: %s' % e)
51-
pass
5251

5352
class BroadcastListenerImpl(object):
5453
implements(BroadcastListener)
@@ -61,6 +60,8 @@ def notify(self, guid, message):
6160
# pull the metadata for this node from the db
6261
f = Following()
6362
ser = self.db.follow.get_following()
63+
handle = ""
64+
avatar_hash = ""
6465
if ser is not None:
6566
f.ParseFromString(ser)
6667
for user in f.users:

market/tests/test_listeners.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from twisted.trial import unittest
22
from twisted.python import log
33
from mock import MagicMock
4+
import mock
45

5-
from market.listeners import MessageListenerImpl
6+
from market.listeners import MessageListenerImpl, BroadcastListenerImpl
67
from protos.objects import PlaintextMessage
78

89
class MarketListenersTest(unittest.TestCase):
@@ -47,6 +48,7 @@ def _create_valid_message_json(handle):
4748
return message
4849

4950
def test_MarketListeners_notify_without_handle_success(self):
51+
'''MessageListenerImpl correctly notify without handle.'''
5052
p = self._create_valid_plaintext_message('')
5153
signature = 'test_signature'
5254
l = MessageListenerImpl(self.ws, self.db)
@@ -61,6 +63,7 @@ def test_MarketListeners_notify_without_handle_success(self):
6163
self.ws.push.assert_called_with(self._create_valid_message_json(''))
6264

6365
def test_MarketListeners_notify_with_handle_success(self):
66+
'''MessageListenerImpl correctly notify with handle.'''
6467
p = self._create_valid_plaintext_message('test_handle')
6568
signature = 'test_signature'
6669
l = MessageListenerImpl(self.ws, self.db)
@@ -82,3 +85,13 @@ def test_MarketListeners_save_message_exception(self):
8285
self.db.messages.save_message.side_effect = Exception("test_exception")
8386
l.notify(p, signature)
8487
self.assertEqual('[ERROR] Market.Listener.notify Exception: test_exception', self.catcher[0]['message'][0])
88+
89+
def test_MarketListeners_broadcast_notify_success(self):
90+
'''BroadcastListenerImpl correctly notifies.'''
91+
b = BroadcastListenerImpl(self.ws, self.db)
92+
b.notify('123', 'test_message')
93+
self.db.broadcasts.save_broadcast.assert_called_once_with(mock.ANY,
94+
'313233', '',
95+
'test_message',
96+
mock.ANY, '')
97+
self.ws.push.assert_called_once_with(mock.ANY)

0 commit comments

Comments
 (0)