def update(): request_data = request.json logger.debug('--request_data--' + str(request_data)) id = request_data.get('id') if not id: abort(400) result = update_user(request_data) if not result: return Response(status=500) obj = convert_user_from_mongo(result) response_data = json.dumps(obj) logger.debug('--response_data--' + response_data) resp = Response(response=response_data, status=200, content_type='application/json') return resp
def test_update_user(self): name = 'user_name' password = '******' level = 'normal' add_user(name, password, level) user = get_user()[0] update_user(user, password='******', level='disable') user = get_user()[0] assert user.name == 'user_name' assert user.password == _encrypt(user.name, 'new_password') assert check_user_password(user, 'new_password') assert user.level == 'disable' try: update_user(user, name='some_name') except AttributeError: pass try: update_user(user, level='some_level') except AssertionError: pass
def patch(self, key): args = UserPatchArgs().args user = get_user(key=key)[0] update_user(user, **args) user = get_user(key=key)[0] return user