-
Notifications
You must be signed in to change notification settings - Fork 139
/
test_base_core.py
84 lines (65 loc) · 3.21 KB
/
test_base_core.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# SPDX-License-Identifier: MIT
import pytest
from disnake import Permissions
from disnake.ext import commands
class TestDefaultPermissions:
def test_decorator(self) -> None:
class Cog(commands.Cog):
@commands.slash_command(default_member_permissions=64)
async def cmd(self, _) -> None:
...
@commands.default_member_permissions(64)
@commands.slash_command()
async def above(self, _) -> None:
...
@commands.slash_command()
@commands.default_member_permissions(64)
async def below(self, _) -> None:
...
for c in (Cog, Cog()):
assert c.cmd.default_member_permissions == Permissions(64)
assert c.above.default_member_permissions == Permissions(64)
assert c.below.default_member_permissions == Permissions(64)
def test_decorator_overwrite(self) -> None:
# putting the decorator above should fail
with pytest.raises(ValueError, match="Cannot set `default_member_permissions`"):
class Cog(commands.Cog):
@commands.default_member_permissions(32)
@commands.slash_command(default_member_permissions=64)
async def above(self, _) -> None:
...
# putting the decorator below shouldn't fail
# (this is a side effect of how command copying works,
# and while this *should* probably fail, we're just testing
# for regressions for now)
class Cog2(commands.Cog):
@commands.slash_command(default_member_permissions=64)
@commands.default_member_permissions(32)
async def below(self, _) -> None:
...
for c in (Cog2, Cog2()):
assert c.below.default_member_permissions == Permissions(32)
def test_attrs(self) -> None:
class Cog(commands.Cog, slash_command_attrs={"default_member_permissions": 32}):
@commands.slash_command()
async def no_overwrite(self, _) -> None:
...
@commands.slash_command(default_member_permissions=64)
async def overwrite(self, _) -> None:
...
@commands.default_member_permissions(64)
@commands.slash_command()
async def overwrite_decorator_above(self, _) -> None:
...
@commands.slash_command()
@commands.default_member_permissions(64)
async def overwrite_decorator_below(self, _) -> None:
...
assert Cog.no_overwrite.default_member_permissions is None
assert Cog().no_overwrite.default_member_permissions == Permissions(32)
assert Cog.overwrite.default_member_permissions == Permissions(64)
assert Cog().overwrite.default_member_permissions == Permissions(64)
assert Cog.overwrite_decorator_above.default_member_permissions == Permissions(64)
assert Cog().overwrite_decorator_above.default_member_permissions == Permissions(64)
assert Cog.overwrite_decorator_below.default_member_permissions == Permissions(64)
assert Cog().overwrite_decorator_below.default_member_permissions == Permissions(64)