Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Aug 24, 2022
1 parent 4153678 commit 5386c20
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/ext/commands/test_base_core.py
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)

0 comments on commit 5386c20

Please sign in to comment.