Beispiel #1
0
    def test_connects_directly(self, sleep):
        connector = Mock()
        data_transport = DataTransport(connector)
        data_transport.send = Mock()
        data_transport.deliver_event(Event("test"))

        connector.connect.assert_called_once()
        assert sleep.call_count == 0
    def test_connects_directly(self, sleep):
        connector = Mock()
        data_transport = DataTransport(connector)
        data_transport.send = Mock()
        data_transport.deliver_event(Event("test"))

        connector.connect.assert_called_once()
        assert sleep.call_count == 0
Beispiel #3
0
    def test_connects_after_retries(self, sleep):
        data_transport = DataTransport(
            FailsAfterNTimes(2, with_exception=ConnectionError))
        data_transport.send = Mock()
        data_transport.deliver_event(Event("test"))

        data_transport.send.assert_called_once_with("decoded test")

        assert sleep.call_count == DataTransport.retry_n_times - 1, sleep.call_count
    def test_connects_after_retries(self, sleep):
        data_transport = DataTransport(
            FailsAfterNTimes(2, with_exception=ConnectionError)
        )
        data_transport.send = Mock()
        data_transport.deliver_event(Event("test"))

        data_transport.send.assert_called_once_with("decoded test")

        assert (
            sleep.call_count == DataTransport.retry_n_times - 1
        ), sleep.call_count
Beispiel #5
0
    def test_error_in_event(self, sleep):
        data_transport = DataTransport(Mock())
        event = Mock(decode=Mock(side_effect=ValueError))
        with patch("exceptions_1.logger.error"):
            self.assertRaises(ValueError, data_transport.deliver_event, event)

        assert not sleep.called
Beispiel #6
0
    def test_connection_error(self, sleep):
        data_transport = DataTransport(
            Mock(connect=Mock(side_effect=ConnectionError)))

        self.assertRaisesRegex(
            ConnectionError,
            "Couldn't connect after \d+ times",
            data_transport.deliver_event,
            Event("connection error"),
        )
        assert sleep.call_count == DataTransport._RETRY_TIMES