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

Commit c1efe32

Browse files
authored
Merge pull request #436 from tomgalloway/Extra_Listener_Tests
Notification listener tests created.
2 parents 09e3dde + 02600b9 commit c1efe32

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

market/listeners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def notify(self, guid, handle, notif_type, order_id, title, image_hash):
109109
"image_hash": image_hash.encode("hex")
110110
}
111111
}
112-
self.ws.push(json.dumps(sanitize_html(notification_json), indent=4))
112+
self.push_ws(notification_json)
113113

114114
def push_ws(self, json_obj):
115115
self.ws.push(json.dumps(sanitize_html(json_obj), indent=4))

market/tests/test_listeners.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from mock import MagicMock
44
import mock
55

6-
from market.listeners import MessageListenerImpl, BroadcastListenerImpl
6+
from market.listeners import MessageListenerImpl, BroadcastListenerImpl, NotificationListenerImpl
77
from protos.objects import PlaintextMessage
88

99
class MarketListenersTest(unittest.TestCase):
@@ -95,3 +95,22 @@ def test_MarketListeners_broadcast_notify_success(self):
9595
'test_message',
9696
mock.ANY, '')
9797
self.ws.push.assert_called_once_with(mock.ANY)
98+
99+
def test_MarketListeners_notifiation_notify_success(self):
100+
n = NotificationListenerImpl(self.ws, self.db)
101+
n.notify('1231', 'test_handle', 'test_notify_type', 'test_order_id',
102+
'test_title', 'test_image_hash')
103+
self.db.notifications.save_notification.assert_called_once_with(mock.ANY, '31323331', 'test_handle',
104+
'test_notify_type', 'test_order_id',
105+
'test_title', mock.ANY, 'test_image_hash')
106+
self.ws.push.assert_called_once_with(mock.ANY)
107+
108+
def test_MarketListeners_notifiation_push_success(self):
109+
notification_json = {
110+
"notification": {
111+
"guid": "guid"
112+
}
113+
}
114+
n = NotificationListenerImpl(self.ws, self.db)
115+
n.push_ws(notification_json)
116+
self.ws.push.assert_called_once_with('{\n "notification": {\n "guid": "guid"\n }\n}')

0 commit comments

Comments
 (0)