def test_protocol_connectionReady(self): proto = MongoProtocol() d1 = proto.connectionReady() d2 = proto.connectionReady() d1.cancel() with AssertCallbackNotCalled(d1): proto.makeConnection(proto_helpers.StringTransport()) self.assertTrue(d2.called) self.failureResultOf(d1, defer.CancelledError)
def test_protocol_query(self): tr = proto_helpers.StringTransport() proto = MongoProtocol() proto.makeConnection(tr) d = proto.send_QUERY(Query(query={'x': 42})) d.cancel() with AssertCallbackNotCalled(d): reply = Reply(response_to=1, documents=[{'x': 42}]) reply_bin = struct.pack("<iiiiqii", 1, *reply[2:8]) + b''.join(reply.documents) reply_bin = struct.pack('<i', len(reply_bin) + 4) + reply_bin proto.dataReceived(reply_bin) self.failureResultOf(d, defer.CancelledError)