| @@ 4625-4692 (lines=68) @@ | ||
| 4622 | assert res['timezone'] == 'Europe/London' |
|
| 4623 | assert res['lang'] == 'en' |
|
| 4624 | ||
| 4625 | def test_api__set_user_info__ok_200__user_itself(self): |
|
| 4626 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4627 | admin = dbsession.query(models.User) \ |
|
| 4628 | .filter(models.User.email == '[email protected]') \ |
|
| 4629 | .one() |
|
| 4630 | uapi = UserApi( |
|
| 4631 | current_user=admin, |
|
| 4632 | session=dbsession, |
|
| 4633 | config=self.app_config, |
|
| 4634 | ) |
|
| 4635 | gapi = GroupApi( |
|
| 4636 | current_user=admin, |
|
| 4637 | session=dbsession, |
|
| 4638 | config=self.app_config, |
|
| 4639 | ) |
|
| 4640 | groups = [gapi.get_one_with_name('users')] |
|
| 4641 | test_user = uapi.create_user( |
|
| 4642 | email='[email protected]', |
|
| 4643 | password='pass', |
|
| 4644 | name='bob', |
|
| 4645 | groups=groups, |
|
| 4646 | timezone='Europe/Paris', |
|
| 4647 | lang='fr', |
|
| 4648 | do_save=True, |
|
| 4649 | do_notify=False, |
|
| 4650 | ) |
|
| 4651 | uapi.save(test_user) |
|
| 4652 | transaction.commit() |
|
| 4653 | user_id = int(test_user.user_id) |
|
| 4654 | ||
| 4655 | self.testapp.authorization = ( |
|
| 4656 | 'Basic', |
|
| 4657 | ( |
|
| 4658 | '[email protected]', |
|
| 4659 | 'pass', |
|
| 4660 | ) |
|
| 4661 | ) |
|
| 4662 | # check before |
|
| 4663 | res = self.testapp.get( |
|
| 4664 | '/api/v2/users/{}'.format(user_id), |
|
| 4665 | status=200 |
|
| 4666 | ) |
|
| 4667 | res = res.json_body |
|
| 4668 | assert res['user_id'] == user_id |
|
| 4669 | assert res['public_name'] == 'bob' |
|
| 4670 | assert res['timezone'] == 'Europe/Paris' |
|
| 4671 | assert res['lang'] == 'fr' |
|
| 4672 | # Set params |
|
| 4673 | params = { |
|
| 4674 | 'public_name': 'updated', |
|
| 4675 | 'timezone': 'Europe/London', |
|
| 4676 | 'lang': 'en', |
|
| 4677 | } |
|
| 4678 | self.testapp.put_json( |
|
| 4679 | '/api/v2/users/{}'.format(user_id), |
|
| 4680 | params=params, |
|
| 4681 | status=200, |
|
| 4682 | ) |
|
| 4683 | # Check After |
|
| 4684 | res = self.testapp.get( |
|
| 4685 | '/api/v2/users/{}'.format(user_id), |
|
| 4686 | status=200 |
|
| 4687 | ) |
|
| 4688 | res = res.json_body |
|
| 4689 | assert res['user_id'] == user_id |
|
| 4690 | assert res['public_name'] == 'updated' |
|
| 4691 | assert res['timezone'] == 'Europe/London' |
|
| 4692 | assert res['lang'] == 'en' |
|
| 4693 | ||
| 4694 | def test_api__set_user_email__err_403__other_normal_user(self): |
|
| 4695 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 4556-4623 (lines=68) @@ | ||
| 4553 | """ |
|
| 4554 | fixtures = [BaseFixture] |
|
| 4555 | ||
| 4556 | def test_api__set_user_info__ok_200__admin(self): |
|
| 4557 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4558 | admin = dbsession.query(models.User) \ |
|
| 4559 | .filter(models.User.email == '[email protected]') \ |
|
| 4560 | .one() |
|
| 4561 | uapi = UserApi( |
|
| 4562 | current_user=admin, |
|
| 4563 | session=dbsession, |
|
| 4564 | config=self.app_config, |
|
| 4565 | ) |
|
| 4566 | gapi = GroupApi( |
|
| 4567 | current_user=admin, |
|
| 4568 | session=dbsession, |
|
| 4569 | config=self.app_config, |
|
| 4570 | ) |
|
| 4571 | groups = [gapi.get_one_with_name('users')] |
|
| 4572 | test_user = uapi.create_user( |
|
| 4573 | email='[email protected]', |
|
| 4574 | password='pass', |
|
| 4575 | name='bob', |
|
| 4576 | groups=groups, |
|
| 4577 | timezone='Europe/Paris', |
|
| 4578 | lang='fr', |
|
| 4579 | do_save=True, |
|
| 4580 | do_notify=False, |
|
| 4581 | ) |
|
| 4582 | uapi.save(test_user) |
|
| 4583 | transaction.commit() |
|
| 4584 | user_id = int(test_user.user_id) |
|
| 4585 | ||
| 4586 | self.testapp.authorization = ( |
|
| 4587 | 'Basic', |
|
| 4588 | ( |
|
| 4589 | '[email protected]', |
|
| 4590 | '[email protected]' |
|
| 4591 | ) |
|
| 4592 | ) |
|
| 4593 | # check before |
|
| 4594 | res = self.testapp.get( |
|
| 4595 | '/api/v2/users/{}'.format(user_id), |
|
| 4596 | status=200 |
|
| 4597 | ) |
|
| 4598 | res = res.json_body |
|
| 4599 | assert res['user_id'] == user_id |
|
| 4600 | assert res['public_name'] == 'bob' |
|
| 4601 | assert res['timezone'] == 'Europe/Paris' |
|
| 4602 | assert res['lang'] == 'fr' |
|
| 4603 | # Set params |
|
| 4604 | params = { |
|
| 4605 | 'public_name': 'updated', |
|
| 4606 | 'timezone': 'Europe/London', |
|
| 4607 | 'lang': 'en', |
|
| 4608 | } |
|
| 4609 | self.testapp.put_json( |
|
| 4610 | '/api/v2/users/{}'.format(user_id), |
|
| 4611 | params=params, |
|
| 4612 | status=200, |
|
| 4613 | ) |
|
| 4614 | # Check After |
|
| 4615 | res = self.testapp.get( |
|
| 4616 | '/api/v2/users/{}'.format(user_id), |
|
| 4617 | status=200 |
|
| 4618 | ) |
|
| 4619 | res = res.json_body |
|
| 4620 | assert res['user_id'] == user_id |
|
| 4621 | assert res['public_name'] == 'updated' |
|
| 4622 | assert res['timezone'] == 'Europe/London' |
|
| 4623 | assert res['lang'] == 'en' |
|
| 4624 | ||
| 4625 | def test_api__set_user_info__ok_200__user_itself(self): |
|
| 4626 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|