-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
253 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from unittest import mock | ||
|
||
from toot import User, cli | ||
|
||
|
||
# Saving config is mocked so we don't mess up our local config | ||
# TODO: could this be implemented using an auto-use fixture so we have it always | ||
# mocked? | ||
@mock.patch("toot.config.load_app") | ||
@mock.patch("toot.config.save_app") | ||
@mock.patch("toot.config.save_user") | ||
def test_login_cli( | ||
save_user: mock.MagicMock, | ||
save_app: mock.MagicMock, | ||
load_app: mock.MagicMock, | ||
user: User, | ||
run | ||
): | ||
load_app.return_value = None | ||
|
||
result = run( | ||
cli.login_cli, | ||
"--instance", "http://localhost:3000", | ||
"--email", f"{user.username}@example.com", | ||
"--password", "password", | ||
) | ||
assert result.exit_code == 0 | ||
assert "✓ Successfully logged in." in result.stdout | ||
|
||
save_app.assert_called_once() | ||
(app,) = save_app.call_args.args | ||
assert app.instance == "localhost:3000" | ||
assert app.base_url == "http://localhost:3000" | ||
assert app.client_id | ||
assert app.client_secret | ||
|
||
save_user.assert_called_once() | ||
(new_user,) = save_user.call_args.args | ||
assert new_user.instance == "localhost:3000" | ||
assert new_user.username == user.username | ||
# access token will be different since this is a new login | ||
assert new_user.access_token and new_user.access_token != user.access_token | ||
assert save_user.call_args.kwargs == {"activate": True} | ||
|
||
|
||
@mock.patch("toot.config.load_app") | ||
@mock.patch("toot.config.save_app") | ||
@mock.patch("toot.config.save_user") | ||
def test_login_cli_wrong_password( | ||
save_user: mock.MagicMock, | ||
save_app: mock.MagicMock, | ||
load_app: mock.MagicMock, | ||
user: User, | ||
run | ||
): | ||
load_app.return_value = None | ||
|
||
result = run( | ||
cli.login_cli, | ||
"--instance", "http://localhost:3000", | ||
"--email", f"{user.username}@example.com", | ||
"--password", "wrong password", | ||
) | ||
assert result.exit_code == 1 | ||
assert result.stderr.strip() == "Error: Login failed" | ||
|
||
save_app.assert_called_once() | ||
(app,) = save_app.call_args.args | ||
assert app.instance == "localhost:3000" | ||
assert app.base_url == "http://localhost:3000" | ||
assert app.client_id | ||
assert app.client_secret | ||
|
||
save_user.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.