def test_bogus_payload(self, instance): p = PubSubProtocol() p.onMessage(b'', True) p.onMessage(b'foo', True) p.onMessage(b'{foo}', True) p.onMessage(b'{"foo"}', True) self.assertFalse(instance.called)
def test_request_command(self, send, handle): p = PubSubProtocol() p.onMessage(b'{"request":"topic"}', True) handle.assert_called_once_with({"request":"topic"}) send.assert_called_once_with("topic", "response")
def test_unsubscribe_command(self, unsubscribe): p = PubSubProtocol() p.onMessage(b'{"unsubscribe":"topic"}', True) unsubscribe.assert_called_once_with(p, "topic")
def test_subscribe_publish_one(self, publish_one): p = PubSubProtocol() p.onMessage(b'{"subscribe":"topic"}', True) publish_one.assert_called_once_with(p, "topic")
def test_unknown_command(self, instance): p = PubSubProtocol() p.onMessage(b'{"foo":"bar"}', True) self.assertFalse(instance.called)
def test_request_command(self, send, handle): p = PubSubProtocol() p.onMessage(b'{"request":"topic"}', True) handle.assert_called_once_with({"request": "topic"}) send.assert_called_once_with("topic", "response")