From f739eb35b195e5ea3aacbb6a379e79b10c42825a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=A9na=C3=ABl=20Muller?= Date: Wed, 26 Sep 2018 12:23:12 +0200 Subject: [PATCH] rework exception for create user from tracimcli + support notificationdisabled case by test --- backend/tracim_backend/command/user.py | 12 ++++++------ .../tests/commands/test_commands.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/backend/tracim_backend/command/user.py b/backend/tracim_backend/command/user.py index 801c814f..89ddd5f7 100644 --- a/backend/tracim_backend/command/user.py +++ b/backend/tracim_backend/command/user.py @@ -191,12 +191,12 @@ def _proceed_user(self, parsed_args: argparse.Namespace) -> User: password=parsed_args.password, do_notify=parsed_args.send_email, ) - except UserAlreadyExistError: - raise UserAlreadyExistError("Error: User already exist (use `user update` command instead)") # nopep8 - except NotificationSendingFailed: - raise NotificationSendingFailed("Error: Cannot send email notification due to error, user not created.") # nopep8 - except NotificationDisabled: - raise NotificationSendingFailed("Error: Email notification disabled but notification required, user not created.") # nopep8 + except UserAlreadyExistError as exc: + raise UserAlreadyExistError("Error: User already exist (use `user update` command instead)") from exc # nopep8 + except NotificationSendingFailed as exc: + raise NotificationSendingFailed("Error: Cannot send email notification due to error, user not created.") from exc # nopep8 + except NotificationDisabled as exc: + raise NotificationDisabled("Error: Email notification disabled but notification required, user not created.") from exc # nopep8 else: if parsed_args.password: self._update_password_for_login( diff --git a/backend/tracim_backend/tests/commands/test_commands.py b/backend/tracim_backend/tests/commands/test_commands.py index 54ff4f8d..d38efff8 100644 --- a/backend/tracim_backend/tests/commands/test_commands.py +++ b/backend/tracim_backend/tests/commands/test_commands.py @@ -7,6 +7,7 @@ import tracim_backend from tracim_backend.command import TracimCLI from tracim_backend.exceptions import BadCommandError +from tracim_backend.exceptions import NotificationDisabled from tracim_backend.exceptions import DatabaseInitializationFailed from tracim_backend.exceptions import ForceArgumentNeeded from tracim_backend.exceptions import GroupDoesNotExist @@ -121,6 +122,22 @@ def test_func__user_create_command__err_user_already_exist(self) -> None: '--debug', ]) + def test_func__user_create_command__err__with_email_notification_disabled(self) -> None: # nopep8 + """ + Test User creation with email with notification disable + """ + app = TracimCLI() + with pytest.raises(NotificationDisabled): + app.run([ + '--debug', + 'user', 'create', + '-c', 'tests_configs.ini#command_test', + '-l', 'pof@pof.pof', + '-p', 'new_password', + '--send-email', + '--debug', + ]) + def test_func__user_create_command__err__password_required(self) -> None: """ Test User creation without filling password