Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more testing #402

Merged
merged 1 commit into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions hikari/api/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,32 @@ async def disconnect(self) -> None:
@abc.abstractmethod
async def connect_to(
self,
channel: snowflakes.SnowflakeishOr[channels.GuildVoiceChannel],
guild: snowflakes.SnowflakeishOr[guilds.Guild],
channel: snowflakes.SnowflakeishOr[channels.GuildVoiceChannel],
voice_connection_type: typing.Type[_VoiceConnectionT],
*,
deaf: bool = False,
mute: bool = False,
voice_connection_type: typing.Type[_VoiceConnectionT],
**kwargs: typing.Any,
) -> _VoiceConnectionT:
"""Connect to a given voice channel.

Parameters
----------
channel : hikari.snowflakes.SnowflakeishOr[hikari.channels.GuildVoiceChannel]
The channel or channel ID to connect to.
guild : hikari.snowflakes.SnowflakeishOr[hikari.guilds.Guild]
The guild to connect to.
channel : hikari.snowflakes.SnowflakeishOr[hikari.channels.GuildVoiceChannel]
The channel or channel ID to connect to.
voice_connection_type : typing.Type[VoiceConnection]
The type of voice connection to use. This should be initialized
internally using the `IVoiceConnection.initialize`
`builtins.classmethod`.
deaf : builtins.bool
Defaulting to `builtins.False`, if `builtins.True`, the client will
enter the voice channel deafened (thus unable to hear other users).
mute : builtins.bool
Defaulting to `builtins.False`, if `builtins.True`, the client will
enter the voice channel muted (thus unable to send audio).
voice_connection_type : typing.Type[VoiceConnection]
The type of voice connection to use. This should be initialized
internally using the `IVoiceConnection.initialize`
`builtins.classmethod`.
**kwargs : typing.Any
Any arguments to provide to the `IVoiceConnection.initialize`
method.
Expand Down
2 changes: 1 addition & 1 deletion hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ def deserialize_template(self, payload: data_binding.JSONObject) -> template_mod
created_at=time.iso8601_datetime_string_to_datetime(payload["created_at"]),
updated_at=time.iso8601_datetime_string_to_datetime(payload["updated_at"]),
source_guild=source_guild,
is_dirty=payload["is_dirty"],
is_unsynced=bool(payload["is_dirty"]),
)

###############
Expand Down
8 changes: 3 additions & 5 deletions hikari/impl/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@
from hikari.internal import ux

if typing.TYPE_CHECKING:
_VoiceEventCallbackT = typing.Callable[[voice_events.VoiceEvent], typing.Coroutine[None, typing.Any, None]]
_VoiceConnectionT = typing.TypeVar("_VoiceConnectionT", bound="voice.VoiceConnection")

_LOGGER: typing.Final[logging.Logger] = logging.getLogger("hikari.voice.management")

_VoiceConnectionT = typing.TypeVar("_VoiceConnectionT", bound="voice.VoiceConnection")


class VoiceComponentImpl(voice.VoiceComponent):
"""A standard voice component management implementation.
Expand Down Expand Up @@ -81,12 +79,12 @@ async def close(self) -> None:

async def connect_to(
self,
channel: snowflakes.SnowflakeishOr[channels.GuildVoiceChannel],
guild: snowflakes.SnowflakeishOr[guilds.PartialGuild],
channel: snowflakes.SnowflakeishOr[channels.GuildVoiceChannel],
voice_connection_type: typing.Type[_VoiceConnectionT],
*,
deaf: bool = False,
mute: bool = False,
voice_connection_type: typing.Type[_VoiceConnectionT],
**kwargs: typing.Any,
) -> _VoiceConnectionT:
guild_id = snowflakes.Snowflake(guild)
Expand Down
7 changes: 1 addition & 6 deletions hikari/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ class TemplateGuild(guilds.PartialGuild):
"""Return flags for the guild system channel.

These are used to describe which notifications are suppressed.

Returns
-------
GuildSystemChannelFlag
The system channel flags for this channel.
"""


