def create_user(email=EXAMPLE_EMAIL, password=EXAMPLE_PASSWORD): user = User.create(email, password) # store = Store(name=STORE_NAME, user=user) # db.session.add(store) db.session.add(user) db.session.commit() return user
def user_with_product(): new_user = User.create("*****@*****.**", "pass") store = Store(name="Test Store", user=new_user) product = Product(name='Test Product', description='a product', store=store) db.session.add(product) db.session.commit() yield new_user
def sample_book(): new_user = User.create('*****@*****.**', 'examplepass') db.session.add(new_user) store = Store(name='Store Name', user=new_user) # db.session.add(store) book = Product(name="Sherlock Homes", store=store, description="A house hunting detective") db.session.add(book) db.session.commit() return book
def authenticated_request(client): new_user = User.create('*****@*****.**', 'examplepass') store = Store(name="Test Store", user=new_user) db.session.add(new_user) db.session.commit() response = client.post(url_for('user.login'), data={ 'email': '*****@*****.**', 'password': '******' }, follow_redirects=True) yield client
def register(): if current_user.is_authenticated: flash('You are already logged in', 'warning') return redirect(url_for('products.index')) form = SignupForm() if form.validate_on_submit(): # create a user user = User.create(form.email.data, form.password.data) db.session.add(user) store = Store(name=form.store_name.data, user=user) # may need another db.session.add(store) db.session.commit() login_user(user) send_welcome_message(user) flash("Registered successfully", "success") return redirect(url_for('products.index')) return render_template('users/register.html', form=form)