@@ 4825-4886 (lines=62) @@ | ||
4822 | assert res['user_id'] == user_id |
|
4823 | assert res['profile'] == 'administrators' |
|
4824 | ||
4825 | def test_api__set_user_info__err_403__user_itself(self): |
|
4826 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
4827 | admin = dbsession.query(models.User) \ |
|
4828 | .filter(models.User.email == '[email protected]') \ |
|
4829 | .one() |
|
4830 | uapi = UserApi( |
|
4831 | current_user=admin, |
|
4832 | session=dbsession, |
|
4833 | config=self.app_config, |
|
4834 | ) |
|
4835 | gapi = GroupApi( |
|
4836 | current_user=admin, |
|
4837 | session=dbsession, |
|
4838 | config=self.app_config, |
|
4839 | ) |
|
4840 | groups = [gapi.get_one_with_name('users')] |
|
4841 | test_user = uapi.create_user( |
|
4842 | email='[email protected]', |
|
4843 | password='pass', |
|
4844 | name='bob', |
|
4845 | groups=groups, |
|
4846 | timezone='Europe/Paris', |
|
4847 | lang='fr', |
|
4848 | do_save=True, |
|
4849 | do_notify=False, |
|
4850 | ) |
|
4851 | uapi.save(test_user) |
|
4852 | transaction.commit() |
|
4853 | user_id = int(test_user.user_id) |
|
4854 | ||
4855 | self.testapp.authorization = ( |
|
4856 | 'Basic', |
|
4857 | ( |
|
4858 | '[email protected]', |
|
4859 | 'pass', |
|
4860 | ) |
|
4861 | ) |
|
4862 | # check before |
|
4863 | res = self.testapp.get( |
|
4864 | '/api/v2/users/{}'.format(user_id), |
|
4865 | status=200 |
|
4866 | ) |
|
4867 | res = res.json_body |
|
4868 | assert res['user_id'] == user_id |
|
4869 | assert res['profile'] == 'users' |
|
4870 | # Set params |
|
4871 | params = { |
|
4872 | 'profile': 'administrators', |
|
4873 | } |
|
4874 | self.testapp.put_json( |
|
4875 | '/api/v2/users/{}/profile'.format(user_id), |
|
4876 | params=params, |
|
4877 | status=403, |
|
4878 | ) |
|
4879 | # Check After |
|
4880 | res = self.testapp.get( |
|
4881 | '/api/v2/users/{}'.format(user_id), |
|
4882 | status=200 |
|
4883 | ) |
|
4884 | res = res.json_body |
|
4885 | assert res['user_id'] == user_id |
|
4886 | assert res['profile'] == 'users' |
|
4887 | ||
4888 | def test_api__set_user_email__err_403__other_normal_user(self): |
|
4889 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
@@ 4762-4823 (lines=62) @@ | ||
4759 | """ |
|
4760 | fixtures = [BaseFixture] |
|
4761 | ||
4762 | def test_api__set_user_info__ok_200__admin(self): |
|
4763 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
4764 | admin = dbsession.query(models.User) \ |
|
4765 | .filter(models.User.email == '[email protected]') \ |
|
4766 | .one() |
|
4767 | uapi = UserApi( |
|
4768 | current_user=admin, |
|
4769 | session=dbsession, |
|
4770 | config=self.app_config, |
|
4771 | ) |
|
4772 | gapi = GroupApi( |
|
4773 | current_user=admin, |
|
4774 | session=dbsession, |
|
4775 | config=self.app_config, |
|
4776 | ) |
|
4777 | groups = [gapi.get_one_with_name('users')] |
|
4778 | test_user = uapi.create_user( |
|
4779 | email='[email protected]', |
|
4780 | password='pass', |
|
4781 | name='bob', |
|
4782 | groups=groups, |
|
4783 | timezone='Europe/Paris', |
|
4784 | lang='fr', |
|
4785 | do_save=True, |
|
4786 | do_notify=False, |
|
4787 | ) |
|
4788 | uapi.save(test_user) |
|
4789 | transaction.commit() |
|
4790 | user_id = int(test_user.user_id) |
|
4791 | ||
4792 | self.testapp.authorization = ( |
|
4793 | 'Basic', |
|
4794 | ( |
|
4795 | '[email protected]', |
|
4796 | '[email protected]' |
|
4797 | ) |
|
4798 | ) |
|
4799 | # check before |
|
4800 | res = self.testapp.get( |
|
4801 | '/api/v2/users/{}'.format(user_id), |
|
4802 | status=200 |
|
4803 | ) |
|
4804 | res = res.json_body |
|
4805 | assert res['user_id'] == user_id |
|
4806 | assert res['profile'] == 'users' |
|
4807 | # Set params |
|
4808 | params = { |
|
4809 | 'profile': 'administrators', |
|
4810 | } |
|
4811 | self.testapp.put_json( |
|
4812 | '/api/v2/users/{}/profile'.format(user_id), |
|
4813 | params=params, |
|
4814 | status=204, |
|
4815 | ) |
|
4816 | # Check After |
|
4817 | res = self.testapp.get( |
|
4818 | '/api/v2/users/{}'.format(user_id), |
|
4819 | status=200 |
|
4820 | ) |
|
4821 | res = res.json_body |
|
4822 | assert res['user_id'] == user_id |
|
4823 | assert res['profile'] == 'administrators' |
|
4824 | ||
4825 | def test_api__set_user_info__err_403__user_itself(self): |
|
4826 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
@@ 5181-5238 (lines=58) @@ | ||
5178 | status=403, |
|
5179 | ) |
|
5180 | ||
5181 | def test_api_disable_user__ok_200__user_itself(self): |
|
5182 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
5183 | admin = dbsession.query(models.User) \ |
|
5184 | .filter(models.User.email == '[email protected]') \ |
|
5185 | .one() |
|
5186 | uapi = UserApi( |
|
5187 | current_user=admin, |
|
5188 | session=dbsession, |
|
5189 | config=self.app_config, |
|
5190 | ) |
|
5191 | gapi = GroupApi( |
|
5192 | current_user=admin, |
|
5193 | session=dbsession, |
|
5194 | config=self.app_config, |
|
5195 | ) |
|
5196 | groups = [gapi.get_one_with_name('users')] |
|
5197 | test_user = uapi.create_user( |
|
5198 | email='[email protected]', |
|
5199 | password='pass', |
|
5200 | name='bob', |
|
5201 | groups=groups, |
|
5202 | timezone='Europe/Paris', |
|
5203 | lang='fr', |
|
5204 | do_save=True, |
|
5205 | do_notify=False, |
|
5206 | ) |
|
5207 | uapi.enable(test_user, do_save=True) |
|
5208 | uapi.save(test_user) |
|
5209 | transaction.commit() |
|
5210 | user_id = int(test_user.user_id) |
|
5211 | ||
5212 | self.testapp.authorization = ( |
|
5213 | 'Basic', |
|
5214 | ( |
|
5215 | '[email protected]', |
|
5216 | 'pass' |
|
5217 | ) |
|
5218 | ) |
|
5219 | # check before |
|
5220 | res = self.testapp.get( |
|
5221 | '/api/v2/users/{}'.format(user_id), |
|
5222 | status=200 |
|
5223 | ) |
|
5224 | res = res.json_body |
|
5225 | assert res['user_id'] == user_id |
|
5226 | assert res['is_active'] is True |
|
5227 | self.testapp.put_json( |
|
5228 | '/api/v2/users/{}/disable'.format(user_id), |
|
5229 | status=403, |
|
5230 | ) |
|
5231 | # Check After |
|
5232 | res = self.testapp.get( |
|
5233 | '/api/v2/users/{}'.format(user_id), |
|
5234 | status=200 |
|
5235 | ) |
|
5236 | res = res.json_body |
|
5237 | assert res['user_id'] == user_id |
|
5238 | assert res['is_active'] is True |
|
5239 | ||
@@ 5014-5071 (lines=58) @@ | ||
5011 | assert res['user_id'] == user_id |
|
5012 | assert res['is_active'] is True |
|
5013 | ||
5014 | def test_api_disable_user__ok_200__admin(self): |
|
5015 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
5016 | admin = dbsession.query(models.User) \ |
|
5017 | .filter(models.User.email == '[email protected]') \ |
|
5018 | .one() |
|
5019 | uapi = UserApi( |
|
5020 | current_user=admin, |
|
5021 | session=dbsession, |
|
5022 | config=self.app_config, |
|
5023 | ) |
|
5024 | gapi = GroupApi( |
|
5025 | current_user=admin, |
|
5026 | session=dbsession, |
|
5027 | config=self.app_config, |
|
5028 | ) |
|
5029 | groups = [gapi.get_one_with_name('users')] |
|
5030 | test_user = uapi.create_user( |
|
5031 | email='[email protected]', |
|
5032 | password='pass', |
|
5033 | name='bob', |
|
5034 | groups=groups, |
|
5035 | timezone='Europe/Paris', |
|
5036 | lang='fr', |
|
5037 | do_save=True, |
|
5038 | do_notify=False, |
|
5039 | ) |
|
5040 | uapi.enable(test_user, do_save=True) |
|
5041 | uapi.save(test_user) |
|
5042 | transaction.commit() |
|
5043 | user_id = int(test_user.user_id) |
|
5044 | ||
5045 | self.testapp.authorization = ( |
|
5046 | 'Basic', |
|
5047 | ( |
|
5048 | '[email protected]', |
|
5049 | '[email protected]' |
|
5050 | ) |
|
5051 | ) |
|
5052 | # check before |
|
5053 | res = self.testapp.get( |
|
5054 | '/api/v2/users/{}'.format(user_id), |
|
5055 | status=200 |
|
5056 | ) |
|
5057 | res = res.json_body |
|
5058 | assert res['user_id'] == user_id |
|
5059 | assert res['is_active'] is True |
|
5060 | self.testapp.put_json( |
|
5061 | '/api/v2/users/{}/disable'.format(user_id), |
|
5062 | status=204, |
|
5063 | ) |
|
5064 | # Check After |
|
5065 | res = self.testapp.get( |
|
5066 | '/api/v2/users/{}'.format(user_id), |
|
5067 | status=200 |
|
5068 | ) |
|
5069 | res = res.json_body |
|
5070 | assert res['user_id'] == user_id |
|
5071 | assert res['is_active'] is False |
|
5072 | ||
5073 | def test_api_enable_user__err_403__other_account(self): |
|
5074 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
@@ 4955-5012 (lines=58) @@ | ||
4952 | """ |
|
4953 | fixtures = [BaseFixture] |
|
4954 | ||
4955 | def test_api_enable_user__ok_200__admin(self): |
|
4956 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
4957 | admin = dbsession.query(models.User) \ |
|
4958 | .filter(models.User.email == '[email protected]') \ |
|
4959 | .one() |
|
4960 | uapi = UserApi( |
|
4961 | current_user=admin, |
|
4962 | session=dbsession, |
|
4963 | config=self.app_config, |
|
4964 | ) |
|
4965 | gapi = GroupApi( |
|
4966 | current_user=admin, |
|
4967 | session=dbsession, |
|
4968 | config=self.app_config, |
|
4969 | ) |
|
4970 | groups = [gapi.get_one_with_name('users')] |
|
4971 | test_user = uapi.create_user( |
|
4972 | email='[email protected]', |
|
4973 | password='pass', |
|
4974 | name='bob', |
|
4975 | groups=groups, |
|
4976 | timezone='Europe/Paris', |
|
4977 | lang='fr', |
|
4978 | do_save=True, |
|
4979 | do_notify=False, |
|
4980 | ) |
|
4981 | uapi.disable(test_user, do_save=True) |
|
4982 | uapi.save(test_user) |
|
4983 | transaction.commit() |
|
4984 | user_id = int(test_user.user_id) |
|
4985 | ||
4986 | self.testapp.authorization = ( |
|
4987 | 'Basic', |
|
4988 | ( |
|
4989 | '[email protected]', |
|
4990 | '[email protected]' |
|
4991 | ) |
|
4992 | ) |
|
4993 | # check before |
|
4994 | res = self.testapp.get( |
|
4995 | '/api/v2/users/{}'.format(user_id), |
|
4996 | status=200 |
|
4997 | ) |
|
4998 | res = res.json_body |
|
4999 | assert res['user_id'] == user_id |
|
5000 | assert res['is_active'] is False |
|
5001 | self.testapp.put_json( |
|
5002 | '/api/v2/users/{}/enable'.format(user_id), |
|
5003 | status=204, |
|
5004 | ) |
|
5005 | # Check After |
|
5006 | res = self.testapp.get( |
|
5007 | '/api/v2/users/{}'.format(user_id), |
|
5008 | status=200 |
|
5009 | ) |
|
5010 | res = res.json_body |
|
5011 | assert res['user_id'] == user_id |
|
5012 | assert res['is_active'] is True |
|
5013 | ||
5014 | def test_api_disable_user__ok_200__admin(self): |
|
5015 | dbsession = get_tm_session(self.session_factory, transaction.manager) |