コード例 #1
0
    def setUp(self):
        ccdb_path = get_ccdb_home_path()

        self.sqlite_connection_str = "sqlite:///" + os.path.join(
            ccdb_path, "sql", "ccdb.sqlite")
        self.mysql_connection_str = "mysql://[email protected]:3306/ccdb"

        #initialize but disable colorama
        ccdb.cmd.colorama.init(autoreset=True)
        ccdb.cmd.colorama.deinit()

        #create console context
        self.context = ConsoleContext()
        self.context.silent_exceptions = False
        self.context.theme = ccdb.cmd.themes.NoColorTheme()
        self.context.connection_string = self.sqlite_connection_str
        self.context.user_name = "python_tests"
        self.context.register_utilities()

        #save stdout
        self.output = StringIO()
        self.saved_stdout = sys.stdout
        sys.stdout = self.output

        #logger
        ch = logging.StreamHandler()
        ch.stream = self.output
        logger.addHandler(ch)
        logger.setLevel(logging.INFO)
コード例 #2
0
    def setUp(self):
        # We need only sqlite tests. We test that we work with all databases in the provider fixture
        self.sqlite_connection_str = helper.sqlite_test_connection_str

        # DON'T USE COLORAMA IN TESTS. PyCharm test runner FAILS BECAUSE OF IT
        # DON'T - ccdb.cmd.colorama.init(autoreset=True)
        # DON'T - ccdb.cmd.colorama.deinit()

        # create console context
        self.context = ConsoleContext()
        self.context.silent_exceptions = False
        self.context.theme = ccdb.cmd.themes.NoColorTheme()
        self.context.connection_string = self.sqlite_connection_str
        self.context.user_name = "python_user"
        self.context.register_utilities()
        self.context.provider.authentication.current_user_name = "test_user"

        # save stdout
        self.output = StringIO()
        self.saved_stdout = sys.stdout
        sys.stdout = self.output

        # logger
        ch = logging.StreamHandler()
        ch.stream = self.output
        logger.addHandler(ch)
        logger.setLevel(logging.INFO)

        self.context.provider.connect(self.context.connection_string)
        user = self.context.provider.get_current_user()
        # create some test logs w/ current user
        self.context.provider.create_log_record(
            user, ["1"], "create",
            "Created assignment '/testing_filter/start_parms:0:testing_filter:2013-01-17_19-02-27'",
            "Test Log")
コード例 #3
0
    def __init__(self,ccdb_connect_str=None,run=0,variation="default",verbosity=None,ccdb_username=None):        
        if verbosity is None:
            self.VERBOSE = 1
        else:
            self.VERBOSE = verbosity
        if ccdb_username is None:
            # not going to save this for now
            ccdb_username = "******"

        # save defaults for copy command
        self.run = run
        self.variation = variation


        # force users to set the CCDB connection by hand
        # so that we don't accidentally hit the MySQL master too hard
        if ccdb_connect_str is None:
            raise RuntimeError("Need to set CCDB connection!")

        # we need to load the console CCDB interface if we want to use the CLI commands
        self.ccdb_connect_str = ccdb_connect_str
        self.console = ConsoleContext()        # main CLI class
        self.console.silent_exceptions = False                   
        self.console.theme = ccdb.cmd.themes.NoColorTheme()      
        self.console.connection_string = self.ccdb_connect_str
        self.console.user_name = ccdb_username
        self.console.register_utilities()      # initialization

        if self.VERBOSE>0:
            print "Created HDCCDBCopier object:"
            print "  CCDB: %s"%self.ccdb_connect_str
            print "  Source run = %d"%self.run
            print "  Source variation = %s"%self.variation
コード例 #4
0
    def setUp(self):
        # We need only sqlite tests. We test that we work with all databases in the provider fixture
        self.sqlite_connection_str = helper.sqlite_test_connection_str

        # initialize but disable colorama
        #ccdb.cmd.colorama.init(autoreset=True)
        #ccdb.cmd.colorama.deinit()

        # create console context
        self.context = ConsoleContext()
        self.context.silent_exceptions = False
        self.context.theme = ccdb.cmd.themes.NoColorTheme()
        self.context.connection_string = self.sqlite_connection_str
        self.context.user_name = "python_tests"
        self.context.register_utilities()
        self.context.provider.authentication.current_user_name = "test_user"

        # logger
        ch = logging.StreamHandler()
        ch.stream = sys.stdout
        logger.addHandler(ch)
        logger.setLevel(logging.INFO)

        # create table
        try:
            self.context.process_command_line(
                "mktbl /test/channel_mc_efficiency -r 5 -c 1")
        except Exception as e:
            if "Such table already exists" in e.message:
                sys.stderr.write(
                    "mktbl /test/channel_mc_efficiency already exists")
            else:
                raise
コード例 #5
0
def InitCCDB():
    #create connection string:
    ccdb_path = get_ccdb_home_path()
    #sqlite_connection_str = os.getenv(CCDB_CONNECTION, "sqlite:///" + os.path.join(ccdb_path, "sql", "ccdb.sqlite"))
    if os.environ['CCDB_CONNECTION']:
        sqlite_connection_str = os.environ['CCDB_CONNECTION']
    else:
        sqlite_connection_str = "test"
    #print "using CCDB connection = " + sqlite_connection_str

    #create console context
    context = ConsoleContext()  # this is the main class
    context.silent_exceptions = False  # now all exception is raised and you can try-except them
    context.theme = ccdb.cmd.themes.NoColorTheme()  # disable colored output
    context.connection_string = sqlite_connection_str  # set connection string
    #context.user_name = os.getenv(CCDB_USER, "gluex")  # your username
    if 'CCDB_USER' in os.environ and os.environ['CCDB_USER'] is not None:
        context.user_name = os.environ['CCDB_USER']
    else:
        context.user_name = "gluex"
    context.register_utilities(
    )  # Initialization. Register all commands (ls, rm, mktbl etc...)

    return context