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
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
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
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
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
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
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
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']
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']