def test_add_post(): configure_engine(config) session = create_db_session() recreate_db() ed_user = User(name='ed', fullname='Ed Jones', password='******') session.add(ed_user) session.commit() ed_post = Post( title='My title', content='Post content hehehe', user_id=ed_user.id) session.add(ed_post) session.commit() selected_user = session.query(User).filter_by(name='ed').one() assert selected_user.name == 'ed' assert selected_user.fullname == 'Ed Jones' assert selected_user.password == 'edspassword' selected_post = ( session.query(Post).filter_by(user_id=selected_user.id).one()) assert selected_post.title == 'My title' assert selected_post.content == 'Post content hehehe' assert selected_post.user_id == selected_user.id
def test_add_user(): configure_engine(config) session = create_db_session() recreate_db() ed_user = User(name='ed', fullname='Ed Jones', password='******') session.add(ed_user) session.commit() our_user = session.query(User).filter_by(name='ed').one() assert our_user.name == 'ed' assert our_user.fullname == 'Ed Jones' assert our_user.password == 'edspassword'
from pyramid.view import view_config from navgar_core import database as db import redis session = db.create_db_session() @view_config(route_name='home', renderer='templates/home.pt') def main_page(request): return {} @view_config(route_name='posts/most_popular', renderer='json') def get_most_popular_posts(request): most_popular_posts = [ { 'author': 'Adam', 'content': 'Lorem Ipsum' }, { 'author': 'Marcin', 'content': 'Pecunia non olet' } ] # Andrzej FIXME: I can't be hardcoded :) return most_popular_posts @view_config(route_name='users/most_popular', renderer='json') def get_most_popular_users(request): most_popular_users = [