Ejemplo n.º 1
0
    def test_subscribe_unsubscribe_2(self):
        """ Test if subscribe and unusbscribe verbs is pushed even when the connection only
        becomes ready after the subscription is created.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(False)

        sub = chan.subscribe('name', 'topic')

        conn.mock_connection_ready(True)

        conn.assert_upstream_verb(verbs.SubscribeVerb(
            name=b'name',
            topic=b'topic',
            messageref=1,
        ))

        sub.cancel()

        conn.assert_upstream_verb(verbs.UnsubscribeVerb(
            name=b'name',
            topic=b'topic',
        ))

        conn.assert_upstream_verb(None)
Ejemplo n.º 2
0
    def test_subscribe_unsubscribe_1(self):
        """ Test if both an subscribe and unsubscribe verb is pushed when the
        connection is ready before creation of the subscription.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(True)

        sub = chan.subscribe('name', 'topic')

        conn.assert_upstream_verb(verbs.SubscribeVerb(
            name=b'name',
            topic=b'topic',
            messageref=1,
        ))

        sub.cancel()

        conn.assert_upstream_verb(verbs.UnsubscribeVerb(
            name=b'name',
            topic=b'topic',
        ))

        conn.assert_upstream_verb(None)
Ejemplo n.º 3
0
    def test_subscribe_unsubscribe_3(self):
        """ Test if no verbs at all are pushed if the subscription is created and canceled before
        the connection was ready.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(False)

        sub = chan.subscribe('name', 'topic')

        sub.cancel()

        conn.mock_connection_ready(True)

        conn.assert_upstream_verb(None)
Ejemplo n.º 4
0
    def test_subscribe_message_1(self):
        """ Test that the handler is called when a message is received for a subscription.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(True)

        handler = unittest.mock.Mock()
        sub = chan.subscribe('name', 'topic')
        sub.add_handler(handler)

        conn.mock_downstream_verb(verbs.MessageVerb(
            messageref=1,
            status=verbs.MessageVerb.STATUS_OK,
            payload=b'payload1',
        ))

        self.__verify_handler_call(
            handler,
            Message,
            status=MessageStatus.OK,
            payload='payload1',
        )

        conn.mock_downstream_verb(verbs.MessageVerb(
            messageref=1,
            status=verbs.MessageVerb.STATUS_OK,
            payload=b'payload2',
        ))

        self.__verify_handler_call(
            handler,
            Message,
            status=MessageStatus.OK,
            payload='payload2',
        )