예제 #1
0
    def test_bogus_payload(self, send_message):
        p = PubSubProtocol()
        p.send("topic", p)
        p.send(p, {'data': 'bar'})
        p.send(p, p)

        self.assertFalse(send_message.called)
예제 #2
0
    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)
예제 #3
0
    def test_jsonify(self, send_message):
        now = datetime.datetime.now()

        p = PubSubProtocol()
        p.send("foo", now)

        args, kwargs = send_message.call_args
        actual = json.loads(args[0].decode('utf8'))

        expected = {"topic": "foo", "data": now.isoformat()}

        self.assertEqual(actual, expected)
예제 #4
0
    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")
예제 #5
0
    def test_unsubscribe_command(self, unsubscribe):
        p = PubSubProtocol()
        p.onMessage(b'{"unsubscribe":"topic"}', True)

        unsubscribe.assert_called_once_with(p, "topic")
예제 #6
0
    def test_subscribe_publish_one(self, publish_one):
        p = PubSubProtocol()
        p.onMessage(b'{"subscribe":"topic"}', True)

        publish_one.assert_called_once_with(p, "topic")
예제 #7
0
    def test_unknown_command(self, instance):
        p = PubSubProtocol()
        p.onMessage(b'{"foo":"bar"}', True)

        self.assertFalse(instance.called)
예제 #8
0
 def test_unsubscribe_all(self, unsubscribe_all):
     p = PubSubProtocol()
     p.onClose(True, 0, None)
     unsubscribe_all.assert_called_once_with(p)
예제 #9
0
 def test_no_op(self):
     p = PubSubProtocol()
     p.onOpen()
예제 #10
0
 def test_no_op(self):
     p = PubSubProtocol()
     p.onConnect(None)
예제 #11
0
 def test_send_message(self, send_message):
     p = PubSubProtocol()
     p.send("foo", "bar")
     self.assertEqual(send_message.call_count, 1)
예제 #12
0
 def test_str(self):
     p = PubSubProtocol()
     p.peer = "foo"
     self.assertEqual(str(p), "foo")