Пример #1
0
 def setUp(self):
     self.protocol_mock = Mock(spec=CarbonClientProtocol)
     self.protocol_patch = patch("carbon.client.CarbonClientProtocol", new=Mock(return_value=self.protocol_mock))
     self.protocol_patch.start()
     carbon_client.settings = TestSettings()
     self.factory = CarbonClientFactory(("127.0.0.1", 2003, "a"))
     self.connected_factory = CarbonClientFactory(("127.0.0.1", 2003, "a"))
     self.connected_factory.buildProtocol(None)
     self.connected_factory.started = True
Пример #2
0
 def setUp(self):
     self.protocol_mock = Mock(spec=CarbonClientProtocol)
     self.protocol_patch = patch('carbon.client.CarbonClientProtocol',
                                 new=Mock(return_value=self.protocol_mock))
     self.protocol_patch.start()
     carbon_client.settings = TestSettings()
     self.factory = CarbonClientFactory(('127.0.0.1', 2003, 'a'))
     self.connected_factory = CarbonClientFactory(('127.0.0.1', 2003, 'a'))
     self.connected_factory.buildProtocol(None)
     self.connected_factory.started = True
Пример #3
0
class CarbonClientFactoryTest(TestCase):
    def setUp(self):
        self.protocol_mock = Mock(spec=CarbonClientProtocol)
        self.protocol_patch = patch("carbon.client.CarbonClientProtocol", new=Mock(return_value=self.protocol_mock))
        self.protocol_patch.start()
        carbon_client.settings = TestSettings()
        self.factory = CarbonClientFactory(("127.0.0.1", 2003, "a"))
        self.connected_factory = CarbonClientFactory(("127.0.0.1", 2003, "a"))
        self.connected_factory.buildProtocol(None)
        self.connected_factory.started = True

    def tearDown(self):
        if self.factory.deferSendPending and self.factory.deferSendPending.active():
            self.factory.deferSendPending.cancel()
        self.protocol_patch.stop()

    def test_schedule_send_schedules_call_to_send_queued(self):
        self.factory.scheduleSend()
        self.assertIsInstance(self.factory.deferSendPending, DelayedCall)
        self.assertTrue(self.factory.deferSendPending.active())

    def test_schedule_send_ignores_already_scheduled(self):
        self.factory.scheduleSend()
        expected_fire_time = self.factory.deferSendPending.getTime()
        self.factory.scheduleSend()
        self.assertTrue(expected_fire_time, self.factory.deferSendPending.getTime())

    def test_send_queued_should_noop_if_not_connected(self):
        self.factory.scheduleSend()
        self.assertFalse(self.protocol_mock.sendQueued.called)

    def test_send_queued_should_call_protocol_send_queued(self):
        self.connected_factory.sendQueued()
        self.protocol_mock.sendQueued.assert_called_once_with()
Пример #4
0
 def setUp(self):
     carbon_client.settings = TestSettings()  # reset to defaults
     factory = CarbonClientFactory(("127.0.0.1", 2003, "a"))
     self.protocol = factory.buildProtocol(("127.0.0.1", 2003))
     self.transport = StringTransport()
     self.protocol.makeConnection(self.transport)
Пример #5
0
class CarbonClientFactoryTest(TestCase):
    def setUp(self):
        self.protocol_mock = Mock(spec=CarbonClientProtocol)
        self.protocol_patch = patch('carbon.client.CarbonClientProtocol',
                                    new=Mock(return_value=self.protocol_mock))
        self.protocol_patch.start()
        carbon_client.settings = TestSettings()
        self.factory = CarbonClientFactory(('127.0.0.1', 2003, 'a'))
        self.connected_factory = CarbonClientFactory(('127.0.0.1', 2003, 'a'))
        self.connected_factory.buildProtocol(None)
        self.connected_factory.started = True

    def tearDown(self):
        if self.factory.deferSendPending and self.factory.deferSendPending.active(
        ):
            self.factory.deferSendPending.cancel()
        self.protocol_patch.stop()

    def test_schedule_send_schedules_call_to_send_queued(self):
        self.factory.scheduleSend()
        self.assertIsInstance(self.factory.deferSendPending, DelayedCall)
        self.assertTrue(self.factory.deferSendPending.active())

    def test_schedule_send_ignores_already_scheduled(self):
        self.factory.scheduleSend()
        expected_fire_time = self.factory.deferSendPending.getTime()
        self.factory.scheduleSend()
        self.assertTrue(expected_fire_time,
                        self.factory.deferSendPending.getTime())

    def test_send_queued_should_noop_if_not_connected(self):
        self.factory.scheduleSend()
        self.assertFalse(self.protocol_mock.sendQueued.called)

    def test_send_queued_should_call_protocol_send_queued(self):
        self.connected_factory.sendQueued()
        self.protocol_mock.sendQueued.assert_called_once_with()
Пример #6
0
 def setUp(self):
     carbon_client.settings = TestSettings()  # reset to defaults
     factory = CarbonClientFactory(('127.0.0.1', 2003, 'a'))
     self.protocol = factory.buildProtocol(('127.0.0.1', 2003))
     self.transport = StringTransport()
     self.protocol.makeConnection(self.transport)