|
@@ -10,7 +10,8 @@ from sqlalchemy.orm.exc import NoResultFound
|
10
|
10
|
import tracim
|
11
|
11
|
from tracim.command import TracimCLI
|
12
|
12
|
from tracim.command.user import UserCommand
|
13
|
|
-from tracim.exceptions import UserNotExist
|
|
13
|
+from tracim.exceptions import UserAlreadyExistError, BadCommandError, \
|
|
14
|
+ GroupNotExist
|
14
|
15
|
from tracim.lib.core.user import UserApi
|
15
|
16
|
from tracim.tests import CommandFunctionalTest
|
16
|
17
|
|
|
@@ -22,7 +23,7 @@ class TestCommands(CommandFunctionalTest):
|
22
|
23
|
|
23
|
24
|
config_section = 'app:command_test'
|
24
|
25
|
|
25
|
|
- def test_func__check_commands_list__ok__nominal_case(self):
|
|
26
|
+ def test_func__check_commands_list__ok__nominal_case(self) -> None:
|
26
|
27
|
"""
|
27
|
28
|
Test listing of tracimcli command: Tracim commands must be listed
|
28
|
29
|
:return:
|
|
@@ -38,7 +39,7 @@ class TestCommands(CommandFunctionalTest):
|
38
|
39
|
assert output.find('db delete') > 0
|
39
|
40
|
assert output.find('webdav start') > 0
|
40
|
41
|
|
41
|
|
- def test_func__user_create_command__ok__nominal_case(self):
|
|
42
|
+ def test_func__user_create_command__ok__nominal_case(self) -> None:
|
42
|
43
|
"""
|
43
|
44
|
Test User creation
|
44
|
45
|
"""
|
|
@@ -54,13 +55,99 @@ class TestCommands(CommandFunctionalTest):
|
54
|
55
|
'user', 'create',
|
55
|
56
|
'-c', 'tests_configs.ini#command_test',
|
56
|
57
|
'-l', 'command_test@user',
|
57
|
|
- '-p', 'new_password'
|
|
58
|
+ '-p', 'new_password',
|
|
59
|
+ '--debug',
|
58
|
60
|
])
|
59
|
61
|
new_user = api.get_one_by_email('command_test@user')
|
60
|
62
|
assert new_user.email == 'command_test@user'
|
61
|
63
|
assert new_user.validate_password('new_password')
|
|
64
|
+ assert new_user.profile.name == 'users'
|
62
|
65
|
|
63
|
|
- def test_func__user_update_command__ok__nominal_case(self):
|
|
66
|
+ def test_func__user_create_command__ok__in_admin_group(self) -> None:
|
|
67
|
+ """
|
|
68
|
+ Test User creation with admin as group
|
|
69
|
+ """
|
|
70
|
+ api = UserApi(
|
|
71
|
+ current_user=None,
|
|
72
|
+ session=self.session,
|
|
73
|
+ config=self.app_config,
|
|
74
|
+ )
|
|
75
|
+ with pytest.raises(NoResultFound):
|
|
76
|
+ api.get_one_by_email('command_test@user')
|
|
77
|
+ app = TracimCLI()
|
|
78
|
+ result = app.run([
|
|
79
|
+ 'user', 'create',
|
|
80
|
+ '-c', 'tests_configs.ini#command_test',
|
|
81
|
+ '-l', 'command_test@user',
|
|
82
|
+ '-p', 'new_password',
|
|
83
|
+ '-g', 'administrators',
|
|
84
|
+ '--debug',
|
|
85
|
+ ])
|
|
86
|
+ new_user = api.get_one_by_email('command_test@user')
|
|
87
|
+ assert new_user.email == 'command_test@user'
|
|
88
|
+ assert new_user.validate_password('new_password')
|
|
89
|
+ assert new_user.profile.name == 'administrators'
|
|
90
|
+
|
|
91
|
+ def test_func__user_create_command__err__in_unknown_group(self) -> None:
|
|
92
|
+ """
|
|
93
|
+ Test User creation with an unknown group
|
|
94
|
+ """
|
|
95
|
+ api = UserApi(
|
|
96
|
+ current_user=None,
|
|
97
|
+ session=self.session,
|
|
98
|
+ config=self.app_config,
|
|
99
|
+ )
|
|
100
|
+ app = TracimCLI()
|
|
101
|
+ with pytest.raises(GroupNotExist):
|
|
102
|
+ result = app.run([
|
|
103
|
+ 'user', 'create',
|
|
104
|
+ '-c', 'tests_configs.ini#command_test',
|
|
105
|
+ '-l', 'command_test@user',
|
|
106
|
+ '-p', 'new_password',
|
|
107
|
+ '-g', 'unknown',
|
|
108
|
+ '--debug',
|
|
109
|
+ ])
|
|
110
|
+
|
|
111
|
+ def test_func__user_create_command__err_user_already_exist(self) -> None:
|
|
112
|
+ """
|
|
113
|
+ Test User creation with existing user login
|
|
114
|
+ """
|
|
115
|
+ api = UserApi(
|
|
116
|
+ current_user=None,
|
|
117
|
+ session=self.session,
|
|
118
|
+ config=self.app_config,
|
|
119
|
+ )
|
|
120
|
+ app = TracimCLI()
|
|
121
|
+ with pytest.raises(UserAlreadyExistError):
|
|
122
|
+ result = app.run([
|
|
123
|
+ '--debug',
|
|
124
|
+ 'user', 'create',
|
|
125
|
+ '-c', 'tests_configs.ini#command_test',
|
|
126
|
+ '-l', 'admin@admin.admin',
|
|
127
|
+ '-p', 'new_password',
|
|
128
|
+ '--debug',
|
|
129
|
+ ])
|
|
130
|
+
|
|
131
|
+ def test_func__user_create_command__err__password_required(self) -> None:
|
|
132
|
+ """
|
|
133
|
+ Test User creation without filling password
|
|
134
|
+ """
|
|
135
|
+ api = UserApi(
|
|
136
|
+ current_user=None,
|
|
137
|
+ session=self.session,
|
|
138
|
+ config=self.app_config,
|
|
139
|
+ )
|
|
140
|
+ app = TracimCLI()
|
|
141
|
+ with pytest.raises(BadCommandError):
|
|
142
|
+ result = app.run([
|
|
143
|
+ '--debug',
|
|
144
|
+ 'user', 'create',
|
|
145
|
+ '-c', 'tests_configs.ini#command_test',
|
|
146
|
+ '-l', 'admin@admin.admin',
|
|
147
|
+ '--debug',
|
|
148
|
+ ])
|
|
149
|
+
|
|
150
|
+ def test_func__user_update_command__ok__nominal_case(self) -> None:
|
64
|
151
|
"""
|
65
|
152
|
Test user password update
|
66
|
153
|
"""
|
|
@@ -79,9 +166,39 @@ class TestCommands(CommandFunctionalTest):
|
79
|
166
|
'user', 'update',
|
80
|
167
|
'-c', 'tests_configs.ini#command_test',
|
81
|
168
|
'-l', 'admin@admin.admin',
|
82
|
|
- '-p', 'new_password'
|
|
169
|
+ '-p', 'new_password',
|
|
170
|
+ '--debug',
|
|
171
|
+ ])
|
|
172
|
+ new_user = api.get_one_by_email('admin@admin.admin')
|
|
173
|
+ assert new_user.email == 'admin@admin.admin'
|
|
174
|
+ assert new_user.validate_password('new_password')
|
|
175
|
+ assert not new_user.validate_password('admin@admin.admin')
|
|
176
|
+
|
|
177
|
+ def test_func__user_update_command__ok__remove_group(self) -> None:
|
|
178
|
+ """
|
|
179
|
+ Test user password update
|
|
180
|
+ """
|
|
181
|
+ api = UserApi(
|
|
182
|
+ current_user=None,
|
|
183
|
+ session=self.session,
|
|
184
|
+ config=self.app_config,
|
|
185
|
+ )
|
|
186
|
+ user = api.get_one_by_email('admin@admin.admin')
|
|
187
|
+ assert user.email == 'admin@admin.admin'
|
|
188
|
+ assert user.validate_password('admin@admin.admin')
|
|
189
|
+ assert not user.validate_password('new_password')
|
|
190
|
+ assert user.profile.name == 'administrators'
|
|
191
|
+ app = TracimCLI()
|
|
192
|
+ result = app.run([
|
|
193
|
+ 'user', 'update',
|
|
194
|
+ '-c', 'tests_configs.ini#command_test',
|
|
195
|
+ '-l', 'admin@admin.admin',
|
|
196
|
+ '-p', 'new_password',
|
|
197
|
+ '-rmg', 'administrators',
|
|
198
|
+ '--debug',
|
83
|
199
|
])
|
84
|
200
|
new_user = api.get_one_by_email('admin@admin.admin')
|
85
|
201
|
assert new_user.email == 'admin@admin.admin'
|
86
|
202
|
assert new_user.validate_password('new_password')
|
87
|
203
|
assert not new_user.validate_password('admin@admin.admin')
|
|
204
|
+ assert new_user.profile.name == 'managers'
|