|
@@ -1,14 +1,19 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
import pytest
|
3
|
3
|
import transaction
|
|
4
|
+from tracim_backend import models
|
4
|
5
|
|
5
|
|
-from tracim_backend.exceptions import AuthenticationFailed
|
|
6
|
+from tracim_backend.exceptions import AuthenticationFailed, \
|
|
7
|
+ TooShortAutocompleteString
|
6
|
8
|
from tracim_backend.exceptions import UserDoesNotExist
|
7
|
9
|
from tracim_backend.exceptions import UserNotActive
|
8
|
10
|
from tracim_backend.lib.core.group import GroupApi
|
9
|
11
|
from tracim_backend.lib.core.user import UserApi
|
|
12
|
+from tracim_backend.lib.core.userworkspace import RoleApi
|
|
13
|
+from tracim_backend.lib.core.workspace import WorkspaceApi
|
10
|
14
|
from tracim_backend.models import User
|
11
|
15
|
from tracim_backend.models.context_models import UserInContext
|
|
16
|
+from tracim_backend.models.data import UserRoleInWorkspace
|
12
|
17
|
from tracim_backend.tests import DefaultTest
|
13
|
18
|
from tracim_backend.tests import eq_
|
14
|
19
|
|
|
@@ -107,6 +112,184 @@ class TestUserApi(DefaultTest):
|
107
|
112
|
# u1 + Admin user from BaseFixture
|
108
|
113
|
assert 2 == len(users)
|
109
|
114
|
|
|
115
|
+ def test_unit__get_known__user__admin__too_short_acp_str(self):
|
|
116
|
+ api = UserApi(
|
|
117
|
+ current_user=None,
|
|
118
|
+ session=self.session,
|
|
119
|
+ config=self.config,
|
|
120
|
+ )
|
|
121
|
+ u1 = api.create_user(
|
|
122
|
+ email='email@email',
|
|
123
|
+ name='name',
|
|
124
|
+ do_notify=False,
|
|
125
|
+ do_save=True,
|
|
126
|
+ )
|
|
127
|
+ with pytest.raises(TooShortAutocompleteString):
|
|
128
|
+ api.get_known_user('e')
|
|
129
|
+
|
|
130
|
+ def test_unit__get_known__user__admin__by_email(self):
|
|
131
|
+ api = UserApi(
|
|
132
|
+ current_user=None,
|
|
133
|
+ session=self.session,
|
|
134
|
+ config=self.config,
|
|
135
|
+ )
|
|
136
|
+ u1 = api.create_user(
|
|
137
|
+ email='email@email',
|
|
138
|
+ name='name',
|
|
139
|
+ do_notify=False,
|
|
140
|
+ do_save=True,
|
|
141
|
+ )
|
|
142
|
+
|
|
143
|
+ users = api.get_known_user('email')
|
|
144
|
+ assert len(users) == 1
|
|
145
|
+ assert users[0] == u1
|
|
146
|
+
|
|
147
|
+ def test_unit__get_known__user__user__no_workspace_empty_known_user(self):
|
|
148
|
+ admin = self.session.query(models.User) \
|
|
149
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
150
|
+ .one()
|
|
151
|
+ api = UserApi(
|
|
152
|
+ current_user=admin,
|
|
153
|
+ session=self.session,
|
|
154
|
+ config=self.config,
|
|
155
|
+ )
|
|
156
|
+ u1 = api.create_user(
|
|
157
|
+ email='email@email',
|
|
158
|
+ name='name',
|
|
159
|
+ do_notify=False,
|
|
160
|
+ do_save=True,
|
|
161
|
+ )
|
|
162
|
+ api2 = UserApi(
|
|
163
|
+ current_user=u1,
|
|
164
|
+ session=self.session,
|
|
165
|
+ config=self.config,
|
|
166
|
+ )
|
|
167
|
+ users = api2.get_known_user('email')
|
|
168
|
+ assert len(users) == 0
|
|
169
|
+
|
|
170
|
+ def test_unit__get_known__user__same_workspaces_users_by_name(self):
|
|
171
|
+ admin = self.session.query(models.User) \
|
|
172
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
173
|
+ .one()
|
|
174
|
+ api = UserApi(
|
|
175
|
+ current_user=None,
|
|
176
|
+ session=self.session,
|
|
177
|
+ config=self.config,
|
|
178
|
+ )
|
|
179
|
+ u1 = api.create_user(
|
|
180
|
+ email='email@email',
|
|
181
|
+ name='name',
|
|
182
|
+ do_notify=False,
|
|
183
|
+ do_save=True,
|
|
184
|
+ )
|
|
185
|
+ u2 = api.create_user(
|
|
186
|
+ email='email2@email2',
|
|
187
|
+ name='name2',
|
|
188
|
+ do_notify=False,
|
|
189
|
+ do_save=True,
|
|
190
|
+ )
|
|
191
|
+ u3 = api.create_user(
|
|
192
|
+ email='notfound@notfound',
|
|
193
|
+ name='notfound',
|
|
194
|
+ do_notify=False,
|
|
195
|
+ do_save=True,
|
|
196
|
+ )
|
|
197
|
+ wapi = WorkspaceApi(
|
|
198
|
+ current_user=admin,
|
|
199
|
+ session=self.session,
|
|
200
|
+ config=self.app_config,
|
|
201
|
+ )
|
|
202
|
+ workspace = wapi.create_workspace(
|
|
203
|
+ 'test workspace n°1',
|
|
204
|
+ save_now=True)
|
|
205
|
+ role_api = RoleApi(
|
|
206
|
+ current_user=admin,
|
|
207
|
+ session=self.session,
|
|
208
|
+ config=self.app_config,
|
|
209
|
+ )
|
|
210
|
+ role_api.create_one(u1, workspace, UserRoleInWorkspace.READER, False)
|
|
211
|
+ role_api.create_one(u2, workspace, UserRoleInWorkspace.READER, False)
|
|
212
|
+ role_api.create_one(u3, workspace, UserRoleInWorkspace.READER, False)
|
|
213
|
+ api2 = UserApi(
|
|
214
|
+ current_user=u1,
|
|
215
|
+ session=self.session,
|
|
216
|
+ config=self.config,
|
|
217
|
+ )
|
|
218
|
+ users = api2.get_known_user('name')
|
|
219
|
+ assert len(users) == 2
|
|
220
|
+ assert users[0] == u1
|
|
221
|
+ assert users[1] == u2
|
|
222
|
+
|
|
223
|
+ def test_unit__get_known__user__same_workspaces_users_by_email(self):
|
|
224
|
+ admin = self.session.query(models.User) \
|
|
225
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
226
|
+ .one()
|
|
227
|
+ api = UserApi(
|
|
228
|
+ current_user=None,
|
|
229
|
+ session=self.session,
|
|
230
|
+ config=self.config,
|
|
231
|
+ )
|
|
232
|
+ u1 = api.create_user(
|
|
233
|
+ email='email@email',
|
|
234
|
+ name='name',
|
|
235
|
+ do_notify=False,
|
|
236
|
+ do_save=True,
|
|
237
|
+ )
|
|
238
|
+ u2 = api.create_user(
|
|
239
|
+ email='email2@email2',
|
|
240
|
+ name='name2',
|
|
241
|
+ do_notify=False,
|
|
242
|
+ do_save=True,
|
|
243
|
+ )
|
|
244
|
+ u3 = api.create_user(
|
|
245
|
+ email='notfound@notfound',
|
|
246
|
+ name='notfound',
|
|
247
|
+ do_notify=False,
|
|
248
|
+ do_save=True,
|
|
249
|
+ )
|
|
250
|
+ wapi = WorkspaceApi(
|
|
251
|
+ current_user=admin,
|
|
252
|
+ session=self.session,
|
|
253
|
+ config=self.app_config,
|
|
254
|
+ )
|
|
255
|
+ workspace = wapi.create_workspace(
|
|
256
|
+ 'test workspace n°1',
|
|
257
|
+ save_now=True)
|
|
258
|
+ role_api = RoleApi(
|
|
259
|
+ current_user=admin,
|
|
260
|
+ session=self.session,
|
|
261
|
+ config=self.app_config,
|
|
262
|
+ )
|
|
263
|
+ role_api.create_one(u1, workspace, UserRoleInWorkspace.READER, False)
|
|
264
|
+ role_api.create_one(u2, workspace, UserRoleInWorkspace.READER, False)
|
|
265
|
+ role_api.create_one(u3, workspace, UserRoleInWorkspace.READER, False)
|
|
266
|
+ api2 = UserApi(
|
|
267
|
+ current_user=u1,
|
|
268
|
+ session=self.session,
|
|
269
|
+ config=self.config,
|
|
270
|
+ )
|
|
271
|
+ users = api2.get_known_user('email')
|
|
272
|
+ assert len(users) == 2
|
|
273
|
+ assert users[0] == u1
|
|
274
|
+ assert users[1] == u2
|
|
275
|
+
|
|
276
|
+ def test_unit__get_known__user__admin__by_name(self):
|
|
277
|
+ api = UserApi(
|
|
278
|
+ current_user=None,
|
|
279
|
+ session=self.session,
|
|
280
|
+ config=self.config,
|
|
281
|
+ )
|
|
282
|
+ u1 = api.create_user(
|
|
283
|
+ email='email@email',
|
|
284
|
+ name='name',
|
|
285
|
+ do_notify=False,
|
|
286
|
+ do_save=True,
|
|
287
|
+ )
|
|
288
|
+
|
|
289
|
+ users = api.get_known_user('nam')
|
|
290
|
+ assert len(users) == 1
|
|
291
|
+ assert users[0] == u1
|
|
292
|
+
|
110
|
293
|
def test_unit__get_one__ok__nominal_case(self):
|
111
|
294
|
api = UserApi(
|
112
|
295
|
current_user=None,
|