

#Test all of the Oracle interfaces

import os, sys
sys.path.append('../')

import TestAdapter

import DCOracle

DBNAME=os.environ.get("ODS_TEST_DB","ods:test")

from Ft.Ods.StorageManager.Adapters.Oracle import Manager
from Ft.Ods.StorageManager.Adapters.Oracle import Adapter
from Ft.Ods.StorageManager.Adapters import Util



class Validator:

    def validateCreate(self,dbName):
        return 1
        dbName,hostName,port,userName,passwd = Util.SplitDbConnectString(dbName)
        pg_db_name = "ftods__" + dbName
        tmpl_db = PgDatabase.Database('template1',hostName,port,userName,passwd)
        rt = tmpl_db.query("SELECT datname FROM pg_database where datname='%s'" % pg_db_name)
        return len(rt) != 0
        
    def validateDestroy(self,dbName):
        return 1
        dbName,hostName,port,userName,passwd = Util.SplitDbConnectString(dbName)
        pg_db_name = "ftods__" + dbName
        tmpl_db = PgDatabase.Database('template1',hostName,port,userName,passwd)
        rt = tmpl_db.query("SELECT datname FROM pg_database where datname='%s'" % pg_db_name)
        return len(rt) == 0
        

    def getTableInfo(self,dbName):
        return 1
        dbName,hostName,port,userName,passwd = Util.SplitDbConnectString(dbName)
        db = PgDatabase.Database('ftods__%s'%dbName,hostName,port,userName,passwd)
        tables = db.db.get_tables()

        ts = {}
        for t in tables:
            attrs = db.db.get_attnames(t)
            ts[t] = attrs.keys()

        del db
        return ts


def test():

    #Test the management interfaces
    mang = Manager.DbManager()
    ad = Adapter.DbAdapter()

    #TestAdapter.test_management(mang,Validator())
    #TestAdapter.test_python_classes(mang,ad,Validator())
    #TestAdapter.test_basic_repos(mang,ad,Validator())
    #TestAdapter.test_extents(mang,ad,Validator())
    #TestAdapter.test_bindings(mang,ad,Validator())
    #TestAdapter.test_collections(mang,ad,Validator())
    #TestAdapter.test_full_management(mang,ad,Validator()) 
    TestAdapter.test_blobs(mang,ad,Validator()) 
   
    




if __name__ == '__main__':
    test()
