def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False db.init_app(app) with app.app_context(): db.create_all() example_user = User(id=1, email="*****@*****.**", username="******") example_user.set_password("111") db.session.merge(example_user) db.session.commit() self.app = app.test_client()
def register(): """ User registration A GET request will redirect to the register view. A POST request will check that the user is not currently logged in, afterwards it will create a new user based on provided data and redirect to homepage. """ if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('pages.login')) return render_template('pages/register.html', title='Register', form=form)