def test(): import journal # journal.debug("postgres.init").active = True # journal.debug("postgres.execute").active = True # journal.debug("postgres.connection").active = True journal.debug("postgres.transactions").active = True # this is the SQL statement that looks for a table by a given name sql = "SELECT tablename FROM pg_tables WHERE tablename='{}'".format(Weather.pyre_name) # build a database component and connect to the database specified in the local # configuration file db = pyre.db.postgres(name="test").attach() # in a transaction block with db: # create the table db.createTable(Weather) # verify it is there assert db.execute(sql) == (('tablename',), ('weather',)) # drop the table db.dropTable(Weather) # verify it is not there assert db.execute(sql) == (('tablename',),) # and return the connection and the table return db, Weather
def test(): import journal # journal.debug("postgres.init").active = True # journal.debug("postgres.execute").active = True # journal.debug("postgres.connection").active = True journal.debug("postgres.transactions").active = True # this is the SQL statement that looks for a table by a given name sql = "SELECT tablename FROM pg_tables WHERE tablename='{}'".format( Weather.pyre_name) # build a database component and connect to the database specified in the local # configuration file db = pyre.db.postgres(name="test").attach() # in a transaction block with db: # create the table db.createTable(Weather) # verify it is there assert db.execute(sql) == (('tablename', ), ('weather', )) # drop the table db.dropTable(Weather) # verify it is not there assert db.execute(sql) == (('tablename', ), ) # and return the connection and the table return db, Weather
def test(): # build a database component and connect to the database specified in the local # configuration file db = pyre.db.sqlite(name="test").attach() # in a transaction block with db: # create the location table db.createTable(Location) # create the weather table db.createTable(Weather) # drop the weather table db.dropTable(Weather) # drop the location table db.dropTable(Location) # and return the connection and the tables return db, Weather, Location
def test(): # this is the SQL statement that looks for a table by a given name sql = "SELECT * FROM weather" # build a database component and connect to the database specified in the local # configuration file db = pyre.db.sqlite(name="test").attach() # in a transaction block with db: # create the table db.createTable(Weather) # verify it is there assert tuple(db.execute(sql)) == () # drop the table db.dropTable(Weather) # and return the connection and the table return db, Weather
def test(): import journal # journal.debug("postgres.init").active = True # journal.debug("postgres.execute").active = True # journal.debug("postgres.connection").active = True journal.debug("postgres.transactions").active = True # build a database component and connect to the database specified in the local # configuration file db = pyre.db.postgres(name="test").attach() # ask {libpq} to be quiet db.execute("SET client_min_messages = warning;") # in a transaction block with db: # create the location table db.createTable(Location) # verify it is there assert queryForTable(db, Location) == (('tablename', ), (Location.pyre_name, )) # create the weather table # print('\n'.join(db.sql.createTable(Weather))) db.createTable(Weather) # verify it is there assert queryForTable(db, Weather) == (('tablename', ), (Weather.pyre_name, )) # drop the weather table db.dropTable(Weather) # and check it's gone assert queryForTable(db, Weather) == (('tablename', ), ) # drop the location table # print('\n'.join(db.sql.createTable(Location))) db.dropTable(Location) # and check it's gone too assert queryForTable(db, Location) == (('tablename', ), ) # and return the connection and the tables return db, Weather, Location
def test(): import journal # journal.debug("postgres.init").active = True # journal.debug("postgres.execute").active = True # journal.debug("postgres.connection").active = True journal.debug("postgres.transactions").active = True # build a database component and connect to the database specified in the local # configuration file db = pyre.db.postgres(name="test").attach() # ask {libpq} to be quiet db.execute("SET client_min_messages = warning;") # in a transaction block with db: # create the location table db.createTable(Location) # verify it is there assert queryForTable(db, Location) == (('tablename',), (Location.pyre_name,)) # create the weather table # print('\n'.join(db.sql.createTable(Weather))) db.createTable(Weather) # verify it is there assert queryForTable(db, Weather) == (('tablename',), (Weather.pyre_name,)) # drop the weather table db.dropTable(Weather) # and check it's gone assert queryForTable(db, Weather) == (('tablename',),) # drop the location table # print('\n'.join(db.sql.createTable(Location))) db.dropTable(Location) # and check it's gone too assert queryForTable(db, Location) == (('tablename',),) # and return the connection and the tables return db, Weather, Location
def test(): # connect to the test database db = pyre.db.postgres(name="test").attach() # order class invalid(pyre.db.table): order = pyre.db.str() try: db.createTable(invalid) assert False except db.exceptions.ProgrammingError: pass # where class invalid(pyre.db.table): where = pyre.db.str() try: db.createTable(invalid) assert False except db.exceptions.ProgrammingError: pass # group class invalid(pyre.db.table): group = pyre.db.str() try: db.createTable(invalid) assert False except db.exceptions.ProgrammingError: pass # and return the connection return db