@@ 1808-1876 (lines=69) @@ | ||
1805 | res = res.json_body |
|
1806 | assert res['email'] == '[email protected]' |
|
1807 | ||
1808 | def test_api__set_account_email__ok_200__user_nominal(self): |
|
1809 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1810 | admin = dbsession.query(models.User) \ |
|
1811 | .filter(models.User.email == '[email protected]') \ |
|
1812 | .one() |
|
1813 | uapi = UserApi( |
|
1814 | current_user=admin, |
|
1815 | session=dbsession, |
|
1816 | config=self.app_config, |
|
1817 | ) |
|
1818 | gapi = GroupApi( |
|
1819 | current_user=admin, |
|
1820 | session=dbsession, |
|
1821 | config=self.app_config, |
|
1822 | ) |
|
1823 | groups = [gapi.get_one_with_name('users')] |
|
1824 | test_user = uapi.create_user( |
|
1825 | email='[email protected]', |
|
1826 | password='pass', |
|
1827 | name='bob', |
|
1828 | groups=groups, |
|
1829 | timezone='Europe/Paris', |
|
1830 | lang='fr', |
|
1831 | do_save=True, |
|
1832 | do_notify=False, |
|
1833 | ) |
|
1834 | uapi.save(test_user) |
|
1835 | transaction.commit() |
|
1836 | user_id = int(test_user.user_id) |
|
1837 | ||
1838 | self.testapp.authorization = ( |
|
1839 | 'Basic', |
|
1840 | ( |
|
1841 | '[email protected]', |
|
1842 | 'pass' |
|
1843 | ) |
|
1844 | ) |
|
1845 | # check before |
|
1846 | res = self.testapp.get( |
|
1847 | '/api/v2/users/me', |
|
1848 | status=200 |
|
1849 | ) |
|
1850 | res = res.json_body |
|
1851 | assert res['email'] == '[email protected]' |
|
1852 | ||
1853 | # Set password |
|
1854 | params = { |
|
1855 | 'email': '[email protected]', |
|
1856 | 'loggedin_user_password': 'pass', |
|
1857 | } |
|
1858 | self.testapp.put_json( |
|
1859 | '/api/v2/users/me/email', |
|
1860 | params=params, |
|
1861 | status=200, |
|
1862 | ) |
|
1863 | self.testapp.authorization = ( |
|
1864 | 'Basic', |
|
1865 | ( |
|
1866 | '[email protected]', |
|
1867 | 'pass' |
|
1868 | ) |
|
1869 | ) |
|
1870 | # Check After |
|
1871 | res = self.testapp.get( |
|
1872 | '/api/v2/users/me', |
|
1873 | status=200 |
|
1874 | ) |
|
1875 | res = res.json_body |
|
1876 | assert res['email'] == '[email protected]' |
|
1877 | ||
1878 | ||
1879 | class TestSetPasswordEndpoint(FunctionalTest): |
@@ 4673-4741 (lines=69) @@ | ||
4670 | res = res.json_body |
|
4671 | assert res['email'] == '[email protected]' |
|
4672 | ||
4673 | def test_api__set_user_email__ok_200__user_itself(self): |
|
4674 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
4675 | admin = dbsession.query(models.User) \ |
|
4676 | .filter(models.User.email == '[email protected]') \ |
|
4677 | .one() |
|
4678 | uapi = UserApi( |
|
4679 | current_user=admin, |
|
4680 | session=dbsession, |
|
4681 | config=self.app_config, |
|
4682 | ) |
|
4683 | gapi = GroupApi( |
|
4684 | current_user=admin, |
|
4685 | session=dbsession, |
|
4686 | config=self.app_config, |
|
4687 | ) |
|
4688 | groups = [gapi.get_one_with_name('users')] |
|
4689 | test_user = uapi.create_user( |
|
4690 | email='[email protected]', |
|
4691 | password='pass', |
|
4692 | name='bob', |
|
4693 | groups=groups, |
|
4694 | timezone='Europe/Paris', |
|
4695 | lang='fr', |
|
4696 | do_save=True, |
|
4697 | do_notify=False, |
|
4698 | ) |
|
4699 | uapi.save(test_user) |
|
4700 | transaction.commit() |
|
4701 | user_id = int(test_user.user_id) |
|
4702 | ||
4703 | self.testapp.authorization = ( |
|
4704 | 'Basic', |
|
4705 | ( |
|
4706 | '[email protected]', |
|
4707 | 'pass' |
|
4708 | ) |
|
4709 | ) |
|
4710 | # check before |
|
4711 | res = self.testapp.get( |
|
4712 | '/api/v2/users/{}'.format(user_id), |
|
4713 | status=200 |
|
4714 | ) |
|
4715 | res = res.json_body |
|
4716 | assert res['email'] == '[email protected]' |
|
4717 | ||
4718 | # Set password |
|
4719 | params = { |
|
4720 | 'email': '[email protected]', |
|
4721 | 'loggedin_user_password': 'pass', |
|
4722 | } |
|
4723 | self.testapp.put_json( |
|
4724 | '/api/v2/users/{}/email'.format(user_id), |
|
4725 | params=params, |
|
4726 | status=200, |
|
4727 | ) |
|
4728 | self.testapp.authorization = ( |
|
4729 | 'Basic', |
|
4730 | ( |
|
4731 | '[email protected]', |
|
4732 | 'pass' |
|
4733 | ) |
|
4734 | ) |
|
4735 | # Check After |
|
4736 | res = self.testapp.get( |
|
4737 | '/api/v2/users/{}'.format(user_id), |
|
4738 | status=200 |
|
4739 | ) |
|
4740 | res = res.json_body |
|
4741 | assert res['email'] == '[email protected]' |
|
4742 | ||
4743 | def test_api__set_user_email__err_403__other_normal_user(self): |
|
4744 | dbsession = get_tm_session(self.session_factory, transaction.manager) |