Пример #1
0
def test_2(request):
    """
    Test type 2: Single database query
    """
    num = randint(1, 10000)
    result = DBSession.query(World).filter(World.id == num).one()
    return result.__json__()
Пример #2
0
def test_2(request):
    """
    Test type 2: Single database query
    """
    num = randint(1, 10001)
    result = DBSession.query(World).filter(World.id == num).one()
    return result
Пример #3
0
def test_4(request):
    """
    Test type 4: Fortunes
    """
    fortunes = [obj.__json__() for obj in DBSession.query(Fortune).all()]
    fortunes.append(
        {"id": 0, "message": "Additional fortune added at request time."}
    )
    return {'fortunes': sorted(fortunes, key=lambda x: x['message'])}
Пример #4
0
def test_4(request):
    """
    Test type 4: Fortunes
    """
    fortunes = [obj.__json__() for obj in DBSession.query(Fortune).all()]
    fortunes.append({
        "id": 0,
        "message": "Additional fortune added at request time."
    })
    return {"fortunes": sorted(fortunes, key=lambda x: x["message"])}
Пример #5
0
def test_5(request):
    """
    Test type 5: Database updates
    """
    queries = request.GET.get('queries', 1)
    try:
        queries = int(queries)
    except ValueError:
        queries = 1
    else:
        if queries < 1:
            queries = 1
        elif queries > 500:
            queries = 500
    baked_query = bakery(lambda session: session.query(World))
    resultset = []
    for num in sorted(randint(1, 10000) for _ in xrange(queries)):
        obj = baked_query(DBSession).get(num)
        obj.randomNumber = randint(1, 10000)
        resultset.append(obj.__json__())
    DBSession.commit()
    return resultset
Пример #6
0
def test_5(request):
    """
    Test type 5: Database updates
    """
    queries = request.params["queries"]
    try:
        queries = int(queries)
    except ValueError:
        queries = 1
    else:
        if queries < 1:
            queries = 1
        elif queries > 500:
            queries = 500
    objset = [
        DBSession.query(World).filter(World.id == num).one()
        for num in [randint(1, 10000) for _ in range(1, queries + 1)]
    ]
    for obj in objset:
        obj.randomNumber = randint(1, 10000)
    resultset = [obj.__json__() for obj in objset]
    DBSession.commit()
    return resultset
Пример #7
0
def test_5(request):
    """
    Test type 5: Database updates
    """
    queries = request.params['queries']
    try:
        queries = int(queries)
    except ValueError:
        queries = 1
    else:
        if queries < 1:
            queries = 1
        elif queries > 500:
            queries = 500
    objset = [
        DBSession.query(World).filter(World.id == num).one()
        for num in [randint(1, 10001) for _ in range(1, queries + 1)]
    ]
    for obj in objset:
        obj.randomNumber = randint(1, 10001)
    resultset = [obj.__json__() for obj in objset]
    DBSession.commit()
    return resultset
Пример #8
0
def test_3(request):
    """
    Test type 3: Multiple database queries
    """
    queries = request.params["queries"]
    try:
        queries = int(queries)
    except ValueError:
        queries = 1
    else:
        if queries < 1:
            queries = 1
        elif queries > 500:
            queries = 500
    result = [
        DBSession.query(World).filter(World.id == num).one()
        for num in [randint(1, 10000) for _ in range(1, queries + 1)]
    ]
    return [obj.__json__() for obj in result]
Пример #9
0
def test_3(request):
    """
    Test type 3: Multiple database queries
    """
    queries = request.params['queries']
    try:
        queries = int(queries)
    except ValueError:
        queries = 1
    else:
        if queries < 1:
            queries = 1
        elif queries > 500:
            queries = 500
    result = [
        DBSession.query(World).filter(World.id == num).one()
        for num in [randint(1, 10001) for _ in range(1, queries + 1)]
    ]
    return result
Пример #10
0
import codecs
import os
from frameworkbenchmarks.models import DBSession

FWROOT = os.environ.get("FWROOT", "../../..")

if __name__ == "__main__":
    """
    Initialize database
    """
    with codecs.open("%s/config/create-postgres.sql" % FWROOT,
                     "r",
                     encoding="utf-8") as fp:
        sql = fp.read()
    DBSession.execute(sql)
    DBSession.commit()
Пример #11
0
import codecs
import os
from frameworkbenchmarks.models import DBSession

FWROOT = os.environ.get('FWROOT', '../../..')

if __name__ == "__main__":
    """
    Initialize database
    """
    with codecs.open('%s/config/create-postgres.sql' % FWROOT,
                     'r',
                     encoding='utf-8') as fp:
        sql = fp.read()
    DBSession.execute(sql)
    DBSession.commit()