コード例 #1
0
ファイル: conftest.py プロジェクト: jerin/smart-steel-task
def protect_db():  # used to have the 'db' fixture as a param
    """
    Creates a new database session for a test. Note you must use this fixture
    if your test connects to db.
    Here we not only support commit calls but also rollback calls in tests,
    :coolguy:.
    """
    connection = engine.connect()
    transaction = connection.begin()

    db_session.begin_nested()

    # session is actually a scoped_session
    # for the `after_transaction_end` event, we need a session instance to
    # listen for, hence the `session()` call
    @event.listens_for(db_session(), 'after_transaction_end')
    def restart_savepoint(sess, trans):
        if trans.nested and not trans._parent.nested:
            db_session.expire_all()
            db_session.begin_nested()

    yield db_session

    db_session.remove()
    transaction.rollback()
    connection.close()
コード例 #2
0
def add_location():
    content = request.get_json()
    r = Restaurant(content['id'], content['title'], content['coords']['latitude'], content['coords']['longitude'], content['google_ratings'], content['types'])
    db_session.add(r)
    db_session.commit()
    db_session.remove()
    return 'success'
コード例 #3
0
ファイル: app.py プロジェクト: Rhaall/sparetime-backend
def shutdown_session(exception=None):
    db_session.remove()
コード例 #4
0
    '''
    print ("Title: " + title)
    print ("Date: " + str(datetime_obj))
    print ("Content: " + markdown_content)
    '''

    new_post = Post(title = title, content = markdown_content, date = datetime_obj)
    return new_post

# Delete current
db_session.query(Post).delete()

# Seeding code

# TODO grab all the posts
posts = get_formatted_posts()

# TODO Iterate through each and push it to the database
for post in posts:
    parsed_post = parse_post(post)
    db_session.add(parsed_post)

# Commit to db
db_session.commit()

# Show new Posts
Post.query.all()

# End db code
db_session.remove()
コード例 #5
0
def shutdown_session(exception=None):
    db_session.remove()