def test_log_while_connecting(self): connect_d = Deferred() real_connect = self.endpoint.connect.side_effect def _delay_connect(factory): d = real_connect(factory) connect_d.addCallback(lambda _: d) return connect_d self.endpoint.connect.side_effect = _delay_connect client = ScribeClient(self.endpoint) d = client.log('category', 'message') self.assertEqual(self.client_proto.client.Log.call_count, 0) d2 = client.log('category', 'message') self.assertEqual(self.client_proto.client.Log.call_count, 0) connect_d.callback(None) self.assertEqual(self.assertFired(d), ttypes.ResultCode.OK) self.assertEqual(self.assertFired(d2), ttypes.ResultCode.OK) self.assertEqual(self.client_proto.client.Log.call_count, 2)
def test_log_already_connected(self): client = ScribeClient(self.endpoint) d = client.log('category', 'message') self.assertEqual(self.assertFired(d), ttypes.ResultCode.OK) self.assertEqual(self.client_proto.client.Log.call_count, 1) d = client.log('category', 'message') self.assertEqual(self.assertFired(d), ttypes.ResultCode.OK) self.assertEqual(self.client_proto.client.Log.call_count, 2)
def test_log_string(self): client = ScribeClient(self.endpoint) d = client.log('category', 'message') self.assertEqual(self.assertFired(d), ttypes.ResultCode.OK) self.client_proto.client.Log.assert_called_with( [ttypes.LogEntry('category', 'message')])