@@ 2092-2159 (lines=68) @@ | ||
2089 | """ |
|
2090 | fixtures = [BaseFixture] |
|
2091 | ||
2092 | def test_api__set_account_info__ok_200__nominal(self): |
|
2093 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2094 | admin = dbsession.query(models.User) \ |
|
2095 | .filter(models.User.email == '[email protected]') \ |
|
2096 | .one() |
|
2097 | uapi = UserApi( |
|
2098 | current_user=admin, |
|
2099 | session=dbsession, |
|
2100 | config=self.app_config, |
|
2101 | ) |
|
2102 | gapi = GroupApi( |
|
2103 | current_user=admin, |
|
2104 | session=dbsession, |
|
2105 | config=self.app_config, |
|
2106 | ) |
|
2107 | groups = [gapi.get_one_with_name('users')] |
|
2108 | test_user = uapi.create_user( |
|
2109 | email='[email protected]', |
|
2110 | password='pass', |
|
2111 | name='bob', |
|
2112 | groups=groups, |
|
2113 | timezone='Europe/Paris', |
|
2114 | lang='fr', |
|
2115 | do_save=True, |
|
2116 | do_notify=False, |
|
2117 | ) |
|
2118 | uapi.save(test_user) |
|
2119 | transaction.commit() |
|
2120 | user_id = int(test_user.user_id) |
|
2121 | ||
2122 | self.testapp.authorization = ( |
|
2123 | 'Basic', |
|
2124 | ( |
|
2125 | '[email protected]', |
|
2126 | 'pass', |
|
2127 | ) |
|
2128 | ) |
|
2129 | # check before |
|
2130 | res = self.testapp.get( |
|
2131 | '/api/v2/users/me', |
|
2132 | status=200 |
|
2133 | ) |
|
2134 | res = res.json_body |
|
2135 | assert res['user_id'] == user_id |
|
2136 | assert res['public_name'] == 'bob' |
|
2137 | assert res['timezone'] == 'Europe/Paris' |
|
2138 | assert res['lang'] == 'fr' |
|
2139 | # Set params |
|
2140 | params = { |
|
2141 | 'public_name': 'updated', |
|
2142 | 'timezone': 'Europe/London', |
|
2143 | 'lang': 'en', |
|
2144 | } |
|
2145 | self.testapp.put_json( |
|
2146 | '/api/v2/users/me', |
|
2147 | params=params, |
|
2148 | status=200, |
|
2149 | ) |
|
2150 | # Check After |
|
2151 | res = self.testapp.get( |
|
2152 | '/api/v2/users/me', |
|
2153 | status=200 |
|
2154 | ) |
|
2155 | res = res.json_body |
|
2156 | assert res['user_id'] == user_id |
|
2157 | assert res['public_name'] == 'updated' |
|
2158 | assert res['timezone'] == 'Europe/London' |
|
2159 | assert res['lang'] == 'en' |
|
2160 |
@@ 5212-5279 (lines=68) @@ | ||
5209 | assert res['timezone'] == 'Europe/London' |
|
5210 | assert res['lang'] == 'en' |
|
5211 | ||
5212 | def test_api__set_user_info__ok_200__user_itself(self): |
|
5213 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
5214 | admin = dbsession.query(models.User) \ |
|
5215 | .filter(models.User.email == '[email protected]') \ |
|
5216 | .one() |
|
5217 | uapi = UserApi( |
|
5218 | current_user=admin, |
|
5219 | session=dbsession, |
|
5220 | config=self.app_config, |
|
5221 | ) |
|
5222 | gapi = GroupApi( |
|
5223 | current_user=admin, |
|
5224 | session=dbsession, |
|
5225 | config=self.app_config, |
|
5226 | ) |
|
5227 | groups = [gapi.get_one_with_name('users')] |
|
5228 | test_user = uapi.create_user( |
|
5229 | email='[email protected]', |
|
5230 | password='pass', |
|
5231 | name='bob', |
|
5232 | groups=groups, |
|
5233 | timezone='Europe/Paris', |
|
5234 | lang='fr', |
|
5235 | do_save=True, |
|
5236 | do_notify=False, |
|
5237 | ) |
|
5238 | uapi.save(test_user) |
|
5239 | transaction.commit() |
|
5240 | user_id = int(test_user.user_id) |
|
5241 | ||
5242 | self.testapp.authorization = ( |
|
5243 | 'Basic', |
|
5244 | ( |
|
5245 | '[email protected]', |
|
5246 | 'pass', |
|
5247 | ) |
|
5248 | ) |
|
5249 | # check before |
|
5250 | res = self.testapp.get( |
|
5251 | '/api/v2/users/{}'.format(user_id), |
|
5252 | status=200 |
|
5253 | ) |
|
5254 | res = res.json_body |
|
5255 | assert res['user_id'] == user_id |
|
5256 | assert res['public_name'] == 'bob' |
|
5257 | assert res['timezone'] == 'Europe/Paris' |
|
5258 | assert res['lang'] == 'fr' |
|
5259 | # Set params |
|
5260 | params = { |
|
5261 | 'public_name': 'updated', |
|
5262 | 'timezone': 'Europe/London', |
|
5263 | 'lang': 'en', |
|
5264 | } |
|
5265 | self.testapp.put_json( |
|
5266 | '/api/v2/users/{}'.format(user_id), |
|
5267 | params=params, |
|
5268 | status=200, |
|
5269 | ) |
|
5270 | # Check After |
|
5271 | res = self.testapp.get( |
|
5272 | '/api/v2/users/{}'.format(user_id), |
|
5273 | status=200 |
|
5274 | ) |
|
5275 | res = res.json_body |
|
5276 | assert res['user_id'] == user_id |
|
5277 | assert res['public_name'] == 'updated' |
|
5278 | assert res['timezone'] == 'Europe/London' |
|
5279 | assert res['lang'] == 'en' |
|
5280 | ||
5281 | def test_api__set_user_info__err_403__other_normal_user(self): |
|
5282 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
@@ 5143-5210 (lines=68) @@ | ||
5140 | """ |
|
5141 | fixtures = [BaseFixture] |
|
5142 | ||
5143 | def test_api__set_user_info__ok_200__admin(self): |
|
5144 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
5145 | admin = dbsession.query(models.User) \ |
|
5146 | .filter(models.User.email == '[email protected]') \ |
|
5147 | .one() |
|
5148 | uapi = UserApi( |
|
5149 | current_user=admin, |
|
5150 | session=dbsession, |
|
5151 | config=self.app_config, |
|
5152 | ) |
|
5153 | gapi = GroupApi( |
|
5154 | current_user=admin, |
|
5155 | session=dbsession, |
|
5156 | config=self.app_config, |
|
5157 | ) |
|
5158 | groups = [gapi.get_one_with_name('users')] |
|
5159 | test_user = uapi.create_user( |
|
5160 | email='[email protected]', |
|
5161 | password='pass', |
|
5162 | name='bob', |
|
5163 | groups=groups, |
|
5164 | timezone='Europe/Paris', |
|
5165 | lang='fr', |
|
5166 | do_save=True, |
|
5167 | do_notify=False, |
|
5168 | ) |
|
5169 | uapi.save(test_user) |
|
5170 | transaction.commit() |
|
5171 | user_id = int(test_user.user_id) |
|
5172 | ||
5173 | self.testapp.authorization = ( |
|
5174 | 'Basic', |
|
5175 | ( |
|
5176 | '[email protected]', |
|
5177 | '[email protected]' |
|
5178 | ) |
|
5179 | ) |
|
5180 | # check before |
|
5181 | res = self.testapp.get( |
|
5182 | '/api/v2/users/{}'.format(user_id), |
|
5183 | status=200 |
|
5184 | ) |
|
5185 | res = res.json_body |
|
5186 | assert res['user_id'] == user_id |
|
5187 | assert res['public_name'] == 'bob' |
|
5188 | assert res['timezone'] == 'Europe/Paris' |
|
5189 | assert res['lang'] == 'fr' |
|
5190 | # Set params |
|
5191 | params = { |
|
5192 | 'public_name': 'updated', |
|
5193 | 'timezone': 'Europe/London', |
|
5194 | 'lang': 'en', |
|
5195 | } |
|
5196 | self.testapp.put_json( |
|
5197 | '/api/v2/users/{}'.format(user_id), |
|
5198 | params=params, |
|
5199 | status=200, |
|
5200 | ) |
|
5201 | # Check After |
|
5202 | res = self.testapp.get( |
|
5203 | '/api/v2/users/{}'.format(user_id), |
|
5204 | status=200 |
|
5205 | ) |
|
5206 | res = res.json_body |
|
5207 | assert res['user_id'] == user_id |
|
5208 | assert res['public_name'] == 'updated' |
|
5209 | assert res['timezone'] == 'Europe/London' |
|
5210 | assert res['lang'] == 'en' |
|
5211 | ||
5212 | def test_api__set_user_info__ok_200__user_itself(self): |
|
5213 | dbsession = get_tm_session(self.session_factory, transaction.manager) |