def test_sendEvent_should_not_drop_data_when_connection(self, check_connection):
        check_connection.return_value = True
        ybc = WampBroadcaster("host", 42)
        ybc.target = "broadcaster-target"
        ybc.logger = Mock()
        ybc.client = Mock()

        WampBroadcaster._sendEvent(ybc, "event-id", "event-data", tracking_id="tracking-id", target="target")

        self.assertTrue(ybc.client.publish.called)
    def test_sendEvent_should_not_drop_data_when_connection(self, check_connection):
        check_connection.return_value = True
        ybc = WampBroadcaster('host', 42)
        ybc.target = 'broadcaster-target'
        ybc.logger = Mock()
        ybc.client = Mock()

        WampBroadcaster._sendEvent(ybc,
                                   'event-id',
                                   'event-data',
                                   tracking_id='tracking-id',
                                   target='target')

        self.assertTrue(ybc.client.publish.called)
    def test_should_publish_cmd_for_default_target(self):
        ybc = WampBroadcaster('host', 42)
        ybc.target = 'broadcaster-target'
        ybc.logger = Mock()
        ybc.client = Mock()

        ybc.publish_cmd('status', 'failed', 'hello', 'nsa-tracking')

        ybc.client.publish.assert_called_with('broadcaster-target', {
            'cmd': 'status',
            'state': 'failed',
            'payload': None,
            'tracking_id': 'nsa-tracking',
            'message': 'hello',
            'type': 'event',
            'target': 'broadcaster-target',
            'id': 'cmd'})
    def test_should_publish_request_for_target(self):

        ybc = WampBroadcaster('host', 42)
        ybc.target = 'broadcaster-target'
        ybc.logger = Mock()
        ybc.client = Mock()

        ybc.publish_request_for_target('target', 'cmd', 'args', 'nsa-tracker')

        ybc.client.publish.assert_called_with('target',
                                              {
                                                  'args': 'args',
                                                  'cmd': 'cmd',
                                                  'type': 'event',
                                                  'id': 'request',
                                                  'payload': None,
                                                  'target': 'target',
                                                  'tracking_id': 'nsa-tracker'})
    def test_should_publish_request_for_target(self):

        ybc = WampBroadcaster("host", 42)
        ybc.target = "broadcaster-target"
        ybc.logger = Mock()
        ybc.client = Mock()

        ybc.publish_request_for_target("target", "cmd", "args", "nsa-tracker")

        ybc.client.publish.assert_called_with(
            "target",
            {
                "args": "args",
                "cmd": "cmd",
                "type": "event",
                "id": "request",
                "payload": None,
                "target": "target",
                "tracking_id": "nsa-tracker",
            },
        )
    def test_should_publish_cmd_for_target(self):
        ybc = WampBroadcaster("host", 42)
        ybc.target = "broadcaster-target"
        ybc.logger = Mock()
        ybc.client = Mock()

        ybc.publish_cmd_for_target("target", "status", "failed", "hello", "nsa-tracking")

        ybc.client.publish.assert_called_with(
            "target",
            {
                "cmd": "status",
                "state": "failed",
                "payload": None,
                "tracking_id": "nsa-tracking",
                "message": "hello",
                "type": "event",
                "target": "target",
                "id": "cmd",
            },
        )