Skip to content

Commit

Permalink
Merge pull request #229 from yepcord/some-asgi-and-test-changes
Browse files Browse the repository at this point in the history
Some asgi and tests changes
  • Loading branch information
RuslanUC committed May 8, 2024
2 parents 8c71911 + 42376be commit 9805f9f
Show file tree
Hide file tree
Showing 49 changed files with 870 additions and 666 deletions.
1,278 changes: 709 additions & 569 deletions poetry.lock

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,42 @@ yepcord = "yepcord.cli:main"

[tool.poetry.dependencies]
python = "^3.9"
quart = "0.19.4"
quart = "0.19.5"
aiofiles = "23.2.1"
websockets = "12.0"
uvicorn = "0.28.0"
aiohttp = "3.9.3"
uvicorn = "0.29.0"
aiohttp = "3.9.5"
python-magic = "0.4.27"
pillow = "10.2.0"
pillow = "10.3.0"
protobuf = "4.25.3"
python-dateutil = "2.9.0.post0"
cryptography = "42.0.5"
emoji = "2.10.1"
cryptography = "42.0.7"
emoji = "2.11.1"
six = "1.16.0"
bcrypt = "4.1.2"
bcrypt = "4.1.3"
quart-schema = "0.19.1"
pydantic = "2.6.3"
werkzeug = "3.0.1"
pydantic = "2.7.1"
werkzeug = "3.0.3"
aioftp = "0.22.3"
orjson = "3.9.15"
mailers = {version = "3.0.2", extras = ["smtp"]}
orjson = "3.10.3"
mailers = {version = "3.0.5", extras = ["smtp"]}
redis = ">=4.6.0"
click = "8.1.7"
maxminddb = "2.5.2"
maxminddb = "2.6.1"
wget = "3.2"
tortoise-orm = {extras = ["aiosqlite", "asyncmy"], version = "^0.20.0"}
tortoise-orm = {extras = ["aiosqlite", "asyncmy", "accel"], version = "^0.20.0"}
uvloop = "0.19.0"
async-timeout = "^4.0.3"
aerich = "^0.7.2"
yc-protobuf3-to-dict = "^0.3.0"
s3lite = "^0.1.4"
fast-depends = ">=2.4.2"
faststream = {extras = ["kafka", "nats", "rabbit", "redis"], version = "^0.4.7"}
faststream = {extras = ["kafka", "nats", "rabbit", "redis"], version = "^0.5.4"}

[tool.poetry.group.dev.dependencies]
pytest-cov = "4.1.0"
pytest-asyncio = "0.23.5"
pytest = "^8.2.0"
pytest-cov = "^4.1.0"
pytest-asyncio = "^0.23.6"
pyftpdlib = "1.5.8"
fake-s3 = "1.0.2"
types-protobuf = "^4.24.0.4"
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_application_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from yepcord.yepcord.utils import b64encode
from .utils import TestClientType, create_users, create_application, create_guild, add_bot_to_guild, bot_token, \
create_dm_channel, create_dm_group, generate_slash_command_payload
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from yepcord.yepcord.snowflake import Snowflake
from .utils import TestClientType, create_users, create_application
from ..yep_image import YEP_IMAGE
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from yepcord.yepcord.snowflake import Snowflake
from yepcord.yepcord.utils import b64decode, b64encode
from .utils import TestClientType, create_user, get_userdata, create_users
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from yepcord.yepcord.config import Config
from yepcord.yepcord.snowflake import Snowflake
from .utils import TestClientType
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
spotify_oauth_user_get
from yepcord.rest_api.main import app
from yepcord.yepcord.config import Config
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_dm_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from tests.api.utils import TestClientType, create_users, create_guild, create_dm_channel, create_dm_group, \
create_message
from tests.yep_image import YEP_IMAGE
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_emoji_and_stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from yepcord.yepcord.enums import StickerType
from yepcord.yepcord.snowflake import Snowflake
from tests.api.utils import TestClientType, create_users, create_guild, create_emoji, create_sticker
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
add_user_to_guild, create_ban, create_message, create_role, create_application, add_bot_to_guild
from tests.yep_image import YEP_IMAGE
from yepcord.yepcord.utils import b64encode
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_guild_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from yepcord.rest_api.main import app
from yepcord.yepcord.enums import ChannelType
from yepcord.yepcord.snowflake import Snowflake
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from yepcord.rest_api.main import app
from yepcord.yepcord.enums import ChannelType
from .utils import TestClientType, create_users, create_guild, create_invite, create_dm_group, create_ban
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from tests.api.utils import TestClientType, create_users, create_guild, create_guild_channel, create_message, rel_block, \
create_dm_channel, create_sticker, create_emoji, create_dm_group, create_invite, create_webhook
from tests.yep_image import YEP_IMAGE
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_mfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from yepcord.yepcord.config import Config
from yepcord.yepcord.utils import b64decode
from .utils import TestClientType, create_users, enable_mfa
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from yepcord.rest_api.main import app
from yepcord.yepcord.snowflake import Snowflake
from .utils import TestClientType, create_users, create_application, create_guild, create_ban, add_user_to_guild
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from yepcord.rest_api.main import app
from yepcord.yepcord.config import Config
from tests.api.utils import TestClientType, create_users
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from yepcord.rest_api.main import app
from yepcord.yepcord.snowflake import Snowflake
from .utils import TestClientType, create_users, rel_request, rel_count, rel_delete, rel_accept, rel_block
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_remote_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from yepcord.rest_api.main import app
from yepcord.yepcord.utils import b64encode
from .utils import TestClientType, create_users, RemoteAuthClient
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from tests.api.utils import TestClientType, create_users, create_guild, create_role, add_user_to_guild, \
create_application, add_bot_to_guild
from tests.yep_image import YEP_IMAGE
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_scheduled_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from yepcord.yepcord.utils import getImage
from tests.api.utils import TestClientType, create_users, create_guild, create_event
from tests.yep_image import YEP_IMAGE
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_slash_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from yepcord.yepcord.snowflake import Snowflake
from .utils import TestClientType, create_users, create_application, create_guild, add_bot_to_guild, bot_token, \
GatewayClient, gateway_cm, generate_slash_command_payload, create_guild_channel
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from yepcord.yepcord.enums import MessageFlags
from tests.api.utils import TestClientType, create_users, create_guild, create_guild_channel, create_message, \
create_thread, create_dm_group
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_user_message_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from yepcord.yepcord.snowflake import Snowflake
from .utils import TestClientType, create_users, create_application, create_guild, add_bot_to_guild, bot_token, \
GatewayClient, gateway_cm, create_message
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from yepcord.rest_api.main import app
from .utils import TestClientType, create_users, create_guild
from ..yep_image import YEP_IMAGE
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from yepcord.rest_api.main import app
from yepcord.yepcord.proto import PreloadedUserSettings, TextAndImagesSettings, FrecencyUserSettings, FavoriteStickers
from .utils import create_users, TestClientType, create_guild
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from tests.api.utils import TestClientType, create_users, create_guild, create_webhook, \
create_guild_channel, create_sticker, create_dm_group
from tests.yep_image import YEP_IMAGE
from ..utils import register_app_error_handler

