def dispatch(self, frame): ''' Override the default dispatch since we don't need the rest of the stack. ''' if frame.type() == HeartbeatFrame.type(): self.send_heartbeat() elif frame.type() == MethodFrame.type(): if frame.class_id == 10: cb = self._method_map.get(frame.method_id) if cb: method = self.clear_synchronous_cb(cb) method(frame) else: raise Channel.InvalidMethod( "unsupported method %d on channel %d", frame.method_id, self.channel_id) else: raise Channel.InvalidClass( "class %d is not supported on channel %d", frame.class_id, self.channel_id) else: raise Frame.InvalidFrameType( "frame type %d is not supported on channel %d", frame.type(), self.channel_id)
def test_dispatch_method_frame_raises_invalidclass(self): frame = mock() frame.class_id = 11 frame.method_id = 10 expect(frame.type).returns(MethodFrame.type()) with assert_raises(Channel.InvalidClass): self.ch.dispatch(frame)
def test_dispatch_method_frame_class_10(self): frame = mock() frame.class_id = 10 frame.method_id = 10 method = self.ch._method_map[10] = mock() expect(frame.type).returns(MethodFrame.type()) expect(method).args(frame) self.ch.dispatch(frame)
def test_dispatch_runs_callbacks(self): frame = mock() frame.class_id = 10 frame.method_id = 10 method = self.ch._method_map[10] = mock() cb = mock() expect(frame.type).returns(MethodFrame.type()) expect(self.ch.clear_synchronous_cb).args(method).returns(cb) expect(cb).args(frame) self.ch.dispatch(frame)
def test_type(self): assert_equals(1, MethodFrame.type())