Skip to content

Commit

Permalink
Update test_user_api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
michplunkett committed Oct 9, 2024
1 parent ceda267 commit faf125f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions OpenOversight/tests/routes/test_user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def test_admin_can_disable_user(client, session):
# just need to make sure to not select the admin user
user = User.query.filter_by(is_administrator=False).first()

assert not user.is_disabled
assert not user.disabled_at
assert not user.disabled_by

form = EditUserForm(
is_disabled=True,
Expand All @@ -177,14 +178,16 @@ def test_admin_can_disable_user(client, session):
assert "updated!" in rv.data.decode(ENCODING_UTF_8)

user = session.get(User, user.id)
assert user.is_disabled
assert user.disabled_at
assert user.disabled_by


def test_admin_cannot_disable_self(client, session):
with current_app.test_request_context():
_, user = login_admin(client)

assert not user.is_disabled
assert not user.disabled_at
assert not user.disabled_by

form = EditUserForm(
is_disabled=True,
Expand All @@ -200,19 +203,20 @@ def test_admin_cannot_disable_self(client, session):
assert "You cannot edit your own account!" in rv.data.decode(ENCODING_UTF_8)

user = session.get(User, user.id)
assert not user.is_disabled
assert user.disabled_at
assert user.disabled_by


def test_admin_can_enable_user(client, session):
with current_app.test_request_context():
login_admin(client)
_, current_user = login_admin(client)

user = User.query.filter_by(email=GENERAL_USER_EMAIL).one()
user.is_disabled = True
session.commit()
user.disable_user(current_user.id)

user = session.get(User, user.id)
assert user.is_disabled
assert user.disabled_at
assert user.disabled_by

form = EditUserForm(
is_disabled=False,
Expand All @@ -228,7 +232,8 @@ def test_admin_can_enable_user(client, session):
assert "updated!" in rv.data.decode(ENCODING_UTF_8)

user = session.get(User, user.id)
assert not user.is_disabled
assert not user.disabled_at
assert not user.disabled_by


def test_admin_can_resend_user_confirmation_email(client, session):
Expand Down

0 comments on commit faf125f

Please sign in to comment.