コード例 #1
0
def update_stats(test, status):
    p = Popen(['git', 'log', '-1'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
    data, err = p.communicate(None)
    rc = p.returncode
    #print(data)
    data = data.split("\n".encode("ascii"))

    engine = ddb.engine()
    version = str(engine.system['VERSION'])
    date = str(time.strftime('%Y-%m-%d %H:%M:%S'))
    commit = str(data[0])
    log = str(data[4].strip())
    py_major = str(engine.system['PYTHON_MAJOR'])
    py_minor = str(engine.system['PYTHON_MINOR'])
    py_micro = str(engine.system['PYTHON_MICRO'])
    cython = str(engine.system['CYTHON_ENABLED'])
    row = [
        ddb_release, test, version, commit, log, status, py_major, py_minor,
        py_micro, cython, date
    ]
    csv_row = ",".join(row)
    #print (os.getcwd())
    stats_file_path = os.path.join(ddb_project_dir, "profile/stats.csv")
    file = open(stats_file_path, "at")
    file.write(csv_row + "\n")
    file.close()
コード例 #2
0
    def test_set(self):
        """Set a database variable """
        print("SET")
        self.cleanup()
        engine = ddb.engine(config_dir=self.config_dir, debug=None)

        results = engine.query("set AUTOCOMMIT=False")
        self.assertEqual(True, results.success)
        results = engine.query("set OUTPUT_MODULE=YAML")
        self.assertEqual(True, results.success)
        results = engine.query("set OUTPUT_MODULE=TERM_RST")
        self.assertEqual(True, results.success)
        results = engine.query("set OUTPUT_MODULE=TERM_SINGLE")
        self.assertEqual(True, results.success)
        # Because it doesnt exist
        results = engine.query("set OUTPUT=TERM_DOUBLE")
        self.assertEqual(False, results.success)
        # User var test
        results = engine.query("set @time=1")
        self.assertEqual(True, results.success)
        results = engine.query("set @light=ON")
        self.assertEqual(True, results.success)
        results = engine.query("set @light=OFF")
        self.assertEqual(True, results.success)
        results = engine.query("set @config=FALSE")
        self.assertEqual(True, results.success)

        results = engine.query("show variables")
        try:
            ddb.output.factory.output_factory(query_results=results,
                                              output='TERM')
        except:
            ddb.output_factory(query_results=results, output='TERM')

        self.assertEqual(True, results.success)
コード例 #3
0
    def test_drop_table(self, mode=None):
        """Test dropping a table"""
        self.cleanup()
        engine = ddb.engine(config_dir=self.config_dir, debug=None)

        self.create_table(engine, mode)

        # fail on existing table
        results = engine.query(stringer('drop table {0}', self.table_name))
        self.assertEqual(True, results.success)
コード例 #4
0
    def test_use(self, mode=None):
        """Test changing database context"""
        print("USE")
        # single db change from default
        self.cleanup()
        engine = ddb.engine(config_dir=self.config_dir, debug=None)
        self.create_table(engine, mode)

        results = engine.query(stringer("use {0}", self.table_name))
        self.assertEqual(True, results.success)
        results = engine.query("select database()")
        self.assertEqual(True, results.success)
コード例 #5
0
 def test_show_output_modules(self):
     """Test showint output modules and styles"""
     # single db change from default
     self.cleanup()
     engine = ddb.engine(config_dir=self.config_dir, debug=None)
     results = engine.query("show output modules")
     try:
         ddb.output.factory.output_factory(query_results=results,
                                           output='TERM')
     except:
         ddb.output_factory(query_results=results, output='TERM')
     self.assertEqual(True, results.success)
コード例 #6
0
    def test_show_tables(self, mode=None):
        """Show all tables in the database"""
        self.cleanup()
        engine = ddb.engine(config_dir=self.config_dir, debug=None)
        self.create_table(engine, mode)

        results = engine.query("SHOW TABLES")
        #results.debug()
        self.assertEqual(True, results.success)
        try:
            ddb.output.factory.output_factory(query_results=results,
                                              output='term')
        except:
            ddb.output_factory(query_results=results, output='term')
コード例 #7
0
    def test_select(self, mode=None):
        """Test selecting results using various clauses a table"""
        print("SELECT")
        self.cleanup()
        engine = ddb.engine(config_dir=self.config_dir, debug=None)
        # fail on existing table

        self.create_table(engine, mode)

        # test results length

        results = engine.query(
            stringer('select * from {0} LIMIT 10', self.table_name))
        self.assertEqual(True, results.success)
        #results.debug()
        self.assertEqual(10, results.data_length)

        results = engine.query(
            stringer('select * from {0} LIMIT 1', self.table_name))
        self.assertEqual(True, results.success)
        self.assertEqual(1, results.data_length)

        results = engine.query(
            stringer('select * from {0} LIMIT 0', self.table_name))
        self.assertEqual(True, results.success)
        self.assertEqual(0, results.data_length)

        # WHERE/LIMIT
        results = engine.query(
            stringer('select * from {0} where id="1" order by id LIMIT 100;',
                     self.table_name))
        results.debug()
        self.assertEqual(True, results.success)
        self.assertEqual(1, results.data_length)

        # WHERE AND/LIMIT
        results = engine.query(
            stringer(
                'select * from {0} where id="1" and id not "2" order by id LIMIT 100;',
                self.table_name))
        self.assertEqual(True, results.success)
        self.assertEqual(1, results.data_length)

        # WHERE / AND / OR/LIMIT
        results = engine.query(
            stringer(
                'select * from {0} where id="1" and id not "2" or id="3" order by id LIMIT 100;',
                self.table_name))
        self.assertEqual(True, results.success)
        self.assertEqual(2, results.data_length)
コード例 #8
0
    def test_describe_table(self, mode=None):
        """Show table configuration"""
        print("DESCRIBE TABLE")
        self.cleanup()

        engine = ddb.engine(config_dir=self.config_dir, debug=None)
        self.create_table(engine, mode)

        results = engine.query(stringer("DESCRIBE TABLE {0}", self.table_name))
        try:
            ddb.output.factory.output_factory(query_results=results,
                                              output='term')
        except:
            ddb.output_factory(query_results=results, output='TERM')
        self.assertEqual(True, results.success)
コード例 #9
0
    def test_create_table(self, mode=None):
        """Test creating a table"""
        try:
            self.cleanup()
            engine = ddb.engine(config_dir=self.config_dir, debug=None)

            self.create_table(engine, mode)
        except Exception:
            ex = sys.exc_info()[1]
            self.fail(ex)

        # fail on existing table
        results = engine.query(
            stringer(
                "create table {0} ('id','first_name','last_name','email','gender','ip_address') file='{1}' data_starts_on=2",
                self.table_name, os.path.join(self.basedir, self.temp_data)))
        self.assertEqual(False, results.success)
コード例 #10
0
    def test_update(self, mode=None):
        """Update a row in the test file"""
        self.cleanup()
        print("UPDATE")
        engine = ddb.engine(config_dir=self.config_dir, debug=None)
        # fail on existing table
        self.create_table(engine, mode)

        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1002,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name))
        print("UPDATE 1")
        self.assertEqual(True, results.success)
        # update
        results = engine.query(
            stringer('update {0} set email="*****@*****.**" where id="1002"',
                     self.table_name))
        print("UPDATE 2")
        self.assertEqual(True, results.success)

        results = engine.query(
            stringer("delete from {0} where id='1002'", self.table_name))
        print("UPDATE 3")
        self.assertEqual(True, results.success)

        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1002,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name2))
        print("UPDATE 1")
        self.assertEqual(True, results.success)
        # update
        results = engine.query(
            stringer('update {0} set email="*****@*****.**" where id="1002"',
                     self.table_name2))
        print("UPDATE 2")
        self.assertEqual(True, results.success)

        results = engine.query(
            stringer("delete from {0} where id='1002'", self.table_name2))
        print("UPDATE 3")
        self.assertEqual(True, results.success)
