def testCreateTable(self):
     connection,cursor = self.connection_tuple
     tablename='test'
     tablestring = ('CREATE TABLE {name} '
         '(id text PRIMARY KEY, '
         'year integer, '
         'data jsonb);'
         .format(name=tablename)
         )
     setup_db.create_table(connection,cursor,tablename,tablestring)
     assert setup_db.table_exists(cursor, tablename) == True
 def testDeleteTable(self):
     connection,cursor = self.connection_tuple
     tablename='test'
     assert setup_db.table_exists(cursor, tablename) == True
     setup_db.delete_table(connection,cursor,tablename)
     assert setup_db.table_exists(cursor, tablename) == False
    args = parser.parse_args()

    # read config variables
    config_obj = setup_db.read_config(args.configfile)
    connection, cursor = setup_db.connect(config_obj)

    # test that tables exist
    # and clear data, except taxonomy table
    try:
        tabledict = dict(config_obj.items('database_tables'))
        for table in tabledict:
            # skip the taxonomy table, which does note get loaded here
            if table == "otttable":
                continue
            name = tabledict[table]
            if setup_db.table_exists(cursor,name):
                setup_db.clear_single_table(connection,cursor,name)
            else:
                raise psy.ProgrammingError("Table {t} does not exist".format(t=name))
        setup_db.clear_gin_index(connection,cursor)
        print "done clearing tables and index"
    except psy.Error as e:
        print e.pgerror

    # data import
    starttime = dt.datetime.now()
    try:
        # TODO: catch peyotl-specific exceptions
        phy = create_phylesystem_obj()
        print "loading nexsons"
        if (args.nstudies):