Ejemplo n.º 1
0
def test_51_metadata():
    mocker = Mocker()
    connect = mocker.replace('MySQLdb.connect')
    link = connect(ARGS, KWARGS)
    mocker.result(link)
    link.get_server_info()
    mocker.result('5.1.99')
    cursor = link.cursor()
    sql = ("SELECT TABLE_SCHEMA AS `database`, "
           "          TABLE_NAME AS `name`, "
           "          DATA_LENGTH AS `data_size`, "
           "          INDEX_LENGTH AS `index_size`, "
           "          ENGINE AS `engine`, "
           "          TRANSACTIONS AS `is_transactional` "
           "FROM INFORMATION_SCHEMA.TABLES "
           "JOIN INFORMATION_SCHEMA.ENGINES USING (ENGINE) "
           "WHERE TABLE_SCHEMA = %s")
    cursor.execute(sql, ('mysql'))
    cursor.description
    fields = [('database', ), ('name', ), ('data_size', ), ('index_size', ),
              ('engine', ), ('is_transactional', )]
    mocker.result(fields)
    cursor.fetchall()
    results = [
        ('mysql', 'user', 1024, 1024, 'MyISAM', False),
        ('mysql', 'db', 1024, 1024, 'MyISAM', False),
    ]
    mocker.result(results)
    cursor.close()
    mocker.replay()
    try:
        client = MySQLClient(read_default_file='/etc/my.cnf')
        expected_metadata = [
            {
                'database': 'mysql',
                'name': 'user',
                'engine': 'MyISAM',
                'data_size': 1024,
                'index_size': 1024,
                'is_transactional': False,
            },
            {
                'database': 'mysql',
                'name': 'db',
                'engine': 'MyISAM',
                'data_size': 1024,
                'index_size': 1024,
                'is_transactional': False,
            },
        ]
        md = client.show_table_metadata('mysql')
        assert_equals(md, expected_metadata)
        mocker.verify()
    finally:
        mocker.restore()
Ejemplo n.º 2
0
def test_51_metadata():
    mocker = Mocker()
    connect = mocker.replace('MySQLdb.connect')
    link = connect(ARGS, KWARGS)
    mocker.result(link)
    link.get_server_info()
    mocker.result('5.1.99')
    cursor = link.cursor()
    sql = ("SELECT TABLE_SCHEMA AS `database`, "
           "          TABLE_NAME AS `name`, "
           "          DATA_LENGTH AS `data_size`, "
           "          INDEX_LENGTH AS `index_size`, "
           "          ENGINE AS `engine`, "
           "          TRANSACTIONS AS `is_transactional` "
           "FROM INFORMATION_SCHEMA.TABLES "
           "JOIN INFORMATION_SCHEMA.ENGINES USING (ENGINE) "
           "WHERE TABLE_SCHEMA = %s")
    cursor.execute(sql, ('mysql'))
    cursor.description
    fields = [('database',),('name',),('data_size',),('index_size',),('engine',),('is_transactional',)]
    mocker.result(fields)
    cursor.fetchall()
    results = [
        ('mysql', 'user', 1024,1024, 'MyISAM', False),
        ('mysql', 'db', 1024, 1024, 'MyISAM', False),
    ]
    mocker.result(results)
    cursor.close()
    mocker.replay()
    try:
        client = MySQLClient(read_default_file='/etc/my.cnf')
        expected_metadata = [
            { 'database' : 'mysql',
              'name' : 'user',
              'engine' : 'MyISAM',
              'data_size' : 1024,
              'index_size' : 1024,
              'is_transactional' : False,
            },
            { 'database' : 'mysql',
              'name' : 'db',
              'engine' : 'MyISAM',
              'data_size' : 1024,
              'index_size' : 1024,
              'is_transactional' : False,
            },
        ]
        md = client.show_table_metadata('mysql')
        assert_equals(md, expected_metadata)
        mocker.verify()
    finally:
        mocker.restore()
Ejemplo n.º 3
0
def test_50_metadata():
    mocker = Mocker()
    connect = mocker.replace('MySQLdb.connect')
    link = connect(ARGS, KWARGS)
    mocker.result(link)
    link.get_server_info()
    mocker.result('5.0.87')
    cursor = link.cursor()
    cursor.execute('SHOW TABLE STATUS FROM `mysql`')
    cursor.description
    fields = [('name', ), ('engine', ), ('data_length', ), ('index_length', )]
    mocker.result(fields)
    iter(cursor)
    results = [
        ('user', 'myisam', 1024, 1024),
        ('db', 'myisam', 1024, 1024),
    ]
    mocker.generate(results)
    cursor.close()
    mocker.replay()
    try:
        client = MySQLClient(read_default_file='/etc/my.cnf')
        expected_metadata = [
            {
                'database': 'mysql',
                'name': 'user',
                'engine': 'myisam',
                'data_size': 1024,
                'index_size': 1024,
                'is_transactional': False
            },
            {
                'database': 'mysql',
                'name': 'db',
                'engine': 'myisam',
                'data_size': 1024,
                'index_size': 1024,
                'is_transactional': False
            },
        ]
        md = client.show_table_metadata('mysql')
        assert_equals(md, expected_metadata)
        mocker.verify()
    finally:
        mocker.restore()
Ejemplo n.º 4
0
def test_50_metadata():
    mocker = Mocker()
    connect = mocker.replace('MySQLdb.connect')
    link = connect(ARGS, KWARGS)
    mocker.result(link)
    link.get_server_info()
    mocker.result('5.0.87')
    cursor = link.cursor()
    cursor.execute('SHOW TABLE STATUS FROM `mysql`')
    cursor.description
    fields = [('name',),('engine',),('data_length',),('index_length',)]
    mocker.result(fields)
    iter(cursor)
    results = [
        ('user', 'myisam',1024,1024),
        ('db', 'myisam', 1024, 1024),
    ]
    mocker.generate(results)
    cursor.close()
    mocker.replay()
    try:
        client = MySQLClient(read_default_file='/etc/my.cnf')
        expected_metadata = [
            { 'database' : 'mysql',
              'name' : 'user',
              'engine' : 'myisam',
              'data_size' : 1024,
              'index_size' : 1024,
              'is_transactional' : False
            },
            { 'database' : 'mysql',
              'name' : 'db',
              'engine' : 'myisam',
              'data_size' : 1024,
              'index_size' : 1024,
              'is_transactional' : False
            },
        ]
        md = client.show_table_metadata('mysql')
        assert_equals(md, expected_metadata)
        mocker.verify()
    finally:
        mocker.restore()