Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
gitfresnel committed Nov 5, 2024
1 parent 64679c1 commit 6becd9e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('file', 'source', existing_type=sa.VARCHAR(), nullable=False)
op.add_column('union_member', sa.Column('is_deleted', sa.Boolean(), nullable=True))
op.execute(f'UPDATE "union_member" SET is_deleted = False')
op.alter_column('union_member', 'is_deleted', nullable=False)
# ### end Alembic commands ###


Expand Down
57 changes: 51 additions & 6 deletions tests/test_routes/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from print_service.models import UnionMember
from print_service.settings import get_settings
from sqlalchemy import and_, func


url: str = '/is_union_member'
Expand Down Expand Up @@ -46,14 +47,14 @@ def test_post_success(client, dbsession):
'union_number': '1966',
'student_number': '1967',
}
],
]
}
res = client.post(url, data=json.dumps(body))
assert res.status_code == status.HTTP_200_OK
UnionMember.query(session=dbsession).filter(
UnionMember.surname == body['users'][0]['username'],
UnionMember.union_number == body['users'][0]['union_number'],
UnionMember.student_number == body['users'][0]['student_number'],
UnionMember.query(session=dbsession).filter(and_(
UnionMember.surname == func.upper(body['users'][0]['username']),
UnionMember.union_number == func.upper(body['users'][0]['union_number']),
UnionMember.student_number == func.upper(body['users'][0]['student_number']))
).delete()
dbsession.commit()

Expand All @@ -66,12 +67,56 @@ def test_post_is_deleted(client, union_member_user, add_is_deleted_flag):
'union_number': '6666667',
'student_number': '13033224',
}
],
]
}
res = client.post(url, data=json.dumps(body))
assert res.status_code == status.HTTP_404_NOT_FOUND


def test_restore_is_deleted(client, dbsession):
user = UnionMember(id=5,
surname='test_user',
union_number='123',
student_number='56',
is_deleted=False)
dbsession.add(user)
dbsession.commit()

body = {
'users': [
{
'username': 'test_user',
'union_number': '123',
'student_number': '56',
'is_deleted': True
}
]
}
_ = client.post(url, data=json.dumps(body))
res = UnionMember.query(session=dbsession, with_deleted=True).filter(UnionMember.id == 5).one_or_none()
assert res.is_deleted is False
user.is_deleted = True
dbsession.commit()
body = {
'users': [
{
'username': 'test_user',
'union_number': '123',
'student_number': '56',
'is_deleted': False
}
]
}
res = client.post(url, data=json.dumps(body))
assert res.status_code == status.HTTP_404_NOT_FOUND
UnionMember.query(session=dbsession, with_deleted=True).filter(and_(
UnionMember.surname == func.upper(body['users'][0]['username']),
UnionMember.union_number == func.upper(body['users'][0]['union_number']),
UnionMember.student_number == func.upper(body['users'][0]['student_number'])
)).delete()
dbsession.commit()


@pytest.mark.parametrize(
'users',
[
Expand Down

0 comments on commit 6becd9e

Please sign in to comment.