def test_new_post(dbtransaction, authenticated_app):
    """Test that a new post is created."""
    db_rows = DBSession.query(Entry).filter(
        Entry.title == 'Testing' and Entry.text == 'Testing')
    assert db_rows.count() == 0
    params = {
        'title': 'Testing',
        'text': 'Testing'
    }
    authenticated_app.post('/new', params=params, status='3*')
    db_rows = DBSession.query(Entry).filter(
        Entry.title == 'Testing' and Entry.text == 'Testing')
    assert db_rows.count() == 1
def test_edit_entry(dbtransaction, authenticated_app, new_model):
    """Test that a post can be edited."""
    params = {
        'title': 'T' + new_model.title,
        'text': 'T' + new_model.text
    }
    authenticated_app.post('/edit/{}'.format(new_model.id),
                           params=params, status='3*')
    db_rows = DBSession.query(Entry).filter(
        Entry.title == 'T' + new_model.title and Entry.text == 'T' + new_model.text)
    assert db_rows.count() == 1
def test_new_post_minimum_text_length(dbtransaction, app):
    """Test a new post can't be created without min characters in text."""
    db_rows = DBSession.query(Entry).filter(
        Entry.title == 'Testing2' and Entry.text == 'Test')
    assert db_rows.count() == 0
    params = {
        'title': 'Testing2',
        'text': 'Test'
    }
    with pytest.raises(AppError):
        app.post('/new', params=params, status='3*')
def test_new_post_over_max_title_length(dbtransaction, app):
    """Test that a new post adheres to max title length."""
    mock_title = []
    for i in range(130):
        mock_title.append('a')
    mock_title = "".join(mock_title)
    db_rows = DBSession.query(Entry).filter(
        Entry.title == mock_title and Entry.text == 'Testing')
    assert db_rows.count() == 0
    params = {
        'title': mock_title,
        'text': 'Testing'
    }
    with pytest.raises(AppError):
        app.post('/new', params=params, status='3*')