示例#1
0
    def test_resend_exhausted(self, sleep, delivery):
        url = 'test-url'
        delivery.RELEASED = 1
        fn = Mock(side_effect=SendException(delivery.RELEASED))
        messenger = Mock(url=url, connection=Mock())
        args = (messenger, 2, 3)
        kwargs = {'A': 1}

        # test
        wrapped = resend(fn)
        wrapped(*args, **kwargs)

        # validation
        self.assertEqual(
            sleep.call_args_list,
            [
                ((RESEND_DELAY,), {}),
                ((RESEND_DELAY,), {}),
                ((RESEND_DELAY,), {}),
                ((RESEND_DELAY,), {}),
            ])
        self.assertEqual(
            fn.call_args_list,
            [
                (args, kwargs),
                (args, kwargs),
                (args, kwargs),
                (args, kwargs),
            ])
示例#2
0
    def test_resend_exhausted(self, sleep, delivery):
        url = 'test-url'
        delivery.RELEASED = 1
        fn = Mock(side_effect=SendException(delivery.RELEASED))
        messenger = Mock(url=url, connection=Mock())
        args = (messenger, 2, 3)
        kwargs = {'A': 1}

        # test
        wrapped = resend(fn)
        wrapped(*args, **kwargs)

        # validation
        self.assertEqual(sleep.call_args_list, [
            ((RESEND_DELAY, ), {}),
            ((RESEND_DELAY, ), {}),
            ((RESEND_DELAY, ), {}),
            ((RESEND_DELAY, ), {}),
        ])
        self.assertEqual(fn.call_args_list, [
            (args, kwargs),
            (args, kwargs),
            (args, kwargs),
            (args, kwargs),
        ])
示例#3
0
    def test_resend_rejected(self, sleep, delivery):
        url = 'test-url'
        delivery.RELEASED = 1
        delivery.REJECTED = 2
        fn = Mock(side_effect=[SendException(delivery.REJECTED), None])
        messenger = Mock(url=url, connection=Mock())
        args = (messenger, 2, 3)
        kwargs = {'A': 1}

        # test
        wrapped = resend(fn)
        self.assertRaises(SendException, wrapped, *args, **kwargs)
        self.assertFalse(sleep.called)
示例#4
0
    def test_resend_rejected(self, sleep, delivery):
        url = 'test-url'
        delivery.RELEASED = 1
        delivery.REJECTED = 2
        fn = Mock(side_effect=[SendException(delivery.REJECTED), None])
        messenger = Mock(url=url, connection=Mock())
        args = (messenger, 2, 3)
        kwargs = {'A': 1}

        # test
        wrapped = resend(fn)
        self.assertRaises(SendException, wrapped, *args, **kwargs)
        self.assertFalse(sleep.called)
示例#5
0
    def test_resend_released(self, sleep, delivery):
        url = 'test-url'
        delivery.RELEASED = 1
        fn = Mock(side_effect=[SendException(delivery.RELEASED), None])
        messenger = Mock(url=url, connection=Mock())
        args = (messenger, 2, 3)
        kwargs = {'A': 1}

        # test
        wrapped = resend(fn)
        wrapped(*args, **kwargs)

        # validation
        sleep.assert_called_once_with(RESEND_DELAY)
        self.assertEqual(fn.call_args_list, [
            (args, kwargs),
            (args, kwargs),
        ])
示例#6
0
    def test_resend_released(self, sleep, delivery):
        url = 'test-url'
        delivery.RELEASED = 1
        fn = Mock(side_effect=[SendException(delivery.RELEASED), None])
        messenger = Mock(url=url, connection=Mock())
        args = (messenger, 2, 3)
        kwargs = {'A': 1}

        # test
        wrapped = resend(fn)
        wrapped(*args, **kwargs)

        # validation
        sleep.assert_called_once_with(RESEND_DELAY)
        self.assertEqual(
            fn.call_args_list,
            [
                (args, kwargs),
                (args, kwargs),
            ])