@@ 4792-4859 (lines=68) @@ | ||
4789 | assert res['timezone'] == 'Europe/London' |
|
4790 | assert res['lang'] == 'en' |
|
4791 | ||
4792 | def test_api__set_user_info__ok_200__user_itself(self): |
|
4793 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
4794 | admin = dbsession.query(models.User) \ |
|
4795 | .filter(models.User.email == '[email protected]') \ |
|
4796 | .one() |
|
4797 | uapi = UserApi( |
|
4798 | current_user=admin, |
|
4799 | session=dbsession, |
|
4800 | config=self.app_config, |
|
4801 | ) |
|
4802 | gapi = GroupApi( |
|
4803 | current_user=admin, |
|
4804 | session=dbsession, |
|
4805 | config=self.app_config, |
|
4806 | ) |
|
4807 | groups = [gapi.get_one_with_name('users')] |
|
4808 | test_user = uapi.create_user( |
|
4809 | email='[email protected]', |
|
4810 | password='pass', |
|
4811 | name='bob', |
|
4812 | groups=groups, |
|
4813 | timezone='Europe/Paris', |
|
4814 | lang='fr', |
|
4815 | do_save=True, |
|
4816 | do_notify=False, |
|
4817 | ) |
|
4818 | uapi.save(test_user) |
|
4819 | transaction.commit() |
|
4820 | user_id = int(test_user.user_id) |
|
4821 | ||
4822 | self.testapp.authorization = ( |
|
4823 | 'Basic', |
|
4824 | ( |
|
4825 | '[email protected]', |
|
4826 | 'pass', |
|
4827 | ) |
|
4828 | ) |
|
4829 | # check before |
|
4830 | res = self.testapp.get( |
|
4831 | '/api/v2/users/{}'.format(user_id), |
|
4832 | status=200 |
|
4833 | ) |
|
4834 | res = res.json_body |
|
4835 | assert res['user_id'] == user_id |
|
4836 | assert res['public_name'] == 'bob' |
|
4837 | assert res['timezone'] == 'Europe/Paris' |
|
4838 | assert res['lang'] == 'fr' |
|
4839 | # Set params |
|
4840 | params = { |
|
4841 | 'public_name': 'updated', |
|
4842 | 'timezone': 'Europe/London', |
|
4843 | 'lang': 'en', |
|
4844 | } |
|
4845 | self.testapp.put_json( |
|
4846 | '/api/v2/users/{}'.format(user_id), |
|
4847 | params=params, |
|
4848 | status=200, |
|
4849 | ) |
|
4850 | # Check After |
|
4851 | res = self.testapp.get( |
|
4852 | '/api/v2/users/{}'.format(user_id), |
|
4853 | status=200 |
|
4854 | ) |
|
4855 | res = res.json_body |
|
4856 | assert res['user_id'] == user_id |
|
4857 | assert res['public_name'] == 'updated' |
|
4858 | assert res['timezone'] == 'Europe/London' |
|
4859 | assert res['lang'] == 'en' |
|
4860 | ||
4861 | def test_api__set_user_info__err_403__other_normal_user(self): |
|
4862 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
@@ 4723-4790 (lines=68) @@ | ||
4720 | """ |
|
4721 | fixtures = [BaseFixture] |
|
4722 | ||
4723 | def test_api__set_user_info__ok_200__admin(self): |
|
4724 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
4725 | admin = dbsession.query(models.User) \ |
|
4726 | .filter(models.User.email == '[email protected]') \ |
|
4727 | .one() |
|
4728 | uapi = UserApi( |
|
4729 | current_user=admin, |
|
4730 | session=dbsession, |
|
4731 | config=self.app_config, |
|
4732 | ) |
|
4733 | gapi = GroupApi( |
|
4734 | current_user=admin, |
|
4735 | session=dbsession, |
|
4736 | config=self.app_config, |
|
4737 | ) |
|
4738 | groups = [gapi.get_one_with_name('users')] |
|
4739 | test_user = uapi.create_user( |
|
4740 | email='[email protected]', |
|
4741 | password='pass', |
|
4742 | name='bob', |
|
4743 | groups=groups, |
|
4744 | timezone='Europe/Paris', |
|
4745 | lang='fr', |
|
4746 | do_save=True, |
|
4747 | do_notify=False, |
|
4748 | ) |
|
4749 | uapi.save(test_user) |
|
4750 | transaction.commit() |
|
4751 | user_id = int(test_user.user_id) |
|
4752 | ||
4753 | self.testapp.authorization = ( |
|
4754 | 'Basic', |
|
4755 | ( |
|
4756 | '[email protected]', |
|
4757 | '[email protected]' |
|
4758 | ) |
|
4759 | ) |
|
4760 | # check before |
|
4761 | res = self.testapp.get( |
|
4762 | '/api/v2/users/{}'.format(user_id), |
|
4763 | status=200 |
|
4764 | ) |
|
4765 | res = res.json_body |
|
4766 | assert res['user_id'] == user_id |
|
4767 | assert res['public_name'] == 'bob' |
|
4768 | assert res['timezone'] == 'Europe/Paris' |
|
4769 | assert res['lang'] == 'fr' |
|
4770 | # Set params |
|
4771 | params = { |
|
4772 | 'public_name': 'updated', |
|
4773 | 'timezone': 'Europe/London', |
|
4774 | 'lang': 'en', |
|
4775 | } |
|
4776 | self.testapp.put_json( |
|
4777 | '/api/v2/users/{}'.format(user_id), |
|
4778 | params=params, |
|
4779 | status=200, |
|
4780 | ) |
|
4781 | # Check After |
|
4782 | res = self.testapp.get( |
|
4783 | '/api/v2/users/{}'.format(user_id), |
|
4784 | status=200 |
|
4785 | ) |
|
4786 | res = res.json_body |
|
4787 | assert res['user_id'] == user_id |
|
4788 | assert res['public_name'] == 'updated' |
|
4789 | assert res['timezone'] == 'Europe/London' |
|
4790 | assert res['lang'] == 'en' |
|
4791 | ||
4792 | def test_api__set_user_info__ok_200__user_itself(self): |
|
4793 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
@@ 1832-1899 (lines=68) @@ | ||
1829 | """ |
|
1830 | fixtures = [BaseFixture] |
|
1831 | ||
1832 | def test_api__set_account_info__ok_200__nominal(self): |
|
1833 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1834 | admin = dbsession.query(models.User) \ |
|
1835 | .filter(models.User.email == '[email protected]') \ |
|
1836 | .one() |
|
1837 | uapi = UserApi( |
|
1838 | current_user=admin, |
|
1839 | session=dbsession, |
|
1840 | config=self.app_config, |
|
1841 | ) |
|
1842 | gapi = GroupApi( |
|
1843 | current_user=admin, |
|
1844 | session=dbsession, |
|
1845 | config=self.app_config, |
|
1846 | ) |
|
1847 | groups = [gapi.get_one_with_name('users')] |
|
1848 | test_user = uapi.create_user( |
|
1849 | email='[email protected]', |
|
1850 | password='pass', |
|
1851 | name='bob', |
|
1852 | groups=groups, |
|
1853 | timezone='Europe/Paris', |
|
1854 | lang='fr', |
|
1855 | do_save=True, |
|
1856 | do_notify=False, |
|
1857 | ) |
|
1858 | uapi.save(test_user) |
|
1859 | transaction.commit() |
|
1860 | user_id = int(test_user.user_id) |
|
1861 | ||
1862 | self.testapp.authorization = ( |
|
1863 | 'Basic', |
|
1864 | ( |
|
1865 | '[email protected]', |
|
1866 | 'pass', |
|
1867 | ) |
|
1868 | ) |
|
1869 | # check before |
|
1870 | res = self.testapp.get( |
|
1871 | '/api/v2/users/me', |
|
1872 | status=200 |
|
1873 | ) |
|
1874 | res = res.json_body |
|
1875 | assert res['user_id'] == user_id |
|
1876 | assert res['public_name'] == 'bob' |
|
1877 | assert res['timezone'] == 'Europe/Paris' |
|
1878 | assert res['lang'] == 'fr' |
|
1879 | # Set params |
|
1880 | params = { |
|
1881 | 'public_name': 'updated', |
|
1882 | 'timezone': 'Europe/London', |
|
1883 | 'lang': 'en', |
|
1884 | } |
|
1885 | self.testapp.put_json( |
|
1886 | '/api/v2/users/me', |
|
1887 | params=params, |
|
1888 | status=200, |
|
1889 | ) |
|
1890 | # Check After |
|
1891 | res = self.testapp.get( |
|
1892 | '/api/v2/users/me', |
|
1893 | status=200 |
|
1894 | ) |
|
1895 | res = res.json_body |
|
1896 | assert res['user_id'] == user_id |
|
1897 | assert res['public_name'] == 'updated' |
|
1898 | assert res['timezone'] == 'Europe/London' |
|
1899 | assert res['lang'] == 'en' |
|
1900 |