add some tests for CDNBuilder

This commit is contained in:
grey-cat-1908 2022-05-31 18:57:03 +03:00
parent e9fc02cf91
commit 4b1aff2dba
3 changed files with 32 additions and 5 deletions

View file

@ -4,7 +4,7 @@
from .client import Client, Bot
from .models import *
from .exceptions import *
from .rest import RESTApp
from .rest import RESTApp, CDNBuilder
from .cache import CacheManager, ChannelsCachingPolicy
__package__ = "melisa"

View file

@ -681,7 +681,7 @@ class CDNBuilder:
def avatar_url(
self, user_id: str, _hash: str, *, size: int = 1024, image_format: str = None
):
return "/{}/avatars/{}/{}.{}?size={}".format(
return "{}/avatars/{}/{}.{}?size={}".format(
self.BASE_URL,
user_id,
_hash,
@ -692,7 +692,7 @@ class CDNBuilder:
def guild_icon_url(
self, guild_id: str, _hash: str, *, size: int = 1024, image_format: str = None
):
return "/icons/{}/{}.{}?size={}".format(
return "{}/icons/{}/{}.{}?size={}".format(
self.BASE_URL,
guild_id,
_hash,
@ -703,7 +703,7 @@ class CDNBuilder:
def default_avatar_url(
self, discriminator: str
):
return "/embed/avatars/{}.png".format(
return "{}/embed/avatars/{}.png".format(
self.BASE_URL,
discriminator
int(discriminator) % 5
)

27
tests/test_cdn.py Normal file
View file

@ -0,0 +1,27 @@
from melisa import CDNBuilder
cdn = CDNBuilder("png")
class TestCDN:
def test_avatar_url(self):
assert (
cdn.avatar_url("585766846268047370", "52320b1f9ddb1d7546da7b973bc23d6d")
== "https://cdn.discordapp.com/avatars/585766846268047370/52320b1f9ddb1d7546da7b973bc23d6d.png?size=1024"
)
def test_default_avatar_url(self):
assert (
cdn.default_avatar_url("0575")
== "https://cdn.discordapp.com/embed/avatars/0.png"
)
def test_guild_icon_url(self):
assert (
cdn.guild_icon_url(
"951867868188934216",
"5ef33b1f6c4b35f19b605c51c5a64469",
image_format="webp",
)
== "https://cdn.discordapp.com/icons/951867868188934216/5ef33b1f6c4b35f19b605c51c5a64469.webp?size=1024"
)