コード例 #1
0
ファイル: conftest.py プロジェクト: gvasold/papilotte
def data1():
    "Return the first mockdata factoid as dict."
    data = {'factoids': []}
    for i, factoid in enumerate(mockdata.make_factoids(1)):
        if i == 1:
            break
        data['factoids'].append(factoid)
    return data
コード例 #2
0
ファイル: conftest.py プロジェクト: gvasold/papilotte
def data200():
    "Return 200 mockdata factoids as dict"
    data = {'factoids': []}
    for i, factoid in enumerate(mockdata.make_factoids(1)):
        if i == 200:
            break
        data['factoids'].append(factoid)
    return data
コード例 #3
0
def db20_file():
    """Generate a pre-populated database with 20 factoids.
    This database can be used to test modifying access to objects.

    The database lives in a temporary directory.
    Return the path to the sqlite dabase file.
    """
    with tempfile.TemporaryDirectory() as tmp_path:
        dbfile = os.path.join(tmp_path, 'test.db')
        db = database.make_db(provider='sqlite', filename=dbfile)
        Factoid = db.entities['Factoid']
        with orm.db_session:
            for factoid in mockdata.make_factoids(20):
                Factoid.create_from_ipif(factoid)
        yield dbfile
コード例 #4
0
ファイル: conftest.py プロジェクト: gvasold/papilotte
def db200final():
    """Provides a on-disk database with 200 factoids.

    This database MUST NOT be modified during tests!
    """
    with tempfile.TemporaryDirectory() as tmp_path:
        dbfile = os.path.join(tmp_path, 'test.db')
        db = database.make_db(provider='sqlite', filename=dbfile)
        Factoid = db.entities['Factoid']
        with orm.db_session:
            for factoid in mockdata.make_factoids(200):
                Factoid.create_from_ipif(factoid)
            db.commit()
            conn = db.get_connection()
            conn.execute("PRAGMA query_only = ON")
        yield db
コード例 #5
0
def db200_static_file():
    """Generate a pre-populated read only database with 200 factoids.

    The database lives in a temporary directory.
    Return the path to the sqlite dabase file.
    """
    with tempfile.TemporaryDirectory() as tmp_path:
        dbfile = os.path.join(tmp_path, 'test.db')
        db = database.make_db(provider='sqlite', filename=dbfile)
        Factoid = db.entities['Factoid']
        with orm.db_session:
            for factoid in mockdata.make_factoids(200):
                Factoid.create_from_ipif(factoid)
            db.commit()
            conn = db.get_connection()
            conn.execute("PRAGMA query_only = ON")
        yield dbfile
コード例 #6
0
def factoid1():
    "Return factoid with id F00001 from test data as dict."
    for factoid in mockdata.make_factoids(200):
        if factoid['@id'] == 'F00001':
            return factoid
コード例 #7
0
def statement1():
    "Return statement with id Stmt00001 from test data as dict"
    for factoid in mockdata.make_factoids(200):
        for stmt in factoid['statements']:
            if stmt["@id"] == "Stmt00001":
                return stmt
コード例 #8
0
def source1():
    "Return source with id 'S00001' from test data as dict"
    for factoid in mockdata.make_factoids(200):
        if factoid["source"]["@id"] == "S00001":
            return factoid['source']
コード例 #9
0
def person1():
    "Return person with id 'P00001' from test data as dict"
    for factoid in mockdata.make_factoids(200):
        if factoid["person"]["@id"] == "P00001":
            return factoid['person']