def test_update_user_birthday_fail(self): user = User('*****@*****.**') assert user.birthday is None args = dict( birthday='-100-07-13' ) logger.warn = MagicMock() assert update_user(args, user) is False assert user.birthday is None assert logger.warn.call_count == 1
def test_update_user(self): user = User('*****@*****.**') assert user.name is None assert user.last_name is None assert user.profession is None assert user.birthday is None args = dict( name=u'Ren\xe8', last_name=u'Descartes', profession='Philosopher', birthday='1596-03-31' ) db.session = MagicMock() logger.warn = MagicMock() update_user(args, user) assert user.birthday == date(1596, 3, 31) assert user.name == args['name'].encode('utf-8') assert user.last_name == args['last_name'] assert user.profession == args['profession'] assert logger.warn.call_count == 0
def post(self, user_id): """ Updates user information. :param user_id :return: Flask response """ self.request_parser.add_argument('confirm', type=str, required=False) self.request_parser.add_argument('source', type=str, required=False) self.request_parser.add_argument('name', type=unicode, required=False) self.request_parser.add_argument('last_name', type=unicode, required=False) self.request_parser.add_argument('profession', type=unicode, required=False) self.request_parser.add_argument('birthday', type=str, required=False) args = self.request_parser.parse_args() user = service.get_user_by_id(user_id) if not user: return make_response('User with id ' + str(user_id) + ' does not exist.', 404) confirm_hash = args['confirm'] if confirm_hash: if service.confirm_email(user, confirm_hash): logger.info('User %s confirmed their email %s', user.id, user.email) login_user(user) if args['source']: return redirect(args['source']) else: return redirect('/') else: logger.warn('User with email %s tried to confirm their ' 'email with wrong hash (expected %s - got %s)', user.email, user.confirmation_hash, confirm_hash) return make_response('The confirmation email link is wrong! ' 'The email cannot be confirmed.', 400) user_updated = service.update_user(args, user) if user_updated: return make_response('User has been updated', 201) else: return make_response('No request parameters specified!', 400)
def post(self, user_id): """ Updates user information. :param user_id :return: Flask response """ self.request_parser.add_argument('confirm', type=str, required=False) self.request_parser.add_argument('source', type=str, required=False) self.request_parser.add_argument('name', type=unicode, required=False) self.request_parser.add_argument('last_name', type=unicode, required=False) self.request_parser.add_argument('profession', type=unicode, required=False) self.request_parser.add_argument('birthday', type=str, required=False) args = self.request_parser.parse_args() user = service.get_user_by_id(user_id) if not user: return make_response( 'User with id ' + str(user_id) + ' does not exist.', 404) confirm_hash = args['confirm'] if confirm_hash: if service.confirm_email(user, confirm_hash): logger.info('User %s confirmed their email %s', user.id, user.email) login_user(user) if args['source']: return redirect(args['source']) else: return redirect('/') else: logger.warn( 'User with email %s tried to confirm their ' 'email with wrong hash (expected %s - got %s)', user.email, user.confirmation_hash, confirm_hash) return make_response( 'The confirmation email link is wrong! ' 'The email cannot be confirmed.', 400) user_updated = service.update_user(args, user) if user_updated: return make_response('User has been updated', 201) else: return make_response('No request parameters specified!', 400)