2023-03-10 11:05:22 -05:00
|
|
|
import pytest
|
2023-04-30 17:42:45 -04:00
|
|
|
from sachet.server.commands import create_user, delete_user
|
2023-03-10 11:05:22 -05:00
|
|
|
from sqlalchemy import inspect
|
|
|
|
|
|
|
|
from sachet.server.models import User
|
|
|
|
|
2023-03-30 20:20:09 -04:00
|
|
|
|
2023-03-10 13:57:18 -05:00
|
|
|
def test_user(client, cli):
|
2023-03-10 11:05:22 -05:00
|
|
|
"""Test the CLI's ability to create then delete a user."""
|
|
|
|
# create user
|
|
|
|
result = cli.invoke(create_user, ["--username", "jeff", "--password", "1234"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert User.query.filter_by(username="jeff").first() is not None
|
|
|
|
|
|
|
|
# create duplicate user
|
|
|
|
result = cli.invoke(create_user, ["--username", "jeff", "--password", "1234"])
|
|
|
|
assert isinstance(result.exception, KeyError)
|
|
|
|
|
|
|
|
# delete user
|
|
|
|
result = cli.invoke(delete_user, ["--yes", "jeff"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert User.query.filter_by(username="jeff").first() is None
|
|
|
|
|
|
|
|
# delete non-existent user
|
|
|
|
result = cli.invoke(delete_user, ["--yes", "jeff"])
|
|
|
|
assert isinstance(result.exception, KeyError)
|