@@ 3502-3541 (lines=40) @@ | ||
3499 | assert res[1]['public_name'] == test_user.display_name |
|
3500 | assert res[1]['avatar_url'] is None |
|
3501 | ||
3502 | def test_api__get_user__err_403__normal_user(self): |
|
3503 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
3504 | admin = dbsession.query(models.User) \ |
|
3505 | .filter(models.User.email == '[email protected]') \ |
|
3506 | .one() |
|
3507 | uapi = UserApi( |
|
3508 | current_user=admin, |
|
3509 | session=dbsession, |
|
3510 | config=self.app_config, |
|
3511 | ) |
|
3512 | gapi = GroupApi( |
|
3513 | current_user=admin, |
|
3514 | session=dbsession, |
|
3515 | config=self.app_config, |
|
3516 | ) |
|
3517 | groups = [gapi.get_one_with_name('users')] |
|
3518 | test_user = uapi.create_user( |
|
3519 | email='[email protected]', |
|
3520 | password='pass', |
|
3521 | name='bob', |
|
3522 | groups=groups, |
|
3523 | timezone='Europe/Paris', |
|
3524 | lang='fr', |
|
3525 | do_save=True, |
|
3526 | do_notify=False, |
|
3527 | ) |
|
3528 | uapi.save(test_user) |
|
3529 | transaction.commit() |
|
3530 | user_id = int(test_user.user_id) |
|
3531 | ||
3532 | self.testapp.authorization = ( |
|
3533 | 'Basic', |
|
3534 | ( |
|
3535 | '[email protected]', |
|
3536 | 'pass' |
|
3537 | ) |
|
3538 | ) |
|
3539 | self.testapp.get( |
|
3540 | '/api/v2/users', |
|
3541 | status=403 |
|
3542 | ) |
|
3543 | ||
3544 |
@@ 165-202 (lines=38) @@ | ||
162 | assert res.json_body['avatar_url'] is None |
|
163 | assert res.json_body['lang'] is None |
|
164 | ||
165 | def test_api__try_whoami_enpoint__err_401__user_is_not_active(self): |
|
166 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
167 | admin = dbsession.query(models.User) \ |
|
168 | .filter(models.User.email == '[email protected]') \ |
|
169 | .one() |
|
170 | uapi = UserApi( |
|
171 | current_user=admin, |
|
172 | session=dbsession, |
|
173 | config=self.app_config, |
|
174 | ) |
|
175 | gapi = GroupApi( |
|
176 | current_user=admin, |
|
177 | session=dbsession, |
|
178 | config=self.app_config, |
|
179 | ) |
|
180 | groups = [gapi.get_one_with_name('users')] |
|
181 | test_user = uapi.create_user( |
|
182 | email='[email protected]', |
|
183 | password='pass', |
|
184 | name='bob', |
|
185 | groups=groups, |
|
186 | timezone='Europe/Paris', |
|
187 | lang='en', |
|
188 | do_save=True, |
|
189 | do_notify=False, |
|
190 | ) |
|
191 | uapi.save(test_user) |
|
192 | uapi.disable(test_user) |
|
193 | transaction.commit() |
|
194 | self.testapp.authorization = ( |
|
195 | 'Basic', |
|
196 | ( |
|
197 | '[email protected]', |
|
198 | 'pass' |
|
199 | ) |
|
200 | ) |
|
201 | ||
202 | res = self.testapp.get('/api/v2/sessions/whoami', status=401) |
|
203 | ||
204 | def test_api__try_whoami_enpoint__err_401__unauthenticated(self): |
|
205 | self.testapp.authorization = ( |
|
@@ 67-103 (lines=37) @@ | ||
64 | assert res.json_body['caldav_url'] is None |
|
65 | assert res.json_body['avatar_url'] is None |
|
66 | ||
67 | def test_api__try_login_enpoint__err_401__user_not_activated(self): |
|
68 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
69 | admin = dbsession.query(models.User) \ |
|
70 | .filter(models.User.email == '[email protected]') \ |
|
71 | .one() |
|
72 | uapi = UserApi( |
|
73 | current_user=admin, |
|
74 | session=dbsession, |
|
75 | config=self.app_config, |
|
76 | ) |
|
77 | gapi = GroupApi( |
|
78 | current_user=admin, |
|
79 | session=dbsession, |
|
80 | config=self.app_config, |
|
81 | ) |
|
82 | groups = [gapi.get_one_with_name('users')] |
|
83 | test_user = uapi.create_user( |
|
84 | email='[email protected]', |
|
85 | password='pass', |
|
86 | name='bob', |
|
87 | groups=groups, |
|
88 | timezone='Europe/Paris', |
|
89 | do_save=True, |
|
90 | do_notify=False, |
|
91 | ) |
|
92 | uapi.save(test_user) |
|
93 | uapi.disable(test_user) |
|
94 | transaction.commit() |
|
95 | ||
96 | params = { |
|
97 | 'email': '[email protected]', |
|
98 | 'password': '[email protected]', |
|
99 | } |
|
100 | res = self.testapp.post_json( |
|
101 | '/api/v2/sessions/login', |
|
102 | params=params, |
|
103 | status=403, |
|
104 | ) |
|
105 | ||
106 | def test_api__try_login_enpoint__err_403__bad_password(self): |
|
@@ 240-275 (lines=36) @@ | ||
237 | assert res.json_body['caldav_url'] is None |
|
238 | assert res.json_body['avatar_url'] is None |
|
239 | ||
240 | def test_api__try_whoami_enpoint__err_401__user_is_not_active(self): |
|
241 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
242 | admin = dbsession.query(models.User) \ |
|
243 | .filter(models.User.email == '[email protected]') \ |
|
244 | .one() |
|
245 | uapi = UserApi( |
|
246 | current_user=admin, |
|
247 | session=dbsession, |
|
248 | config=self.app_config, |
|
249 | ) |
|
250 | gapi = GroupApi( |
|
251 | current_user=admin, |
|
252 | session=dbsession, |
|
253 | config=self.app_config, |
|
254 | ) |
|
255 | groups = [gapi.get_one_with_name('users')] |
|
256 | test_user = uapi.create_user( |
|
257 | email='[email protected]', |
|
258 | password='pass', |
|
259 | name='bob', |
|
260 | groups=groups, |
|
261 | timezone='Europe/Paris', |
|
262 | do_save=True, |
|
263 | do_notify=False, |
|
264 | ) |
|
265 | uapi.save(test_user) |
|
266 | uapi.disable(test_user) |
|
267 | transaction.commit() |
|
268 | headers_auth = { |
|
269 | 'Tracim-Api-Key': 'mysuperapikey', |
|
270 | 'Tracim-Api-Login': '[email protected]', |
|
271 | } |
|
272 | res = self.testapp.get( |
|
273 | '/api/v2/sessions/whoami', |
|
274 | status=401, |
|
275 | headers=headers_auth |
|
276 | ) |
|
277 | ||
278 | def test_api__try_whoami_enpoint__err_401__unauthenticated(self): |