Tested request_guild_members
@@ -94,6 +94,10 @@ class TestGatewayClientConstructor:
assert client.shard_id == expected_shard_id
assert client.shard_count == expected_shard_count
+ async def test_dispatch_is_callable(self):
+ client = gateway.GatewayClient(token="xxx", url="yyy")
+ client.dispatch(client, "ping", "pong")
+
@pytest.mark.parametrize(
["compression", "expected_url_query"],
[
@@ -809,3 +813,63 @@ class TestPollEvents:
await client._poll_events()
client.dispatch.assert_called_with(client, "MESSAGE_CREATE", {"content": "whatever"})
+
+
+@pytest.mark.asyncio
+class TestRequestGuildMembers:
+ @pytest.fixture
+ def client(self, event_loop):
+ asyncio.set_event_loop(event_loop)
+ client = _helpers.unslot_class(gateway.GatewayClient)(token="1234", url="xxx")
+ client = _helpers.mock_methods_on(client, except_=("request_guild_members",))
+ return client
+
+ async def test_no_kwargs(self, client):
+ await client.request_guild_members("1234", "5678")
+ client._send.assert_awaited_once_with({
+ "op": 8,
+ "d": {
+ "guild_id": ["1234", "5678"], "query": "", "limit": 0
+ }
+ })
+
+ @pytest.mark.parametrize(
+ ["kwargs", "expected_limit", "expected_query"],
+ [
+ ({"limit": 22}, 22, ""),
+ ({"query": "lol"}, 0, "lol"),
+ ({"limit": 22, "query": "lol"}, 22, "lol"),
+ ]
+ )
+ async def test_limit_and_query(self, client, kwargs, expected_limit, expected_query):
+ await client.request_guild_members("1234", "5678", **kwargs)
+ client._send.assert_awaited_once_with({
+ "op": 8,
+ "d": {
+ "guild_id": ["1234", "5678"],
+ "query": expected_query,
+ "limit": expected_limit,
+ }
+ })
+
+ async def test_user_ids(self, client):
+ await client.request_guild_members("1234", "5678", user_ids=["9", "18", "27"])
+ client._send.assert_awaited_once_with({
+ "op": 8,
+ "d": {
+ "guild_id": ["1234", "5678"], "user_ids": ["9", "18", "27"]
+ }
+ })
+
+ @pytest.mark.parametrize("presences", [True, False])
+ async def test_presences(self, client, presences):
+ await client.request_guild_members("1234", "5678", presences=presences)
+ client._send.assert_awaited_once_with({
+ "op": 8,
+ "d": {
+ "guild_id": ["1234", "5678"],
+ "query": "",
+ "limit": 0,
+ "presences": presences
+ }
+ })
