-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/endpoints group #55
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
884eba7
merge feat/test_auth
dc1c710
resolve profile.py
ba91414
tests profile
fc7629d
fix gitignore, test.fixtures.user
0b414f2
Фикстура для создания юзеров с профилями гернерит 5 юзеров
fc9c8e2
тест фильтрации
a363ac8
тест пагинации
afae6f4
Тест получения своего профиля
4481485
тест запрета получения чужого профиля обычным юзером
6d1e2e3
тест получения фото своего профиля
2a4c024
вынес получение юзера в отдельную функцию
24d418e
refactoring
879aae1
тест апдейта профиля
9e084c3
Добавил тесты
ead1366
test udate photo
5afb149
isort
0e4842d
gitignore и пустой метод get для получения группы по id
da5e065
resolved
35d5af5
добавил тесты на создание группы суперюзером и запрет для юзера
7a023c4
эндпоинты, круд, тесты
204482f
Эндпоинты, круд, модели, тесты
587c5c8
refactoring, isort
b658d8b
flake8
3bd713c
isort tests
fc0098d
рефакторинг
1988797
resolve
5bb1292
refactoring
e8f0910
pep8
9774e9c
refactoring status codes
c9a23a7
добавлена пагинация на гет и тест пагинации
f0eed70
isort
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,9 +1,34 @@ | ||
from sqlalchemy import select | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from sqlalchemy.orm import selectinload | ||
|
||
from app.crud.base import CRUDBase | ||
from app.models import Group | ||
from app.models import Group, User | ||
|
||
|
||
class CRUDGroup(CRUDBase): | ||
pass | ||
async def get(self, group_id: int, session: AsyncSession): | ||
stmt = ( | ||
select(Group) | ||
.where(Group.id == group_id) | ||
.options( | ||
selectinload(Group.users) | ||
) | ||
) | ||
group = await session.execute(stmt) | ||
group = group.scalars().first() | ||
return group | ||
|
||
async def get_users_obj(self, user_id: int, session: AsyncSession): | ||
stmt = ( | ||
select(Group) | ||
# .where(Group.users == user_id) | ||
.options( | ||
selectinload(Group.users) | ||
).where(Group.users.any(User.id == user_id)) | ||
) | ||
db_obj = await session.execute(stmt) | ||
return db_obj.scalars().all() | ||
|
||
|
||
group_crud = CRUDGroup(Group) |
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
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
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
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,18 @@ | ||
import pytest_asyncio | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from app.models import Group | ||
|
||
|
||
@pytest_asyncio.fixture | ||
async def moc_groups( | ||
db_session: AsyncSession | ||
) -> None: | ||
moc_groups = [ | ||
Group( | ||
name=f'Group_{i}', | ||
description=f'Description for Group_{i}' | ||
) for i in range(1, 6) | ||
] | ||
db_session.add_all(moc_groups) | ||
await db_session.commit() |
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,90 @@ | ||
from typing import AsyncGenerator | ||
|
||
import pytest_asyncio | ||
from passlib.hash import bcrypt | ||
from sqlalchemy import select | ||
|
||
from app.models import Profile, User | ||
from tests.conftest import AsyncSessionLocalTest | ||
|
||
|
||
@pytest_asyncio.fixture | ||
async def moc_users( | ||
db_session: AsyncSessionLocalTest | ||
) -> AsyncGenerator: | ||
"""Фикстура заполнения базы юзерами с профилями.""" | ||
hashed_password = bcrypt.hash('qwerty') | ||
moc_users = [ | ||
User( | ||
email=f'user_{i}@example.com', | ||
hashed_password=hashed_password, | ||
role='user', | ||
username=f'user_{i}' | ||
) for i in range(1, 6) | ||
] | ||
db_session.add_all(moc_users) | ||
await db_session.commit() | ||
moc_users = await db_session.execute(select(User)) | ||
moc_users = moc_users.scalars().all() | ||
moc_profiles = [ | ||
Profile( | ||
first_name=f'name_{user.username}', | ||
last_name=f'surname_{user.username}', | ||
age=i + 20, | ||
user_id=user.id | ||
) for i, user in enumerate(moc_users) | ||
] | ||
db_session.add_all(moc_profiles) | ||
await db_session.commit() | ||
|
||
|
||
# @pytest_asyncio.fixture | ||
# async def user_1( | ||
# prepare_database: FastAPI, | ||
# db_session: AsyncSessionLocalTest | ||
# ) -> AsyncGenerator: | ||
# """Фикстура зарегистрированного клиента.""" | ||
# hashed_password = bcrypt.hash('qwerty') | ||
# user_1 = User( | ||
# email='[email protected]', | ||
# hashed_password=hashed_password, | ||
# role='user', | ||
# username='user_1' | ||
# ) | ||
# db_session.add(user_1) | ||
# await db_session.commit() | ||
# await db_session.refresh(user_1) | ||
# profile_1 = Profile( | ||
# first_name='user_1_fn', | ||
# last_name='user_1_ln', | ||
# age=25, | ||
# user_id=user_1.id | ||
# ) | ||
# db_session.add(profile_1) | ||
# await db_session.commit() | ||
|
||
|
||
# @pytest_asyncio.fixture | ||
# async def user_2( | ||
# prepare_database: FastAPI, | ||
# db_session: AsyncSessionLocalTest | ||
# ) -> AsyncGenerator: | ||
# """Фикстура зарегистрированного клиента.""" | ||
# hashed_password = bcrypt.hash('qwerty') | ||
# user_2 = User( | ||
# email='[email protected]', | ||
# hashed_password=hashed_password, | ||
# role='user', | ||
# username='user_2' | ||
# ) | ||
# db_session.add(user_2) | ||
# await db_session.commit() | ||
# await db_session.refresh(user_2) | ||
# profile_2 = Profile( | ||
# first_name='user_2_fn', | ||
# last_name='user_2_ln', | ||
# age=47, | ||
# user_id=user_2.id | ||
# ) | ||
# db_session.add(profile_2) | ||
# await db_session.commit() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пагинацию пока не будем добавлять в эти эндпоинты?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
и тест на пагинацию добавил