Expand Down Expand Up @@ -176,7 +171,7 @@ class Template:
source_guild: TemplateGuild = attr.ib(eq=False, hash=False, repr=True)
"""The partial object of the guild this template is based on."""

is_dirty: typing.Optional[bool] = attr.ib(eq=False, hash=False, repr=False)
is_unsynced: bool = attr.ib(eq=False, hash=False, repr=False)
"""Whether this template is missing changes from it's source guild."""

def __str__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion hikari/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ async def fetch_self(self) -> OwnUser:
return await self.app.rest.fetch_my_user()

async def fetch_dm_channel(self) -> typing.NoReturn:
raise TypeError("Unable to send a DM to yourself")
raise TypeError("Unable to fetch your own DM channel")

async def send(self) -> typing.NoReturn: # type: ignore[override]
raise TypeError("Unable to send a DM to yourself")
11 changes: 9 additions & 2 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,13 @@ def test_deserialize_role(self, entity_factory_impl, mock_app, guild_role_payloa
assert isinstance(guild_role, guild_models.Role)

def test_deserialize_role_with_missing_or_unset_fields(self, entity_factory_impl, guild_role_payload):
guild_role_payload["tags"] = {}
guild_role = entity_factory_impl.deserialize_role(guild_role_payload, guild_id=snowflakes.Snowflake(76534453))
assert guild_role.bot_id is None
assert guild_role.integration_id is None
assert guild_role.is_premium_subscriber_role is False

def test_deserialize_role_with_no_tags(self, entity_factory_impl, guild_role_payload):
del guild_role_payload["tags"]
guild_role = entity_factory_impl.deserialize_role(guild_role_payload, guild_id=snowflakes.Snowflake(76534453))
assert guild_role.bot_id is None
Expand Down Expand Up @@ -3050,7 +3057,7 @@ def test_deserialize_template(
assert template.source_guild.system_channel_id == 8
assert template.source_guild.system_channel_flags == guild_models.GuildSystemChannelFlag.NONE

assert template.is_dirty is True
assert template.is_unsynced is True

def test_deserialize_template_with_null_fields(self, entity_factory_impl, template_payload, user_payload):
template = entity_factory_impl.deserialize_template(
Expand Down Expand Up @@ -3095,7 +3102,7 @@ def test_deserialize_template_with_null_fields(self, entity_factory_impl, templa
assert template.description is None
assert template.source_guild.afk_channel_id is None
assert template.source_guild.system_channel_id is None
assert template.is_dirty is None
assert template.is_unsynced is False

###############
# USER MODELS #
Expand Down
3 changes: 3 additions & 0 deletions tests/hikari/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def error(self):
def test_percentage_completion_property(self, error):
assert error.percentage_completion == 50

def test_str(self, error):
assert str(error) == "Error encountered when bulk deleting messages (10/20 messages deleted)"


class TestMissingIntentError:
@pytest.fixture()
Expand Down
42 changes: 42 additions & 0 deletions tests/hikari/test_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Nekokatt
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import pytest

from hikari import templates


class TestTemplate:
@pytest.fixture()
def obj(self):
return templates.Template(
code="abc123",
name="Test Template",
description="Template used for testing",
usage_count=101,
creator=object(),
created_at=object(),
updated_at=object(),
source_guild=object(),
is_unsynced=True,
)

def test_str(self, obj):
assert str(obj) == "https://discord.new/abc123"
8 changes: 8 additions & 0 deletions tests/hikari/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,11 @@ async def test_fetch_self(self, obj):
obj.app.rest.fetch_my_user = mock.AsyncMock(return_value=user)
assert await obj.fetch_self() is user
obj.app.rest.fetch_my_user.assert_awaited_once_with()

async def test_fetch_dm_channel(self, obj):
with pytest.raises(TypeError, match=r"Unable to fetch your own DM channel"):
await obj.fetch_dm_channel()

async def test_send(self, obj):
with pytest.raises(TypeError, match=r"Unable to send a DM to yourself"):
await obj.send()