def test_request_stream(): _body = dict(Type='*') _request = serf.get_request_class('stream')(**_body) _request.check(FakeClient(), ) assert _request.is_checked _body = dict( # missing value ) _request = serf.get_request_class('stream')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked _body = dict( Type=True, # this must be str ) _request = serf.get_request_class('stream')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_handshake(): _request = serf.get_request_class('handshake')() _request.check(FakeClient(), ) assert _request.is_checked assert 'Version' in _request.body assert _request.body.get('Version') == FakeClient.ipc_version # set by default in Client _new_ipc_version = 101 _request = serf.get_request_class('handshake')() _request.check(FakeClient(ipc_version=_new_ipc_version, ), ) assert _request.is_checked assert 'Version' in _request.body assert _request.body.get('Version') == _new_ipc_version # set in request body _new_ipc_version = 99 _request = serf.get_request_class('handshake')(Version=_new_ipc_version, ) _request.check(FakeClient(), ) assert _request.is_checked assert 'Version' in _request.body assert _request.body.get('Version') == _new_ipc_version
def test_request_auth(): _body = dict(AuthKey='auth-key', ) _request = serf.get_request_class('auth')(**_body) _request.check(FakeClient(), ) assert _request.is_checked _body = dict( AuthKey=1, # `AuthKey` must be str ) _request = serf.get_request_class('auth')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked _body = dict( # empty values ) _request = serf.get_request_class('auth')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_monitor(): _body = dict(LogLevel='DEBUG', ) _request = serf.get_request_class('monitor')(**_body) _request.check(FakeClient(), ) assert _request.is_checked _body = dict( # missing value ) _request = serf.get_request_class('monitor')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked _body = dict( LogLevel=True, # this must be str ) _request = serf.get_request_class('monitor')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_event () : _body = dict( Name='anonymous-event', Payload='payload', ) _request = serf.get_request_class('event')(**_body) _request.check(FakeClient(), ) assert _request.is_checked _body = dict( Name='anonymous-event', Payload='payload', Coalesce=1, # `Coalesce` is not bool type ) _request = serf.get_request_class('event')(**_body) with pytest.raises(serf.InvalidRequest, ) : _request.check(FakeClient(), ) assert not _request.is_checked _body = dict( # empty values ) _request = serf.get_request_class('event')(**_body) with pytest.raises(serf.InvalidRequest, ) : _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_join () : _body = dict( Existing=('127.0.0.1:7901', ), Replay=True, ) _request = serf.get_request_class('join')(**_body) _request.check(FakeClient(), ) assert _request.is_checked _body = dict( # missing value What='is it', ) _request = serf.get_request_class('join')(**_body) with pytest.raises(serf.InvalidRequest, ) : _request.check(FakeClient(), ) assert not _request.is_checked _body = dict( Existing=('127.0.0.1:7901', ), Replay=1, # invalid value, it must be bool ) _request = serf.get_request_class('join')(**_body) with pytest.raises(serf.InvalidRequest, ) : _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_stop(): _body = dict(Stop=10, ) _request = serf.get_request_class('stop')(**_body) _request.check(FakeClient(), ) assert _request.is_checked _body = dict( # unknown values Name='anonymous-stop', Payload='payload', Coalesce=1, ) _request = serf.get_request_class('stop')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked _body = dict( # empty values ) _request = serf.get_request_class('stop')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_members(): _request = serf.get_request_class('members')() _request.check(FakeClient(), ) assert _request.is_checked _body = dict(What='is it', ) _request = serf.get_request_class('members')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_force_leave(): _body = dict(Node='node0', ) _request = serf.get_request_class('force_leave')(**_body) _request.check(FakeClient(), ) assert _request.is_checked # `Coalesce` is not bool type _body = dict() _request = serf.get_request_class('force_leave')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_respond_payload_size_limit(): _client = FakeClient() _body_normal = dict( ID=10, Payload='a', ) _request = serf.get_request_class('respond')(**_body_normal) _request.check(_client, ) assert _request.is_checked _dumped = '' _n = 10 _body_without_payload = dict( ID=10, Payload='', ) while len(str(_dumped)) < serf.constant.RESPOND_PAYLOAD_SIZE_LIMIT: _body_without_payload['Payload'] = 'a' * _n _dumped = serf.get_request_class('respond', ).dumps( _request.command, _client.seq, _body_without_payload, ) _n += 1 _body_overlimit = _body_without_payload.copy() _body_overlimit['Payload'] = 'a' * (_n + 1) _request = serf.get_request_class('respond')(**_body_overlimit) with pytest.raises(serf.InvalidRequest): _request.check(FakeClient(), ) _body_overlimit['Payload'] = 'a' * (_n - 1) _request = serf.get_request_class('respond')(**_body_overlimit) _request.check(FakeClient(), ) assert _request.is_checked
def test_request_respond(): _body = dict( ID=10, Payload='payload', ) _request = serf.get_request_class('respond')(**_body) _request.check(FakeClient(), ) assert _request.is_checked _body = dict( ID='not-int', Payload='payload', ) _request = serf.get_request_class('respond')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked
def test_request_event_payload_size_limit () : _body_normal = dict( Name='anonymous-event', Payload='payload', ) _request = serf.get_request_class('event')(**_body_normal) _request.check(FakeClient(), ) assert _request.is_checked _dumped = '' _n = 10 _body_without_payload = dict(Name='anonymous-event', Payload='', ) while len(_dumped) < serf.constant.PAYLOAD_SIZE_LIMIT : _body_without_payload['Payload'] = 'a' * _n _dumped = serf.get_request_class('event', ).dumps( _request.command, 0, _body_without_payload, ) _n += 1 _body_overlimit = _body_without_payload.copy() _body_overlimit['Payload'] = 'a' * (_n + 1) _request = serf.get_request_class('event')(**_body_overlimit) with pytest.raises(serf.InvalidRequest) : _request.check(FakeClient(), ) _body_overlimit['Payload'] = 'a' * (_n - 1) _request = serf.get_request_class('event')(**_body_overlimit) _request.check(FakeClient(), ) assert _request.is_checked
def test_request_query(): _body = dict( FilterNodes=[ "node0", "node1", ], FilterTags={"role": ".*"}, RequestAck=True, Timeout=0, Name='response-me', Payload='this is payload of `response-me` query event', ) _request = serf.get_request_class('query')(**_body) _request.check(FakeClient(), ) assert _request.is_checked _body = dict( # missing value ) _request = serf.get_request_class('query')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked _body = dict( Name='response-me', Timeout='string', ) _request = serf.get_request_class('query')(**_body) with pytest.raises(serf.InvalidRequest, ): _request.check(FakeClient(), ) assert not _request.is_checked