register_app_error_handler(app)


@pytest_asyncio.fixture(autouse=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/cdn/test_storage_and_cdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
"""

from asyncio import get_event_loop
from cProfile import Profile
from io import BytesIO
from time import time

import pytest as pt
import pytest_asyncio
Expand All @@ -36,8 +34,10 @@
from .ftp_server import ftp_server
from .local_server import local_server
from .s3_server import s3_server
from ..utils import register_app_error_handler
from ..yep_image import YEP_IMAGE

register_app_error_handler(app)
TestClientType = app.test_client_class
core = Core(b64decode(Config.KEY))

Expand Down
8 changes: 8 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ def generateMfaVerificationKey(nonce: str, mfa_key: str, key: bytes):
token = JWT.encode({"code": payload["code"]}, key)
signature = token.split(".")[2]
return signature.replace("-", "").replace("_", "")[:8].upper()


def register_app_error_handler(app):
from werkzeug.exceptions import InternalServerError

@app.errorhandler(500)
async def handle_500_for_pytest(error: InternalServerError):
raise error.original_exception
15 changes: 1 addition & 14 deletions yepcord/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,7 @@
remote_auth.ws_gateway.__name__ = "ws_ra_gateway"
app.websocket("/remote-auth", strict_slashes=False)(remote_auth.ws_gateway)

app.get("/media/avatars/<int:user_id>/<string:file_hash>.<string:format_>")(cdn.get_avatar)
app.get("/media/banners/<int:user_id>/<string:file_hash>.<string:format_>")(cdn.get_banner)
app.get("/media/splashes/<int:guild_id>/<string:file_hash>.<string:format_>")(cdn.get_splash)
app.get("/media/channel-icons/<int:channel_id>/<string:file_hash>.<string:format_>")(cdn.get_channel_icon)
app.get("/media/icons/<int:guild_id>/<string:file_hash>.<string:format_>")(cdn.get_guild_icon)
app.get("/media/role-icons/<int:role_id>/<string:file_hash>.<string:format_>")(cdn.get_role_icon)
app.get("/media/emojis/<int:emoji_id>.<string:format_>")(cdn.get_emoji)
app.get("/media/guilds/<int:guild_id>/users/<int:member_id>/avatars/<string:file_hash>.<string:format_>")(
cdn.get_guild_avatar
)
app.get("/media/stickers/<int:sticker_id>.<string:format_>")(cdn.get_sticker)
app.get("/media/guild-events/<int:event_id>/<string:file_hash>")(cdn.get_guild_event_image)
app.get("/media/attachments/<int:channel_id>/<int:attachment_id>/<string:name>")(cdn.get_attachment)
app.get("/media/app-icons/<int:app_id>/<string:file_hash>.<string:format_>")(cdn.get_app_icon)
app.register_blueprint(cdn.cdn, url_prefix="/media")

register_tortoise(
app,
Expand Down
Loading

0 comments on commit 9805f9f

Please sign in to comment.