| @@ 4098-4166 (lines=69) @@ | ||
| 4095 | res = res.json_body |
|
| 4096 | assert res['email'] == '[email protected]' |
|
| 4097 | ||
| 4098 | def test_api__set_user_email__ok_200__user_itself(self): |
|
| 4099 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4100 | admin = dbsession.query(models.User) \ |
|
| 4101 | .filter(models.User.email == '[email protected]') \ |
|
| 4102 | .one() |
|
| 4103 | uapi = UserApi( |
|
| 4104 | current_user=admin, |
|
| 4105 | session=dbsession, |
|
| 4106 | config=self.app_config, |
|
| 4107 | ) |
|
| 4108 | gapi = GroupApi( |
|
| 4109 | current_user=admin, |
|
| 4110 | session=dbsession, |
|
| 4111 | config=self.app_config, |
|
| 4112 | ) |
|
| 4113 | groups = [gapi.get_one_with_name('users')] |
|
| 4114 | test_user = uapi.create_user( |
|
| 4115 | email='[email protected]', |
|
| 4116 | password='pass', |
|
| 4117 | name='bob', |
|
| 4118 | groups=groups, |
|
| 4119 | timezone='Europe/Paris', |
|
| 4120 | lang='fr', |
|
| 4121 | do_save=True, |
|
| 4122 | do_notify=False, |
|
| 4123 | ) |
|
| 4124 | uapi.save(test_user) |
|
| 4125 | transaction.commit() |
|
| 4126 | user_id = int(test_user.user_id) |
|
| 4127 | ||
| 4128 | self.testapp.authorization = ( |
|
| 4129 | 'Basic', |
|
| 4130 | ( |
|
| 4131 | '[email protected]', |
|
| 4132 | 'pass' |
|
| 4133 | ) |
|
| 4134 | ) |
|
| 4135 | # check before |
|
| 4136 | res = self.testapp.get( |
|
| 4137 | '/api/v2/users/{}'.format(user_id), |
|
| 4138 | status=200 |
|
| 4139 | ) |
|
| 4140 | res = res.json_body |
|
| 4141 | assert res['email'] == '[email protected]' |
|
| 4142 | ||
| 4143 | # Set password |
|
| 4144 | params = { |
|
| 4145 | 'email': '[email protected]', |
|
| 4146 | 'loggedin_user_password': 'pass', |
|
| 4147 | } |
|
| 4148 | self.testapp.put_json( |
|
| 4149 | '/api/v2/users/{}/email'.format(user_id), |
|
| 4150 | params=params, |
|
| 4151 | status=200, |
|
| 4152 | ) |
|
| 4153 | self.testapp.authorization = ( |
|
| 4154 | 'Basic', |
|
| 4155 | ( |
|
| 4156 | '[email protected]', |
|
| 4157 | 'pass' |
|
| 4158 | ) |
|
| 4159 | ) |
|
| 4160 | # Check After |
|
| 4161 | res = self.testapp.get( |
|
| 4162 | '/api/v2/users/{}'.format(user_id), |
|
| 4163 | status=200 |
|
| 4164 | ) |
|
| 4165 | res = res.json_body |
|
| 4166 | assert res['email'] == '[email protected]' |
|
| 4167 | ||
| 4168 | def test_api__set_user_email__err_403__other_normal_user(self): |
|
| 4169 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 4035-4096 (lines=62) @@ | ||
| 4032 | res = res.json_body |
|
| 4033 | assert res['email'] == '[email protected]' |
|
| 4034 | ||
| 4035 | def test_api__set_user_email__err_400__admin_string_is_not_email(self): |
|
| 4036 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4037 | admin = dbsession.query(models.User) \ |
|
| 4038 | .filter(models.User.email == '[email protected]') \ |
|
| 4039 | .one() |
|
| 4040 | uapi = UserApi( |
|
| 4041 | current_user=admin, |
|
| 4042 | session=dbsession, |
|
| 4043 | config=self.app_config, |
|
| 4044 | ) |
|
| 4045 | gapi = GroupApi( |
|
| 4046 | current_user=admin, |
|
| 4047 | session=dbsession, |
|
| 4048 | config=self.app_config, |
|
| 4049 | ) |
|
| 4050 | groups = [gapi.get_one_with_name('users')] |
|
| 4051 | test_user = uapi.create_user( |
|
| 4052 | email='[email protected]', |
|
| 4053 | password='pass', |
|
| 4054 | name='bob', |
|
| 4055 | groups=groups, |
|
| 4056 | timezone='Europe/Paris', |
|
| 4057 | lang='fr', |
|
| 4058 | do_save=True, |
|
| 4059 | do_notify=False, |
|
| 4060 | ) |
|
| 4061 | uapi.save(test_user) |
|
| 4062 | transaction.commit() |
|
| 4063 | user_id = int(test_user.user_id) |
|
| 4064 | ||
| 4065 | self.testapp.authorization = ( |
|
| 4066 | 'Basic', |
|
| 4067 | ( |
|
| 4068 | '[email protected]', |
|
| 4069 | '[email protected]' |
|
| 4070 | ) |
|
| 4071 | ) |
|
| 4072 | # check before |
|
| 4073 | res = self.testapp.get( |
|
| 4074 | '/api/v2/users/{}'.format(user_id), |
|
| 4075 | status=200 |
|
| 4076 | ) |
|
| 4077 | res = res.json_body |
|
| 4078 | assert res['email'] == '[email protected]' |
|
| 4079 | ||
| 4080 | # Set password |
|
| 4081 | params = { |
|
| 4082 | 'email': 'thatisnotandemail', |
|
| 4083 | 'loggedin_user_password': '[email protected]', |
|
| 4084 | } |
|
| 4085 | self.testapp.put_json( |
|
| 4086 | '/api/v2/users/{}/email'.format(user_id), |
|
| 4087 | params=params, |
|
| 4088 | status=400, |
|
| 4089 | ) |
|
| 4090 | # Check After |
|
| 4091 | res = self.testapp.get( |
|
| 4092 | '/api/v2/users/{}'.format(user_id), |
|
| 4093 | status=200 |
|
| 4094 | ) |
|
| 4095 | res = res.json_body |
|
| 4096 | assert res['email'] == '[email protected]' |
|
| 4097 | ||
| 4098 | def test_api__set_user_email__ok_200__user_itself(self): |
|
| 4099 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 3972-4033 (lines=62) @@ | ||
| 3969 | res = res.json_body |
|
| 3970 | assert res['email'] == '[email protected]' |
|
| 3971 | ||
| 3972 | def test_api__set_user_email__err_403__admin_wrong_password(self): |
|
| 3973 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 3974 | admin = dbsession.query(models.User) \ |
|
| 3975 | .filter(models.User.email == '[email protected]') \ |
|
| 3976 | .one() |
|
| 3977 | uapi = UserApi( |
|
| 3978 | current_user=admin, |
|
| 3979 | session=dbsession, |
|
| 3980 | config=self.app_config, |
|
| 3981 | ) |
|
| 3982 | gapi = GroupApi( |
|
| 3983 | current_user=admin, |
|
| 3984 | session=dbsession, |
|
| 3985 | config=self.app_config, |
|
| 3986 | ) |
|
| 3987 | groups = [gapi.get_one_with_name('users')] |
|
| 3988 | test_user = uapi.create_user( |
|
| 3989 | email='[email protected]', |
|
| 3990 | password='pass', |
|
| 3991 | name='bob', |
|
| 3992 | groups=groups, |
|
| 3993 | timezone='Europe/Paris', |
|
| 3994 | lang='fr', |
|
| 3995 | do_save=True, |
|
| 3996 | do_notify=False, |
|
| 3997 | ) |
|
| 3998 | uapi.save(test_user) |
|
| 3999 | transaction.commit() |
|
| 4000 | user_id = int(test_user.user_id) |
|
| 4001 | ||
| 4002 | self.testapp.authorization = ( |
|
| 4003 | 'Basic', |
|
| 4004 | ( |
|
| 4005 | '[email protected]', |
|
| 4006 | '[email protected]' |
|
| 4007 | ) |
|
| 4008 | ) |
|
| 4009 | # check before |
|
| 4010 | res = self.testapp.get( |
|
| 4011 | '/api/v2/users/{}'.format(user_id), |
|
| 4012 | status=200 |
|
| 4013 | ) |
|
| 4014 | res = res.json_body |
|
| 4015 | assert res['email'] == '[email protected]' |
|
| 4016 | ||
| 4017 | # Set password |
|
| 4018 | params = { |
|
| 4019 | 'email': '[email protected]', |
|
| 4020 | 'loggedin_user_password': 'badpassword', |
|
| 4021 | } |
|
| 4022 | self.testapp.put_json( |
|
| 4023 | '/api/v2/users/{}/email'.format(user_id), |
|
| 4024 | params=params, |
|
| 4025 | status=403, |
|
| 4026 | ) |
|
| 4027 | # Check After |
|
| 4028 | res = self.testapp.get( |
|
| 4029 | '/api/v2/users/{}'.format(user_id), |
|
| 4030 | status=200 |
|
| 4031 | ) |
|
| 4032 | res = res.json_body |
|
| 4033 | assert res['email'] == '[email protected]' |
|
| 4034 | ||
| 4035 | def test_api__set_user_email__err_400__admin_string_is_not_email(self): |
|
| 4036 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 3909-3970 (lines=62) @@ | ||
| 3906 | res = res.json_body |
|
| 3907 | assert res['email'] == '[email protected]' |
|
| 3908 | ||
| 3909 | def test_api__set_user_email__err_400__admin_same_email(self): |
|
| 3910 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 3911 | admin = dbsession.query(models.User) \ |
|
| 3912 | .filter(models.User.email == '[email protected]') \ |
|
| 3913 | .one() |
|
| 3914 | uapi = UserApi( |
|
| 3915 | current_user=admin, |
|
| 3916 | session=dbsession, |
|
| 3917 | config=self.app_config, |
|
| 3918 | ) |
|
| 3919 | gapi = GroupApi( |
|
| 3920 | current_user=admin, |
|
| 3921 | session=dbsession, |
|
| 3922 | config=self.app_config, |
|
| 3923 | ) |
|
| 3924 | groups = [gapi.get_one_with_name('users')] |
|
| 3925 | test_user = uapi.create_user( |
|
| 3926 | email='[email protected]', |
|
| 3927 | password='pass', |
|
| 3928 | name='bob', |
|
| 3929 | groups=groups, |
|
| 3930 | timezone='Europe/Paris', |
|
| 3931 | lang='fr', |
|
| 3932 | do_save=True, |
|
| 3933 | do_notify=False, |
|
| 3934 | ) |
|
| 3935 | uapi.save(test_user) |
|
| 3936 | transaction.commit() |
|
| 3937 | user_id = int(test_user.user_id) |
|
| 3938 | ||
| 3939 | self.testapp.authorization = ( |
|
| 3940 | 'Basic', |
|
| 3941 | ( |
|
| 3942 | '[email protected]', |
|
| 3943 | '[email protected]' |
|
| 3944 | ) |
|
| 3945 | ) |
|
| 3946 | # check before |
|
| 3947 | res = self.testapp.get( |
|
| 3948 | '/api/v2/users/{}'.format(user_id), |
|
| 3949 | status=200 |
|
| 3950 | ) |
|
| 3951 | res = res.json_body |
|
| 3952 | assert res['email'] == '[email protected]' |
|
| 3953 | ||
| 3954 | # Set password |
|
| 3955 | params = { |
|
| 3956 | 'email': '[email protected]', |
|
| 3957 | 'loggedin_user_password': '[email protected]', |
|
| 3958 | } |
|
| 3959 | self.testapp.put_json( |
|
| 3960 | '/api/v2/users/{}/email'.format(user_id), |
|
| 3961 | params=params, |
|
| 3962 | status=400, |
|
| 3963 | ) |
|
| 3964 | # Check After |
|
| 3965 | res = self.testapp.get( |
|
| 3966 | '/api/v2/users/{}'.format(user_id), |
|
| 3967 | status=200 |
|
| 3968 | ) |
|
| 3969 | res = res.json_body |
|
| 3970 | assert res['email'] == '[email protected]' |
|
| 3971 | ||
| 3972 | def test_api__set_user_email__err_403__admin_wrong_password(self): |
|
| 3973 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 3846-3907 (lines=62) @@ | ||
| 3843 | """ |
|
| 3844 | fixtures = [BaseFixture] |
|
| 3845 | ||
| 3846 | def test_api__set_user_email__ok_200__admin(self): |
|
| 3847 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 3848 | admin = dbsession.query(models.User) \ |
|
| 3849 | .filter(models.User.email == '[email protected]') \ |
|
| 3850 | .one() |
|
| 3851 | uapi = UserApi( |
|
| 3852 | current_user=admin, |
|
| 3853 | session=dbsession, |
|
| 3854 | config=self.app_config, |
|
| 3855 | ) |
|
| 3856 | gapi = GroupApi( |
|
| 3857 | current_user=admin, |
|
| 3858 | session=dbsession, |
|
| 3859 | config=self.app_config, |
|
| 3860 | ) |
|
| 3861 | groups = [gapi.get_one_with_name('users')] |
|
| 3862 | test_user = uapi.create_user( |
|
| 3863 | email='[email protected]', |
|
| 3864 | password='pass', |
|
| 3865 | name='bob', |
|
| 3866 | groups=groups, |
|
| 3867 | timezone='Europe/Paris', |
|
| 3868 | lang='fr', |
|
| 3869 | do_save=True, |
|
| 3870 | do_notify=False, |
|
| 3871 | ) |
|
| 3872 | uapi.save(test_user) |
|
| 3873 | transaction.commit() |
|
| 3874 | user_id = int(test_user.user_id) |
|
| 3875 | ||
| 3876 | self.testapp.authorization = ( |
|
| 3877 | 'Basic', |
|
| 3878 | ( |
|
| 3879 | '[email protected]', |
|
| 3880 | '[email protected]' |
|
| 3881 | ) |
|
| 3882 | ) |
|
| 3883 | # check before |
|
| 3884 | res = self.testapp.get( |
|
| 3885 | '/api/v2/users/{}'.format(user_id), |
|
| 3886 | status=200 |
|
| 3887 | ) |
|
| 3888 | res = res.json_body |
|
| 3889 | assert res['email'] == '[email protected]' |
|
| 3890 | ||
| 3891 | # Set password |
|
| 3892 | params = { |
|
| 3893 | 'email': '[email protected]', |
|
| 3894 | 'loggedin_user_password': '[email protected]', |
|
| 3895 | } |
|
| 3896 | self.testapp.put_json( |
|
| 3897 | '/api/v2/users/{}/email'.format(user_id), |
|
| 3898 | params=params, |
|
| 3899 | status=200, |
|
| 3900 | ) |
|
| 3901 | # Check After |
|
| 3902 | res = self.testapp.get( |
|
| 3903 | '/api/v2/users/{}'.format(user_id), |
|
| 3904 | status=200 |
|
| 3905 | ) |
|
| 3906 | res = res.json_body |
|
| 3907 | assert res['email'] == '[email protected]' |
|
| 3908 | ||
| 3909 | def test_api__set_user_email__err_400__admin_same_email(self): |
|
| 3910 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|