Пример #1
0
def test_add(authenticated_app):
    results = DBSession.query(Entry).filter(
        Entry.title == 'title' and Entry.text == 'text')
    assert results.count() == 0
    entry_dict = {'title': 'title', 'text': 'text'}
    authenticated_app.post('/write', params=entry_dict, status='3*')
    results = DBSession.query(Entry).filter(
        Entry.title == 'title' and Entry.text == 'text')
    assert results.count() == 1
Пример #2
0
def test_delete_entry(loaded_db_item, authorized_app):
    from learning_journal.models import Entry, DBSession
    check_db = DBSession.query(Entry).filter(
                Entry.title == 'jill').first()
    assert check_db
    authorized_app.get('/delete_entry/{}'.format(loaded_db_item.id))
    check_db = DBSession.query(Entry).filter(
                Entry.title == 'jill').first()
    assert not check_db
Пример #3
0
def test_edit_entry_view_functional(loaded_db_item, authenticated_app):
    """Test if the db updates upon request."""
    from learning_journal.models import Entry, DBSession
    authenticated_app.post('/edit_entry/{}'.format(loaded_db_item.id),
             {'title': 'new title', 'text': 'new text'})
    new = DBSession.query(Entry).filter(Entry.id == loaded_db_item.id).first()
    assert new.title == 'new title'
    assert new.text == 'new text'
Пример #4
0
def test_add_entry_view_functional(authenticated_app):
    """Test if the db updates upon request."""
    from learning_journal.models import Entry, DBSession
    authenticated_app.post('/add_entry', {'title': 'fancy title', 'text': 'new text'})
    new_entry = DBSession.query(Entry).filter(
                Entry.title == 'fancy title').first()
    assert new_entry.id
    assert new_entry.title == 'fancy title'
    assert new_entry.text == 'new text'
Пример #5
0
def test_edit_entry_view_functional(loaded_db_item, authenticated_app):
    """Test if the db updates upon request."""
    from learning_journal.models import Entry, DBSession
    authenticated_app.post('/edit_entry/{}'.format(loaded_db_item.id), {
        'title': 'new title',
        'text': 'new text'
    })
    new = DBSession.query(Entry).filter(Entry.id == loaded_db_item.id).first()
    assert new.title == 'new title'
    assert new.text == 'new text'
Пример #6
0
def edit_post(request):
    entry_id = request.matchdict['id']
    entry = DBSession.query(Entry).get(entry_id)
    form = EntryForm(request.POST, entry)
    if request.method == 'POST' and form.validate():
        form.populate_obj(entry)
        DBSession.add(entry)
        DBSession.flush()
        url = request.route_url('entry', id=entry_id)
        return HTTPFound(url)
    return {'form': form}
Пример #7
0
def test_add_entry_view_functional(authenticated_app):
    """Test if the db updates upon request."""
    from learning_journal.models import Entry, DBSession
    authenticated_app.post('/add_entry', {
        'title': 'fancy title',
        'text': 'new text'
    })
    new_entry = DBSession.query(Entry).filter(
        Entry.title == 'fancy title').first()
    assert new_entry.id
    assert new_entry.title == 'fancy title'
    assert new_entry.text == 'new text'
Пример #8
0
def test_edit(dbtransaction, app, new_entry, auth_env):
    """Test that an entry was created by a person whose logged in."""
    title = new_entry.title
    text = new_entry.text
    entry_dict = {'title': title,
                  'text': text,
                  'username': '******',
                  'password': '******'
                  }
    app.post('/{}/edit'.format(new_entry.id), params=entry_dict, status='3*')
    results = DBSession.query(Entry).filter(
        Entry.title == title and Entry.text == text)

    assert results.count() == 1
Пример #9
0
 def teardown():
     DBSession.query(Entry).filter(Entry.id == new_entry.id).delete()
     DBSession.flush()
Пример #10
0
def view_post(request):
    entry_id = '{id}'.format(**request.matchdict)
    entry = DBSession.query(Entry).get(entry_id)
    return {'entry': entry}
Пример #11
0
def post_index(request):
    entries = DBSession.query(Entry).all()
    return {'entries': entries}