-
Notifications
You must be signed in to change notification settings - Fork 3
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
Софт делиты #33
The head ref may contain hidden characters: "29-\u0434\u043E\u0431\u0430\u0432\u0438\u0442\u044C-\u0441\u043E\u0444\u0442-\u0434\u0435\u043B\u0438\u0442\u044B-\u0432-\u043F\u0440\u0438\u043D\u0442\u0435\u0440"
Софт делиты #33
Conversation
Добавил софт делиты, релэйшоншипсы и написал тесты для нововведений
✅ Result of Pytest Coverage---------- coverage: platform linux, python 3.11.2-final-0 -----------
|
@@ -22,6 +22,7 @@ def upgrade(): | |||
sa.Column('id', sa.Integer(), nullable=False), | |||
sa.Column('surname', sa.String(), nullable=False), | |||
sa.Column('number', sa.String(), nullable=False), | |||
sa.Column('is_deleted', sa.Boolean(), nullable=True, default=False), |
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.
Этот файл миграций уже применен
Надо новый, старый не трогаем
@@ -40,4 +32,63 @@ class File(Model): | |||
DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow | |||
) | |||
|
|||
owner: Mapped[UnionMember] = relationship('UnionMember', back_populates='files') | |||
owner: Mapped[UnionMember] = relationship('UnionMember', back_populates='files', foreign_keys=[owner_id]) |
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.
А если owner is deleted
Зачем он мне тут?
Надо юзать primaryjoin
owner: Mapped[UnionMember] = relationship('UnionMember', back_populates='files', foreign_keys=[owner_id]) | ||
|
||
|
||
class UnionMember(Model): |
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.
Почему софт делиты только в юзере? Погнали в файлы тоже
@@ -24,6 +24,7 @@ class UserCreate(BaseModel): | |||
username: constr(strip_whitespace=True, to_upper=True, min_length=1) | |||
union_number: Optional[constr(strip_whitespace=True, to_upper=True, min_length=1)] | |||
student_number: Optional[constr(strip_whitespace=True, to_upper=True, min_length=1)] | |||
is_deleted: bool = False |
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.
Не надо это отдавать в модельках
Если удален то для внешнего мира вообще ничего не возвращается
@@ -49,7 +50,7 @@ async def check_union_member( | |||
"""Проверяет наличие пользователя в списке.""" | |||
user = db.session.query(UnionMember) | |||
if not settings.ALLOW_STUDENT_NUMBER: | |||
user = user.filter(UnionMember.union_number != None) | |||
user = user.filter(UnionMember.union_number is not None) |
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.
А зачем это изменять? Кажется что алхимия лучше работает с !=
@@ -93,11 +95,13 @@ def update_list(input: UpdateUserList, user: dict[str, str] = Depends(auth)): | |||
or_( | |||
and_( | |||
UnionMember.union_number == user.union_number, | |||
UnionMember.union_number != None, | |||
UnionMember.union_number is not None, | |||
UnionMember.is_deleted is not True, |
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.
Почему не используешь фильтр написанный в классе?
@@ -108,13 +112,14 @@ def update_list(input: UpdateUserList, user: dict[str, str] = Depends(auth)): | |||
db_user.surname = user.username | |||
db_user.union_number = user.union_number | |||
db_user.student_number = user.student_number | |||
db_user.is_deleted = user.is_deleted |
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.
Ты запрашиваешь с удаленными
Если он там есть то возвращаешь
Это поле не передается в моделях
surname=user.username, | ||
union_number=user.union_number, | ||
student_number=user.student_number, | ||
is_deleted=user.is_deleted |
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.
Тут должно по дефолту стоять значение
def test_union_member_update(dbsession): | ||
union_member = dict( | ||
id=644, | ||
surname='test', | ||
union_number='6666667', | ||
student_number='13033224', | ||
) | ||
union_member_updated = dict( | ||
id=644, | ||
surname='not_test', | ||
union_number='1233454', | ||
student_number='00000004' | ||
) | ||
UnionMember.create(session=dbsession, **union_member) | ||
dbsession.flush() | ||
tmp = UnionMember.update(obj_id=union_member['id'], session=dbsession, **union_member_updated) | ||
dbsession.flush() | ||
assert tmp is not None | ||
db_union_member_updated = dbsession.query(UnionMember).filter(UnionMember.id == union_member['id']).one_or_none() | ||
assert db_union_member_updated.surname != union_member['surname'] | ||
assert db_union_member_updated.union_number != union_member['union_number'] | ||
assert db_union_member_updated.student_number != union_member['student_number'] | ||
dbsession.query(UnionMember).filter(UnionMember.id == union_member['id']).delete() | ||
dbsession.commit() | ||
|
||
|
||
def test_union_member_delete(dbsession): | ||
union_member = dict( | ||
id=104, | ||
surname='test_4', | ||
union_number='6666660', | ||
student_number='45033224', | ||
) | ||
UnionMember.create(session=dbsession, **union_member) | ||
dbsession.flush() | ||
UnionMember.delete(obj_id=union_member['id'], session=dbsession) | ||
dbsession.commit() | ||
tmp = dbsession.query(UnionMember).filter(UnionMember.id == union_member['id']).one_or_none() | ||
assert tmp.is_deleted is True |
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.
Несколько тестов на логику работы класса оставь
Надо протестить тогда каждый метод оттуда
И еще добавь тесты на работу с внешним миром
Через requests
Добавил софт делиты, релэйшоншипсы и написал тесты для нововведений