From df23763b99d033bd6d8a57514372c25b6fa440d0 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 20 Oct 2023 17:44:38 -0500 Subject: [PATCH] Fix tests --- tests/cli/test_group.py | 4 ++-- tests/cli/test_login.py | 20 ++++++++++---------- tests/cli/test_logout.py | 6 +++--- tests/{test_hooks.py => test_plugin.py} | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) rename tests/{test_hooks.py => test_plugin.py} (82%) diff --git a/tests/cli/test_group.py b/tests/cli/test_group.py index 93e9c43..eee170a 100644 --- a/tests/cli/test_group.py +++ b/tests/cli/test_group.py @@ -1,6 +1,6 @@ import pytest -from conda_auth.cli import auth_wrapper +from conda_auth.cli import auth def test_auth_wrapper(): @@ -11,4 +11,4 @@ def test_auth_wrapper(): exception. """ with pytest.raises(SystemExit): - auth_wrapper([]) + auth([]) diff --git a/tests/cli/test_login.py b/tests/cli/test_login.py index bc608f5..8186bbb 100644 --- a/tests/cli/test_login.py +++ b/tests/cli/test_login.py @@ -1,4 +1,4 @@ -from conda_auth.cli import group, SUCCESSFUL_LOGIN_MESSAGE +from conda_auth.cli import auth, SUCCESSFUL_LOGIN_MESSAGE from conda_auth.condarc import CondaRCError from conda_auth.exceptions import CondaAuthError @@ -16,7 +16,7 @@ def test_login_basic_auth_no_options(runner, keyring, condarc): # run command result = runner.invoke( - group, ["login", channel_name, "--basic"], input=f"{username}\n{secret}" + auth, ["login", channel_name, "--basic"], input=f"{username}\n{secret}" ) assert result.exit_code == 0 @@ -34,7 +34,7 @@ def test_login_with_options_basic_auth(runner, keyring, condarc): # run command result = runner.invoke( - group, + auth, ["login", channel_name, "--basic", "--username", "test", "--password", "test"], ) @@ -52,12 +52,12 @@ def test_login_with_invalid_auth_type(runner, keyring, condarc): keyring(None) # run command - result = runner.invoke(group, ["login", channel_name]) + result = runner.invoke(auth, ["login", channel_name]) exc_type, exception, _ = result.exc_info - assert result.exit_code == 1 - assert exc_type == CondaAuthError - assert "Please specify an authentication type" in exception.message + assert result.exit_code == 2 + assert exc_type == SystemExit + assert "Error: Missing option 'basic' / 'token'." in result.stdout def test_login_succeeds_error_returned_when_updating_condarc(runner, keyring, condarc): @@ -73,7 +73,7 @@ def test_login_succeeds_error_returned_when_updating_condarc(runner, keyring, co # run command result = runner.invoke( - group, ["login", channel_name, "--basic"], input="user\npassword" + auth, ["login", channel_name, "--basic"], input="user\npassword" ) exc_type, exception, _ = result.exc_info @@ -92,7 +92,7 @@ def test_login_token(mocker, runner, keyring, condarc): mock_context.channel_settings = [] keyring(None) - result = runner.invoke(group, ["login", channel_name, "--token", "token"]) + result = runner.invoke(auth, ["login", channel_name, "--token", "token"]) assert result.exit_code == 0 @@ -106,7 +106,7 @@ def test_login_token_no_options(runner, keyring, condarc): # setup mocks keyring(None) - result = runner.invoke(group, ["login", channel_name, "--token"], input="token\n") + result = runner.invoke(auth, ["login", channel_name, "--token"], input="token\n") assert result.exit_code == 0 assert SUCCESSFUL_LOGIN_MESSAGE in result.output diff --git a/tests/cli/test_logout.py b/tests/cli/test_logout.py index 0ff252e..ecb5137 100644 --- a/tests/cli/test_logout.py +++ b/tests/cli/test_logout.py @@ -1,4 +1,4 @@ -from conda_auth.cli import group, SUCCESSFUL_LOGOUT_MESSAGE +from conda_auth.cli import auth, SUCCESSFUL_LOGOUT_MESSAGE from conda_auth.constants import PLUGIN_NAME from conda_auth.handlers.basic_auth import HTTP_BASIC_AUTH_NAME from conda_auth.exceptions import CondaAuthError @@ -20,7 +20,7 @@ def test_logout_of_active_session(mocker, runner, keyring): ] # run command - result = runner.invoke(group, ["logout", channel_name]) + result = runner.invoke(auth, ["logout", channel_name]) assert SUCCESSFUL_LOGOUT_MESSAGE in result.output assert result.exit_code == 0 @@ -43,7 +43,7 @@ def test_logout_of_non_existing_session(mocker, runner, keyring): mock_context.channel_settings = [] # run command - result = runner.invoke(group, ["logout", channel_name]) + result = runner.invoke(auth, ["logout", channel_name]) exc_type, exception, _ = result.exc_info assert exc_type == CondaAuthError diff --git a/tests/test_hooks.py b/tests/test_plugin.py similarity index 82% rename from tests/test_hooks.py rename to tests/test_plugin.py index 015bd1c..d14d4db 100644 --- a/tests/test_hooks.py +++ b/tests/test_plugin.py @@ -1,6 +1,6 @@ from conda.cli.conda_argparse import BUILTIN_COMMANDS -from conda_auth import hooks +from conda_auth import plugin from conda_auth.constants import PLUGIN_NAME from conda_auth.handlers import ( HTTP_BASIC_AUTH_NAME, @@ -14,7 +14,7 @@ def test_conda_subcommands_hook(): """ Test to make sure that this hook yields the correct objects. """ - objs = list(hooks.conda_subcommands()) + objs = list(plugin.conda_subcommands()) assert objs[0].name == "auth" assert objs[0].summary == "Authentication commands for conda" @@ -24,9 +24,9 @@ def test_conda_pre_commands_hook(): """ Test to make sure that this hook yields the correct objects. """ - objs = list(hooks.conda_pre_commands()) + objs = list(plugin.conda_pre_commands()) - run_for = BUILTIN_COMMANDS.union(hooks.ENV_COMMANDS) + run_for = BUILTIN_COMMANDS.union(plugin.ENV_COMMANDS) assert objs[0].name == f"{PLUGIN_NAME}-{HTTP_BASIC_AUTH_NAME}" assert objs[0].run_for == run_for @@ -39,7 +39,7 @@ def test_conda_auth_handlers_hook(): """ Test to make sure that this hook yields the correct objects. """ - objs = list(hooks.conda_auth_handlers()) + objs = list(plugin.conda_auth_handlers()) assert objs[0].name == HTTP_BASIC_AUTH_NAME assert objs[0].handler == BasicAuthHandler