Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
rework exception for create user from tracimcli + support notificatio…
Browse files Browse the repository at this point in the history
…ndisabled case by test
  • Loading branch information
inkhey committed Sep 26, 2018
1 parent 1fecbcc commit f739eb3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
12 changes: 6 additions & 6 deletions backend/tracim_backend/command/user.py
Expand Up @@ -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(
Expand Down
17 changes: 17 additions & 0 deletions backend/tracim_backend/tests/commands/test_commands.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f739eb3

Please sign in to comment.