-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: users count in same school (#21)
* feat: users count in same school * fix: function name refactor * style: fix ci * refactor: clearer function name * test: read users from school info
- Loading branch information
Showing
5 changed files
with
118 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
from crenata.discord.commands.exit import exit | ||
from crenata.discord.commands.preferences import preferences | ||
from crenata.discord.commands.preferences.edit import preferences_edit as _ | ||
from crenata.discord.commands.profile import profile | ||
from crenata.discord.commands.register import register | ||
from crenata.discord.commands.school import school | ||
from crenata.discord.commands.school.meal import meal as _ | ||
from crenata.discord.commands.school.search import search as _ | ||
from crenata.discord.commands.school.set import school_set as _ | ||
from crenata.discord.commands.school.timetable import time_table as _ | ||
|
||
commands = [register, profile, exit, school, preferences] | ||
from crenata.discord.commands.exit import exit | ||
from crenata.discord.commands.preferences import preferences | ||
from crenata.discord.commands.preferences.edit import preferences_edit as _ | ||
from crenata.discord.commands.profile import profile | ||
from crenata.discord.commands.register import register | ||
from crenata.discord.commands.school import school | ||
from crenata.discord.commands.school.meal import meal as _ | ||
from crenata.discord.commands.school.search import search as _ | ||
from crenata.discord.commands.school.set import school_set as _ | ||
from crenata.discord.commands.school.timetable import time_table as _ | ||
from crenata.discord.commands.school.users import users as _ | ||
|
||
commands = [register, profile, exit, school, preferences] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from crenata.discord import CrenataInteraction | ||
from crenata.discord.commands.school import school | ||
from crenata.discord.embed import school_users_embed_maker | ||
from crenata.exception import NeedSchoolRegister | ||
|
||
|
||
@school.command(name="유저", description="나와 학교가 같은 유저 수를 가져옵니다.") | ||
async def users(interaction: CrenataInteraction) -> None: | ||
user = await interaction.client.ctx.query.user.read(interaction.user.id) | ||
|
||
if not user or not user.school_info: | ||
raise NeedSchoolRegister | ||
|
||
users = await interaction.client.ctx.query.user.read_all_user_from_school_info( | ||
user.school_info | ||
) | ||
|
||
embed = school_users_embed_maker( | ||
user.school_info.school_name, len(users), user.preferences.private | ||
) | ||
|
||
await interaction.response.send_message( | ||
embed=embed, ephemeral=user.preferences.ephemeral | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
import pytest | ||
|
||
from crenata.database.query import Query | ||
from crenata.database.schema import UserSchema | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user_read(query: Query): | ||
user = await query.user.read(1) | ||
assert user | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user_update(query: Query, new_user: UserSchema): | ||
new_user.preferences.private = False | ||
await query.user.update(new_user) | ||
user = await query.user.read(1) | ||
assert user | ||
assert user.preferences.private is False | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user_delete(query: Query, new_user: UserSchema): | ||
await query.user.delete(new_user) | ||
user = await query.user.read(1) | ||
assert user is None | ||
import pytest | ||
|
||
from crenata.database.query import Query | ||
from crenata.database.schema import SchoolInfoSchema, UserSchema | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user_read(query: Query): | ||
user = await query.user.read(1) | ||
assert user | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user_update(query: Query, new_user: UserSchema): | ||
new_user.preferences.private = False | ||
await query.user.update(new_user) | ||
user = await query.user.read(1) | ||
assert user | ||
assert user.preferences.private is False | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user_delete(query: Query, new_user: UserSchema): | ||
await query.user.delete(new_user) | ||
user = await query.user.read(1) | ||
assert user is None | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user_read_from_school_info( | ||
query: Query, | ||
new_school_info: SchoolInfoSchema, | ||
): | ||
user = await query.user.read_all_user_from_school_info(new_school_info) | ||
assert user |