def test_GroupDMChannel_format_icon(): mock_channel = mock.Mock(channels.GroupDMChannel, id=123, icon_hash="456abc") assert channels.GroupDMChannel.format_icon( mock_channel, ext="jpeg", size=16) == files.URL( "https://cdn.discordapp.com/channel-icons/123/456abc.jpeg?size=16")
def compile_to_file( self, base_url: str, *, file_format: str, size: typing.Optional[int] = None, **kwargs: typing.Any, ) -> files.URL: """Perform the same as `compile`, but return the URL as a `files.URL`.""" return files.URL(self.compile(base_url, file_format=file_format, size=size, **kwargs))
def test_make_small_image_url_when_dynamic_url(self, asset_hash: str, expected: str): asset = presences.ActivityAssets( application_id=None, large_image=None, large_text=None, small_image=asset_hash, small_text=None, ) assert asset.make_small_image_url() == files.URL(expected)
def test_compile_to_file_passes_compile_result_to_URL_and_returns_constructed_url(self): resultant_url_str = "http://blep.com/hello/world/weeb/oyy%20lumo" resultant_url = files.URL("http://blep.com/hello/world/weeb/oyy%20lumo") with mock.patch.object(files, "URL", autospec=files.URL, return_value=resultant_url) as URL: route = hikari_test_helpers.mock_class_namespace(routes.CDNRoute, slots_=False)( "/hello/world/{nya}/{boop}", {"png", "jpg"}, sizable=True ) route.compile = mock.Mock(spec_set=route.compile, return_value=resultant_url_str) result = route.compile_to_file("https://blep.com", file_format="png", size=64, boop="oyy lumo", nya="weeb") URL.assert_called_once_with(resultant_url_str) assert result is resultant_url
def _make_asset_url(self, asset: typing.Optional[str], ext: str, size: int) -> typing.Optional[files.URL]: if asset is None: return None try: resource, identifier = asset.split(":", 1) return files.URL(url=_DYNAMIC_URLS[resource].format(identifier)) except KeyError: raise RuntimeError("Unknown asset type") from None except ValueError: assert self._application_id is not None return routes.CDN_APPLICATION_ASSET.compile_to_file( urls.CDN_URL, application_id=self._application_id, hash=asset, size=size, file_format=ext, )
def test_make_icon_url_without_optional_params(self, model): assert model.make_icon_url() == files.URL( "https://cdn.discordapp.com/channel-icons/136134/1a2b3c.png?size=4096" )
def test_make_icon_url(self, model): assert model.make_icon_url(ext="jpeg", size=16) == files.URL( "https://cdn.discordapp.com/channel-icons/136134/1a2b3c.jpeg?size=16" )
def test_GroupDMChannel_format_icon_without_optionals(): mock_channel = mock.Mock(channels.GroupDMChannel, id=123, icon_hash="456abc") assert channels.GroupDMChannel.format_icon(mock_channel) == files.URL( "https://cdn.discordapp.com/channel-icons/123/456abc.png?size=4096")