-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import pytest | ||
|
||
from disnake import Permissions | ||
from disnake.ext import commands | ||
|
||
|
||
class TestDefaultPermissions: | ||
def test_decorator(self): | ||
class Cog(commands.Cog): | ||
@commands.slash_command(default_member_permissions=64) | ||
async def cmd(self, _): | ||
... | ||
|
||
@commands.default_member_permissions(64) | ||
@commands.slash_command() | ||
async def above(self, _): | ||
... | ||
|
||
@commands.slash_command() | ||
@commands.default_member_permissions(64) | ||
async def below(self, _): | ||
... | ||
|
||
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): | ||
# 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, _): | ||
... | ||
|
||
# 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, _): | ||
... | ||
|
||
for c in (Cog2, Cog2()): | ||
assert c.below.default_member_permissions == Permissions(32) | ||
|
||
def test_attrs(self): | ||
class Cog(commands.Cog, slash_command_attrs={"default_member_permissions": 32}): | ||
@commands.slash_command() | ||
async def no_overwrite(self, _): | ||
... | ||
|
||
@commands.slash_command(default_member_permissions=64) | ||
async def overwrite(self, _): | ||
... | ||
|
||
@commands.default_member_permissions(64) | ||
@commands.slash_command() | ||
async def overwrite_decorator_above(self, _): | ||
... | ||
|
||
@commands.slash_command() | ||
@commands.default_member_permissions(64) | ||
async def overwrite_decorator_below(self, _): | ||
... | ||
|
||
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) |