@@ 4253-4321 (lines=69) @@ | ||
4250 | res = res.json_body |
|
4251 | assert res['email'] == '[email protected]' |
|
4252 | ||
4253 | def test_api__set_user_email__ok_200__user_itself(self): |
|
4254 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
4255 | admin = dbsession.query(models.User) \ |
|
4256 | .filter(models.User.email == '[email protected]') \ |
|
4257 | .one() |
|
4258 | uapi = UserApi( |
|
4259 | current_user=admin, |
|
4260 | session=dbsession, |
|
4261 | config=self.app_config, |
|
4262 | ) |
|
4263 | gapi = GroupApi( |
|
4264 | current_user=admin, |
|
4265 | session=dbsession, |
|
4266 | config=self.app_config, |
|
4267 | ) |
|
4268 | groups = [gapi.get_one_with_name('users')] |
|
4269 | test_user = uapi.create_user( |
|
4270 | email='[email protected]', |
|
4271 | password='pass', |
|
4272 | name='bob', |
|
4273 | groups=groups, |
|
4274 | timezone='Europe/Paris', |
|
4275 | lang='fr', |
|
4276 | do_save=True, |
|
4277 | do_notify=False, |
|
4278 | ) |
|
4279 | uapi.save(test_user) |
|
4280 | transaction.commit() |
|
4281 | user_id = int(test_user.user_id) |
|
4282 | ||
4283 | self.testapp.authorization = ( |
|
4284 | 'Basic', |
|
4285 | ( |
|
4286 | '[email protected]', |
|
4287 | 'pass' |
|
4288 | ) |
|
4289 | ) |
|
4290 | # check before |
|
4291 | res = self.testapp.get( |
|
4292 | '/api/v2/users/{}'.format(user_id), |
|
4293 | status=200 |
|
4294 | ) |
|
4295 | res = res.json_body |
|
4296 | assert res['email'] == '[email protected]' |
|
4297 | ||
4298 | # Set password |
|
4299 | params = { |
|
4300 | 'email': '[email protected]', |
|
4301 | 'loggedin_user_password': 'pass', |
|
4302 | } |
|
4303 | self.testapp.put_json( |
|
4304 | '/api/v2/users/{}/email'.format(user_id), |
|
4305 | params=params, |
|
4306 | status=200, |
|
4307 | ) |
|
4308 | self.testapp.authorization = ( |
|
4309 | 'Basic', |
|
4310 | ( |
|
4311 | '[email protected]', |
|
4312 | 'pass' |
|
4313 | ) |
|
4314 | ) |
|
4315 | # Check After |
|
4316 | res = self.testapp.get( |
|
4317 | '/api/v2/users/{}'.format(user_id), |
|
4318 | status=200 |
|
4319 | ) |
|
4320 | res = res.json_body |
|
4321 | assert res['email'] == '[email protected]' |
|
4322 | ||
4323 | def test_api__set_user_email__err_403__other_normal_user(self): |
|
4324 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
@@ 1548-1616 (lines=69) @@ | ||
1545 | res = res.json_body |
|
1546 | assert res['email'] == '[email protected]' |
|
1547 | ||
1548 | def test_api__set_account_email__ok_200__user_nominal(self): |
|
1549 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1550 | admin = dbsession.query(models.User) \ |
|
1551 | .filter(models.User.email == '[email protected]') \ |
|
1552 | .one() |
|
1553 | uapi = UserApi( |
|
1554 | current_user=admin, |
|
1555 | session=dbsession, |
|
1556 | config=self.app_config, |
|
1557 | ) |
|
1558 | gapi = GroupApi( |
|
1559 | current_user=admin, |
|
1560 | session=dbsession, |
|
1561 | config=self.app_config, |
|
1562 | ) |
|
1563 | groups = [gapi.get_one_with_name('users')] |
|
1564 | test_user = uapi.create_user( |
|
1565 | email='[email protected]', |
|
1566 | password='pass', |
|
1567 | name='bob', |
|
1568 | groups=groups, |
|
1569 | timezone='Europe/Paris', |
|
1570 | lang='fr', |
|
1571 | do_save=True, |
|
1572 | do_notify=False, |
|
1573 | ) |
|
1574 | uapi.save(test_user) |
|
1575 | transaction.commit() |
|
1576 | user_id = int(test_user.user_id) |
|
1577 | ||
1578 | self.testapp.authorization = ( |
|
1579 | 'Basic', |
|
1580 | ( |
|
1581 | '[email protected]', |
|
1582 | 'pass' |
|
1583 | ) |
|
1584 | ) |
|
1585 | # check before |
|
1586 | res = self.testapp.get( |
|
1587 | '/api/v2/users/me', |
|
1588 | status=200 |
|
1589 | ) |
|
1590 | res = res.json_body |
|
1591 | assert res['email'] == '[email protected]' |
|
1592 | ||
1593 | # Set password |
|
1594 | params = { |
|
1595 | 'email': '[email protected]', |
|
1596 | 'loggedin_user_password': 'pass', |
|
1597 | } |
|
1598 | self.testapp.put_json( |
|
1599 | '/api/v2/users/me/email', |
|
1600 | params=params, |
|
1601 | status=200, |
|
1602 | ) |
|
1603 | self.testapp.authorization = ( |
|
1604 | 'Basic', |
|
1605 | ( |
|
1606 | '[email protected]', |
|
1607 | 'pass' |
|
1608 | ) |
|
1609 | ) |
|
1610 | # Check After |
|
1611 | res = self.testapp.get( |
|
1612 | '/api/v2/users/me', |
|
1613 | status=200 |
|
1614 | ) |
|
1615 | res = res.json_body |
|
1616 | assert res['email'] == '[email protected]' |
|
1617 | ||
1618 | ||
1619 | class TestSetPasswordEndpoint(FunctionalTest): |