コード例 #1
0
def create_book(name="Sherlock Homes",
                description="a house hunting real estate agent"):
    book = Product(name="Sherlock Homes",
                   description="a house hunting detective",
                   price_cents=500)
    db.session.add(book)
    db.session.commit()
    return book
コード例 #2
0
def test_product_creation(client, init_database, authenticated_request):
    assert Product.query.count() == 0
    book = Product(name='Sherlock Homes',
                   description='A house hunting detective')
    db.session.add(book)
    db.session.commit()
    assert Product.query.count() == 1
    assert Product.query.first().name == book.name
コード例 #3
0
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
コード例 #4
0
def create_store(name="Example Store", num_products=0):
    store = Store(name=name)
    for index in range(num_products):
        product = Product(name="Product {}".format(index),
                          description="example",
                          store=store)
        db.session.add(product)
    db.session.add(store)
    db.session.commit()
    return store
コード例 #5
0
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
コード例 #6
0
ファイル: seed.py プロジェクト: frivolta/flask-rest-yumroad
def setup():
    with app.app_context():
        db.create_all()
        user = User.create("*****@*****.**", "test")
        db.session.add(user)
        store = Store(name="The newline store", user=user)
        for i in range(2):
            prod = Product(name='Fullstack Book v{}'.format((1+i)),
                           description='Book #{} in the series'.format(i+1),
                           price_cents=100*(i+1),
                           store=store)
            db.session.add(prod)
        db.session.commit()
コード例 #7
0
def create():
    form = ProductForm()
    if form.validate_on_submit():
        price = form.price.data or 0
        product = Product(name=form.name.data,
                          description=form.description.data,
                          price_cents=int(price * 100),
                          picture_url=form.picture_url.data,
                          creator=current_user,
                          store=current_user.store)
        db.session.add(product)
        db.session.commit()
        return redirect(url_for('product.details', product_id=product.id))
    return render_template('products/new.html', form=form)
コード例 #8
0
def test_name_validation(client, init_database):
    assert Product.query.count() == 0
    with pytest.raises(ValueError):
        Product(name="bad", description="should be an invalid name")
    assert Product.query.count() == 0
コード例 #9
0
def test_name_validation(client, init_database):
    with pytest.raises(ValueError):
        Product(name='    a', description='invalid book')