Пример #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),
            ])