Skip to content
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

Conversation

VladislavVoskoboinik
Copy link

Добавил софт делиты, релэйшоншипсы и написал тесты для нововведений

Добавил софт делиты, релэйшоншипсы и написал тесты для нововведений
@VladislavVoskoboinik VladislavVoskoboinik linked an issue Mar 11, 2023 that may be closed by this pull request
@github-actions
Copy link

✅ Result of Pytest Coverage

---------- coverage: platform linux, python 3.11.2-final-0 -----------

Name Stmts Miss Cover
print_service/init.py 4 0 100%
print_service/main.py 4 4 0%
print_service/models/init.py 67 3 96%
print_service/models/exceptions.py 3 1 67%
print_service/routes/init.py 1 0 100%
print_service/routes/admin.py 49 26 47%
print_service/routes/auth.py 4 0 100%
print_service/routes/base.py 21 0 100%
print_service/routes/file.py 107 24 78%
print_service/routes/qrprint.py 81 47 42%
print_service/routes/user.py 52 5 90%
print_service/schema.py 2 0 100%
print_service/settings.py 29 0 100%
print_service/utils/init.py 45 1 98%
TOTAL 469 111 76%
================== 26 passed, 1

@@ -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),
Copy link
Member

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])
Copy link
Member

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):
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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,
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут должно по дефолту стоять значение

Comment on lines +47 to +85
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужны тесты на логику работы именно с внешним миром
Кинули джсон
Обновили
Удалили
Восстановили
Это нужно тестировать

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Несколько тестов на логику работы класса оставь
Надо протестить тогда каждый метод оттуда
И еще добавь тесты на работу с внешним миром
Через requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Добавить софт делиты в принтер
2 participants