Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 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
Ejemplo n.º 4
0
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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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']
Ejemplo n.º 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']