コード例 #11
0
    def test_insert(self, mode=None):
        """Insert a row in the test file"""
        self.cleanup()
        print("INSERT")
        engine = ddb.engine(config_dir=self.config_dir, debug=self.debug)
        self.cleanup()
        # fail on existing table
        self.create_table(engine, mode)

        # update
        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1001,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name))
        #results.debug()
        self.assertEqual(True, results.success)
        # Delete
        results = engine.query(
            stringer("delete from {0} where id='1001'", self.table_name))
        self.assertEqual(True, results.success)
コード例 #12
0
    def lock(self, mode=None):
        engine = ddb.engine(config_dir=None, debug=None)
        self.create_table(engine, mode)
        start_time = time.time()
        ellapsed_time = 0
        pid = os.getpid()
        value = 1
        # test results length
        insert_count = 100
        for i in range(0, insert_count):
            timestamp = datetime.datetime.now()

            query = "INSERT INTO @db.@table (`id`,`pid`,`value`,`timestamp`) values (@id,@pid,@value,@timestamp)"
            params = {
                '@db': self.database_name,
                '@table': self.table_name,
                '@id': i,
                '@pid': pid,
                '@value': value,
                '@timestamp': timestamp
            }

            results = engine.query(query, params)
            #self.assertEqual(True, results.success)

        query = "SELECT id FROM  @db.@table WHERE `pid`=@pid"
        params = {
            '@db': self.database_name,
            '@table': self.table_name,
            '@id': i,
            '@pid': pid,
        }

        results = engine.query(query, params)
        if results.data_length != insert_count:
            sys.exit(-1)

        curent_time = time.time()
        ellapsed_time = curent_time - start_time
