-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathtest_cache.py
58 lines (46 loc) · 1.85 KB
/
test_cache.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import discord_typings
import pytest
from interactions.client.client import Client
from interactions.models.discord.channel import DM, GuildText
from interactions.models.discord.snowflake import to_snowflake
from tests.consts import SAMPLE_DM_DATA, SAMPLE_GUILD_DATA, SAMPLE_USER_DATA
__all__ = ("bot", "test_dm_channel", "test_get_user_from_dm", "test_guild_channel", "test_update_guild")
@pytest.fixture()
def bot() -> Client:
return Client()
def test_dm_channel(bot: Client) -> None:
channel = bot.cache.place_channel_data(SAMPLE_DM_DATA())
assert isinstance(channel, DM)
assert channel.recipient.id == to_snowflake(SAMPLE_USER_DATA()["id"])
channel2 = bot.cache.get_channel(channel.id)
assert channel2 is channel
def test_get_user_from_dm(bot: Client) -> None:
bot.cache.place_channel_data(SAMPLE_DM_DATA())
user = bot.cache.get_user(to_snowflake(SAMPLE_USER_DATA()["id"]))
assert user is not None
assert user.username == SAMPLE_USER_DATA()["username"]
def test_guild_channel(bot: Client) -> None:
bot.cache.place_guild_data(SAMPLE_GUILD_DATA())
data: discord_typings.TextChannelData = {
"id": "12345",
"type": 0,
"guild_id": SAMPLE_GUILD_DATA()["id"],
"position": 0,
"last_message_id": None,
"permission_overwrites": [],
"name": "general",
"topic": None,
"nsfw": False,
"parent_id": None,
"rate_limit_per_user": 0,
}
channel = bot.cache.place_channel_data(data)
assert isinstance(channel, GuildText)
assert channel.guild.id == to_snowflake(SAMPLE_GUILD_DATA()["id"])
def test_update_guild(bot: Client) -> None:
guild = bot.cache.place_guild_data(SAMPLE_GUILD_DATA())
assert guild.mfa_level == 0
data = SAMPLE_GUILD_DATA()
data["mfa_level"] = 1
bot.cache.place_guild_data(data)
assert guild.mfa_level == 1