Example #1
0
    def test_send_not_addressed(self, send):
        node = Queue()
        plugin = Mock(url='')
        request = Document(replyto=None)
        status = 'rejected'
        consumer = RequestConsumer(node, plugin)

        # Test
        consumer.send(request, status)

        # Validation
        self.assertFalse(send.called)
Example #2
0
    def test_send_not_addressed(self, send):
        node = Queue()
        plugin = Mock(url='')
        request = Document(replyto=None)
        status = 'rejected'
        consumer = RequestConsumer(node, plugin)

        # Test
        consumer.send(request, status)

        # Validation
        self.assertFalse(send.called)
Example #3
0
    def test_send(self, ts, _open, _close, send):
        send.side_effect = ValueError
        node = Queue()
        plugin = Mock(url='')
        request = Document(sn=1, replyto='elmer', data=123)
        status = 'rejected'
        details = dict(a=1)
        consumer = RequestConsumer(node, plugin)

        # Test
        consumer.send(request, status, **details)

        # Validation
        _open.assert_called_once_with()
        _close.assert_called_once_with()
Example #4
0
    def test_send(self, ts, _open, _close, send):
        send.side_effect = ValueError
        node = Queue()
        plugin = Mock(url='')
        request = Document(
            sn=1,
            replyto='elmer',
            data=123)
        status = 'rejected'
        details = dict(a=1)
        consumer = RequestConsumer(node, plugin)

        # Test
        consumer.send(request, status, **details)

        # Validation
        _open.assert_called_once_with()
        _close.assert_called_once_with()
Example #5
0
    def test_send(self, ts, _open, _close, send):
        node = Queue()
        plugin = Mock(url='')
        request = Document(sn=1, replyto='elmer', data=123)
        status = 'rejected'
        details = dict(a=1)
        consumer = RequestConsumer(node, plugin)

        # Test
        consumer.send(request, status, **details)

        # Validation
        _open.assert_called_once_with()
        send.assert_called_once_with(request.replyto,
                                     sn=request.sn,
                                     data=request.data,
                                     status=status,
                                     timestamp=ts.return_value,
                                     **details)
        _close.assert_called_once_with()
Example #6
0
    def test_dispatch(self):
        node = Queue()
        plugin = Mock(url='')
        request = Document()
        consumer = RequestConsumer(node, plugin)
        consumer.send = Mock()

        # Test
        consumer.dispatch(request)

        # Validation
        consumer.send.assert_called_once_with(request, 'accepted')
        plugin.scheduler.add.assert_called_once_with(request)
Example #7
0
    def test_dispatch(self):
        node = Queue()
        plugin = Mock(url='')
        request = Document()
        consumer = RequestConsumer(node, plugin)
        consumer.send = Mock()

        # Test
        consumer.dispatch(request)

        # Validation
        consumer.send.assert_called_once_with(request, 'accepted')
        plugin.scheduler.add.assert_called_once_with(request)
Example #8
0
    def test_send(self, ts, _open, _close, send):
        node = Queue()
        plugin = Mock(url='')
        request = Document(
            sn=1,
            replyto='elmer',
            data=123)
        status = 'rejected'
        details = dict(a=1)
        consumer = RequestConsumer(node, plugin)

        # Test
        consumer.send(request, status, **details)

        # Validation
        _open.assert_called_once_with()
        send.assert_called_once_with(
            request.replyto,
            sn=request.sn,
            data=request.data,
            status=status,
            timestamp=ts.return_value,
            **details)
        _close.assert_called_once_with()
Example #9
0
    def test_rejected(self):
        node = Queue()
        plugin = Mock(url='')
        code = '401'
        description = 'failed'
        details = dict(msg='failed')
        document = Document(field='value')
        consumer = RequestConsumer(node, plugin)
        consumer.send = Mock()

        # Test
        consumer.rejected(code, description, document, details)

        # Validation
        consumer.send.assert_called_once_with(
            document, 'rejected', **{
                'code': code,
                'description': description,
                'details': details,
            })
Example #10
0
    def test_rejected(self):
        node = Queue()
        plugin = Mock(url='')
        code = '401'
        description = 'failed'
        details = dict(msg='failed')
        document = Document(field='value')
        consumer = RequestConsumer(node, plugin)
        consumer.send = Mock()

        # Test
        consumer.rejected(code, description, document, details)

        # Validation
        consumer.send.assert_called_once_with(
            document,
            'rejected',
            **{
                'code' : code,
                'description': description,
                'details': details,
            }
        )