Exemplo n.º 1
0
def test_list(app, firestore):
    for i in range(1, 12):
        firestore.create({'title': u'Image {0}'.format(i)})

    with app.test_client() as c:
        rv = c.get('/')

    assert rv.status == '200 OK'

    body = rv.data.decode('utf-8')
    assert 'Image 1' in body, "Should show images"
    assert len(re.findall('<h4>Image',
                          body)) <= 10, ("Should not show more than 10 images")
    assert 'More' in body, "Should have more than one page"
Exemplo n.º 2
0
def test_delete(app, firestore):
    existing = firestore.create({'title': "Temp Title"})

    with app.test_client() as c:
        rv = c.get('images/%s/delete' % existing['id'], follow_redirects=True)

    assert rv.status == '200 OK'
    assert not firestore.read(existing['id'])
Exemplo n.º 3
0
def test_edit(app, firestore):
    existing = firestore.create({'title': "Temp Title"})

    with app.test_client() as c:
        rv = c.post('images/%s/edit' % existing['id'],
                    data={'title': 'Updated Title'},
                    follow_redirects=True)

    assert rv.status == '200 OK'
    body = rv.data.decode('utf-8')
    assert 'Updated Title' in body
    assert 'Temp Title' not in body
Exemplo n.º 4
0
def add_item():
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)
        data["price"] = float(data.get("price", 100000))
        data["quantity"] = int(data.get("quantity", 0))
        # If an image was uploaded, update the data to point to the
        image_urls = storage.upload_image_files(request.files.getlist('images'))
        if image_urls:
            data['images'] = image_urls
        item = firestore.create(data)
        return redirect(url_for('.item_detail', item_id=item['id']))

    return render_template("item_entry_form.html", action='Add', item={})
Exemplo n.º 5
0
def add():
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)

        # If an image was uploaded, update the data to point to the new image.
        image_url = upload_image_file(request.files.get('image'))

        if image_url:
            data['imageUrl'] = image_url

        book = firestore.create(data)

        return redirect(url_for('.view', book_id=book['id']))

    return render_template('form.html', action='Add', book={})
Exemplo n.º 6
0
def add():
    """Add a new book to the firestore database

    Return user to the view page for the new book"""
    form = BookForm()

    if form.validate_on_submit():
        data = form.data

        # Processs image if there is one
        # COME BACK

        book = firestore.create(data)
        return redirect(url_for('app.view', book_id=book['id']))

    return render_template('book_form.html', form=form, header="Add Book")
Exemplo n.º 7
0
def add():
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)

        # If an image was uploaded, update the data to point to the new image.
        image_url = upload_image_file(request.files.get('image'))

        if image_url:
            data['imageUrl'] = image_url

        string = request.form.get('genre')
        string_list = string.split(',')

        movies = firestore.create(data, data['title'])
        firestore.update_array(string_list, data['title'])

        return redirect(url_for('.view', movies_id=movies['id']))

    return render_template('form.html', action='Add', movies={})
Exemplo n.º 8
0
def add():
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)
        entry = firestore.create(data)
        return redirect(url_for('.view', entry_id=entry['id']))
    return render_template('form.html', action='Add', entry={})