コード例 #13
0
    def test_params(self, mode=None):
        """Test parameterizing a query"""
        print("PARAMS")
        self.cleanup()
        engine = ddb.engine(config_dir=self.config_dir, debug=None)
        # fail on existing table

        self.create_table(engine, mode)

        # test results length
        engine.set_param("@limit", 10)

        results = engine.query(
            stringer('select * from {0} LIMIT @limit', self.table_name))
        self.assertEqual(True, results.success)
        self.assertEqual(10, results.data_length)

        engine.set_param("@limit", 8)
        results = engine.query(
            stringer('select * from {0} LIMIT @limit', self.table_name))
        self.assertEqual(True, results.success)
        self.assertEqual(8, results.data_length)
コード例 #14
0
    def test_delete(self, mode=None):
        """Delete a test row in the test file"""
        self.cleanup()
        print("DELETE")
        engine = ddb.engine(config_dir=self.config_dir)
        self.create_table(engine, mode)
        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1003,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name))
        self.assertEqual(True, results.success)
        # delete just inserted
        print("DELETE 2")
        results = engine.query(
            stringer("delete from {0} where id='1003'", self.table_name))
        self.assertEqual(True, results.success)

        print("DELETE 3")
        # delete non existing
        results = engine.query(
            stringer("delete from {0} where email like 'bop@%'",
                     self.table_name))
        self.assertEqual(True, results.success)
コード例 #15
0
    def test_upsert(self, mode=None):
        """Show all tables in the database"""
        self.cleanup()
        print("UPSERT")
        engine = ddb.engine(config_dir=self.config_dir, debug=None)
        self.create_table(engine, mode)

        results = engine.query(
            stringer(
                "upsert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1006,test_name,test_lname,'*****@*****.**','m','0.0.0.0') ON DUPLICATE KEY id UPDATE id='12345' ",
                self.table_name))
        self.assertEqual(True, results.success)

        results = engine.query(
            stringer("select * from  {0} where id = 1006", self.table_name))
        self.assertEqual(1, results.data_length)

        results = engine.query(
            stringer(
                "upsert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1006,test_name,test_lname,'*****@*****.**','m','0.0.0.0') ON DUPLICATE KEY id UPDATE id='12345' ",
                self.table_name))
        self.assertEqual(True, results.success)

        results = engine.query(
            stringer("select * from  {0} where id = 12345", self.table_name))
        self.assertEqual(1, results.data_length)

        results = engine.query(
            stringer("delete from {0} where id = 12345", self.table_name))
        self.assertEqual(1, results.affected_rows)

        try:
            ddb.output.factory.output_factory(query_results=results,
                                              output='term')
        except:
            ddb.output_factory(query_results=results, output='TERM')
