def register(): """Register new user.""" form = RegisterForm(request.form, csrf_enabled=False) if form.validate_on_submit(): User.create(username=form.username.data, email=form.email.data, password=form.password.data, active=True) flash('Thank you for registering. You can now log in.', 'success') return redirect(url_for('public.home')) else: flash_errors(form) return render_template('public/register.html', form=form)
def test_check_password(self): """Check password.""" user = User.create(username='******', email='*****@*****.**', password='******') assert user.check_password('foobarbaz123') is True assert user.check_password('barfoobaz') is False
def post(self): create_user_parse = reqparse.RequestParser() create_user_parse.add_argument('username', dest='username', required=True, help="Username of user to be created") create_user_parse.add_argument('password', dest='password', required=True, help="Password of user to be created") create_user_parse.add_argument('password_confirm', dest='password_confirm', required=True, help="Password confirmation of user to be created") create_user_parse.add_argument('email', dest='email', required=True, help="Email address of user to be created") args = create_user_parse.parse_args() user = User.query.filter(User.username == args.username).first() emailuser = User.query.filter(User.email == args.email).first() if user: return {"message": "username already exists"}, 400 elif emailuser: return {"message": "email already registered"}, 400 elif args.password != args.password_confirm: return {"message": "passwords do not match"}, 400 elif len(args.password) < 6 or len(args.password) > 128: return {"message": "invalid password length"}, 400 elif not args.username or len(args.username) > 80: return {"message": "invalid username length"}, 400 else: valid_user = User.create(username=args.username, password=args.password, email=args.email, active=True) return {'access_token': valid_user.generate_auth_token()}, 201
def test_user_token_auth(self): user = User.create(username='******', email='*****@*****.**', password='******') auth_token = user.generate_auth_token() invalid_token = "" assert User.verify_auth_token(invalid_token) is None assert User.verify_auth_token(auth_token) is user
def test_recommend_returns_closest(self): user = User.create(username='******', email='*****@*****.**', password='******'tcare') beer = Beer.create(beer_name='testbeer', abv=2.3, bitter=2.3, color=4, fruit=3, hoppy=4, malty=3, roasty=2, smoke=1, sour=3, spice=4.5, family=1, sweet=2, wood=3) beer1 = Beer.create(beer_name='testbeer1', abv=5.3, bitter=6, color=3, fruit=7, hoppy=8, malty=3, roasty=2, smoke=1, sour=3, spice=4.5, family=1, sweet=2, wood=3) user.update_taste_profile(malty=0, bitter=7, fruit=6.5, hoppy=7, wood=2, sweet=3, spice=1.4, sour=3.4, smoke=4, roasty=3) assert user.reccommend() is beer1 assert user.reccommend() is not beer
def test_recommend_returns(self): user = User.create(username='******', email='*****@*****.**', password='******'tcare') beer = Beer.create(beer_name='testbeer', abv=2.3, bitter=2.3, color=4, fruit=5, hoppy=4, malty=3, roasty=2, smoke=1, sour=3, spice=4.5, family=1, sweet=2, wood=3) beer_rec = user.reccommend() assert beer_rec == beer
def test_rating_beer(self): user = User.create(username='******', email='*****@*****.**', password='******'tcare') beer = Beer.create(beer_name='testbeer', abv=2.3, bitter=2.3, color=4, fruit=3, hoppy=4, malty=3, roasty=2, smoke=1, sour=3, spice=4.5, family=1, sweet=2, wood=3) Rating.create(user_id=user.id, beer_id=beer.id, rating=4) assert [x for x in user.ratings] is not [] assert [x for x in user.ratings][0].rating is 4