コード例 #16
0
    def test_commit(self, mode=None):
        """Rollback db changes"""
        self.cleanup()
        print("COMMIT")
        engine = ddb.engine(config_dir=self.config_dir)

        self.create_table(engine, mode)

        print("PRE BEGIN")
        results = engine.query("begin")
        self.assertEqual(True, results.success)

        print("PRE DELETE")
        # clean any inserts
        results = engine.query(
            stringer("delete from {0} WHERE email='*****@*****.**'",
                     self.table_name))
        self.assertEqual(True, results.success)
        results = engine.query(
            stringer("delete from {0} WHERE email='*****@*****.**'",
                     self.table_name2))
        self.assertEqual(True, results.success)

        print("Get length")
        results = engine.query(stringer("SELECT id FROM {0}", self.table_name))
        #results.debug()
        self.assertEqual(True, results.success)
        target_length = results.data_length

        results = engine.query(stringer("SELECT id FROM {0}",
                                        self.table_name2))
        #results.debug()
        self.assertEqual(True, results.success)
        target_length2 = results.data_length

        print("PRE INSERT")
        # update
        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1001,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name))
        #results.debug()
        self.assertEqual(True, results.success)
        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1001,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name2))
        #results.debug()
        self.assertEqual(True, results.success)

        print("PRE SELECT")
        results = engine.query(stringer("SELECT id FROM {0}", self.table_name))
        #results.debug()
        self.assertEqual(True, results.success)
        self.assertEqual(target_length + 1, results.data_length)
        results = engine.query(stringer("SELECT id FROM {0}",
                                        self.table_name2))
        #results.debug()
        self.assertEqual(True, results.success)
        self.assertEqual(target_length2 + 1, results.data_length)

        #results.debug()

        print("PRE COMMIT")
        results = engine.query("commit")
        print(results.error)
        self.assertEqual(True, results.success)

        print("PRE SELECT")
        results = engine.query(stringer("SELECT id FROM {0}", self.table_name))
        #results.debug()
        self.assertEqual(True, results.success)
        self.assertEqual(target_length + 1, results.data_length)
        results = engine.query(stringer("SELECT id FROM {0}",
                                        self.table_name2))
        #results.debug()
        self.assertEqual(True, results.success)
        self.assertEqual(target_length2 + 1, results.data_length)

        print("PRE DELETE")
        results = engine.query(
            stringer("delete from {0} where id='1001'", self.table_name))
        self.assertEqual(True, results.success)
        results = engine.query(
            stringer("delete from {0} where id='1001'", self.table_name2))
        self.assertEqual(True, results.success)
コード例 #17
0
    def test_rollback(self, mode=None):
        """Rollback db changes"""
        self.cleanup()
        print("ROLLBACK")
        engine = ddb.engine(config_dir=self.config_dir)

        self.create_table(engine, mode)

        print("Begin")
        results = engine.query("begin")
        self.assertEqual(True, results.success)

        # get the length of all rows
        print("Select")
        results = engine.query(stringer("SELECT id FROM {0}", self.table_name))
        self.assertEqual(True, results.success)
        target_length = results.data_length
        results = engine.query(stringer("SELECT id FROM {0}",
                                        self.table_name2))
        self.assertEqual(True, results.success)
        target_length2 = results.data_length

        # update
        print("Insert")
        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1001,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name))
        self.assertEqual(True, results.success)
        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1001,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name))
        self.assertEqual(True, results.success)
        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1001,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name2))
        self.assertEqual(True, results.success)
        results = engine.query(
            stringer(
                "insert into {0} ('id','first_name','last_name','email','gender','ip_address') values (1001,test_name,test_lname,'*****@*****.**','m','0.0.0.0')",
                self.table_name2))
        self.assertEqual(True, results.success)

        print("Select")
        results = engine.query(stringer("SELECT id FROM {0}", self.table_name))
        self.assertEqual(True, results.success)
        self.assertEqual(target_length + 2, results.data_length)
        results = engine.query(stringer("SELECT id FROM {0}",
                                        self.table_name2))
        self.assertEqual(True, results.success)
        self.assertEqual(target_length2 + 2, results.data_length)
        #results.debug()

        print("rollback")
        results = engine.query("rollback")
        self.assertEqual(True, results.success)

        results = engine.query(stringer("SELECT id FROM {0}", self.table_name))
        #results.debug()
        self.assertEqual(True, results.success)
        self.assertEqual(target_length, results.data_length)

        results = engine.query(stringer("SELECT id FROM {0}",
                                        self.table_name2))
        #results.debug()
        self.assertEqual(True, results.success)
        self.assertEqual(target_length2, results.data_length)