Пример #1
0
def step_send_source_command(context):
    with tempfile.NamedTemporaryFile() as f:
        f.write(b'\?')
        f.flush()
        context.cli.sendline('\i {0}'.format(f.name))
        wrappers.expect_exact(
            context, context.conf['pager_boundary'] + '\r\n', timeout=5)
Пример #2
0
def step_send_source_command(context):
    context.tmpfile_sql_help = tempfile.NamedTemporaryFile(prefix='pgcli_')
    context.tmpfile_sql_help.write(b'\?')
    context.tmpfile_sql_help.flush()
    context.cli.sendline('\i {0}'.format(context.tmpfile_sql_help.name))
    wrappers.expect_exact(
        context, context.conf['pager_boundary'] + '\r\n', timeout=5)
Пример #3
0
def step_see_container_unpaused(context, container_name):
    """
    Check container is running.
    """
    wrappers.expect_exact(context, container_name + '\r\n')
    context.cli.sendline('ps')
    wrappers.expect(context, r'Up [a-zA-Z0-9\s]+\s{2,}')
def step_see_container_unpaused(context, container_name):
    """
    Check container is running.
    """
    wrappers.expect_exact(context, container_name + '\r\n')
    context.cli.sendline('ps')
    wrappers.expect(context, r'Up [a-zA-Z0-9\s]+\s{2,}')
def step_see_container_paused(context, container_name):
    """
    Check container is paused.
    """
    wrappers.expect_exact(context, container_name + '\r\n')
    context.cli.sendline('ps')
    wrappers.expect_exact(context, ' (Paused)')
Пример #6
0
def step_confirm_destructive_command(context):
    """Confirm destructive command."""
    wrappers.expect_exact(
        context,
        'You\'re about to run a destructive command.\r\nDo you want to proceed? (y/n):',
        timeout=2)
    context.cli.sendline('y')
Пример #7
0
def step_wait_prompt(context):
    """Make sure prompt is displayed."""
    user = context.conf['user']
    host = context.conf['host']
    dbname = context.conf['dbname']
    wrappers.expect_exact(context, 'mysql {0}@{1}:{2}> '.format(
        user, host, dbname), timeout=5)
Пример #8
0
def step_see_prompt(context):
    """
    Wait to see the prompt.
    """
    wrappers.expect_exact(context,
                          '{0}> '.format(context.conf['dbname']),
                          timeout=5)
Пример #9
0
def step_see_db_connected(context):
    """
    Wait to see drop database output.
    """
    wrappers.expect_exact(context,
                          'You are now connected to database',
                          timeout=2)
Пример #10
0
def step_wait_prompt(context):
    """
    Make sure prompt is displayed.
    """
    wrappers.expect_exact(context,
                          '{0}> '.format(context.conf['dbname']),
                          timeout=5)
Пример #11
0
def step_see_prompt(context):
    """
    Wait to see the prompt.
    """
    db_name = getattr(context, "currentdb", context.conf["dbname"])
    wrappers.expect_exact(context, f"{db_name}> ", timeout=5)
    context.atprompt = True
Пример #12
0
def step_see_container_paused(context, container_name):
    """
    Check container is paused.
    """
    wrappers.expect_exact(context, container_name + '\r\n')
    context.cli.sendline('ps')
    wrappers.expect_exact(context, ' (Paused)')
Пример #13
0
def step_see_refresh_started(context):
    """
    Wait to see refresh output.
    """
    wrappers.expect_exact(context,
                          'Auto-completion refresh started in the background',
                          timeout=2)
Пример #14
0
def step_edit_done_sql(context):
    for match in 'select * from abc'.split(' '):
        wrappers.expect_exact(context, match, timeout=1)
    # Cleanup the command line.
    context.cli.sendcontrol('c')
    # Cleanup the edited file.
    if context.editor_file_name and os.path.exists(context.editor_file_name):
        os.remove(context.editor_file_name)
Пример #15
0
def step_db_drop(context):
    """Send drop database."""
    context.cli.sendline('drop database {0};'.format(
        context.conf['dbname_tmp']))

    wrappers.expect_exact(
        context, 'You\'re about to run a destructive command.\r\nDo you want to proceed? (y/n):', timeout=2)
    context.cli.sendline('y')
def step_see_prompt(context):
    """Wait to see the prompt."""
    user = context.conf['user']
    host = context.conf['host']
    dbname = context.currentdb
    wrappers.expect_exact(context, 'mysql {0}@{1}:{2}> '.format(
        user, host, dbname), timeout=5)
    context.atprompt = True
Пример #17
0
def status_contains(context, expression):
    wrappers.expect_exact(context, f'{expression}', timeout=5)

    # Normally, the shutdown after scenario waits for the prompt.
    # But we may have changed the prompt, depending on parameters,
    # so let's wait for its last character
    context.cli.expect_exact('>')
    context.atprompt = True
def step_db_drop(context):
    """Send drop database."""
    context.cli.sendline('drop database {0};'.format(
        context.conf['dbname_tmp']))

    wrappers.expect_exact(
        context, 'You\'re about to run a destructive command.\r\nDo you want to proceed? (y/n):', timeout=2)
    context.cli.sendline('y')
Пример #19
0
def step_see_data_selected(context):
    """
    Wait to see select output.
    """
    wrappers.expect_exact(
        context,
        '+-----+\r\n| x   |\r\n|-----|\r\n| yyy |\r\n+-----+\r\n1 row in set\r\n',
        timeout=1)
Пример #20
0
def step_see_large_results(context):
    rows = ['{n:3}| {n}'.format(n=str(n)) for n in range(1, 50)]
    expected = ('***************************[ 1. row ]'
                '***************************\r\n' +
                '{}\r\n'.format('\r\n'.join(rows) + '\r\n'))

    wrappers.expect_pager(context, expected, timeout=5)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #21
0
def step_see_large_results(context):
    rows = ['{n:3}| {n}'.format(n=str(n)) for n in range(1, 50)]
    expected = ('***************************[ 1. row ]'
                '***************************\r\n' +
                '{}\r\n'.format('\r\n'.join(rows) + '\r\n'))

    wrappers.expect_pager(context, expected, timeout=10)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #22
0
def step_send_source_command(context):
    context.tmpfile_sql_help = tempfile.NamedTemporaryFile(prefix="pgcli_")
    context.tmpfile_sql_help.write(b"\?")
    context.tmpfile_sql_help.flush()
    context.cli.sendline("\i {0}".format(context.tmpfile_sql_help.name))
    wrappers.expect_exact(context,
                          context.conf["pager_boundary"] + "\r\n",
                          timeout=5)
Пример #23
0
def step_see_prompt(context):
    """Wait to see the prompt."""
    user = context.conf['user']
    host = context.conf['host']
    dbname = context.currentdb
    wrappers.expect_exact(context, '{0}@{1}:{2}> '.format(
        user, host, dbname), timeout=5)
    context.atprompt = True
Пример #24
0
def step_delete_from_table(context):
    """Send deete from table."""
    context.cli.sendline('''delete from a where x = 'yyy';''')
    wrappers.expect_exact(
        context,
        'You\'re about to run a destructive command.\r\nDo you want to proceed? (y/n):',
        timeout=2)
    context.cli.sendline('y')
Пример #25
0
def step_drop_table(context):
    """Send drop table."""
    context.cli.sendline('drop table a;')
    wrappers.expect_exact(
        context,
        'You\'re about to run a destructive command.\r\nDo you want to proceed? (y/n):',
        timeout=2)
    context.cli.sendline('y')
Пример #26
0
def step_send_source_command(context):
    context.tmpfile_sql_help = tempfile.NamedTemporaryFile(prefix='pgcli_')
    context.tmpfile_sql_help.write(b'\?')
    context.tmpfile_sql_help.flush()
    context.cli.sendline('\i {0}'.format(context.tmpfile_sql_help.name))
    wrappers.expect_exact(context,
                          context.conf['pager_boundary'] + '\r\n',
                          timeout=5)
Пример #27
0
def step_edit_done_sql(context):
    for match in 'select * from abc'.split(' '):
        wrappers.expect_exact(context, match, timeout=1)
    # Cleanup the command line.
    context.cli.sendcontrol('c')
    # Cleanup the edited file.
    if context.editor_file_name and os.path.exists(context.editor_file_name):
        os.remove(context.editor_file_name)
Пример #28
0
def step_send_help(context):
    """Send \?

    to see help.

    """
    context.cli.sendline('\\?')
    wrappers.expect_exact(
        context, context.conf['pager_boundary'] + '\r\n', timeout=5)
Пример #29
0
def step_see_db_dropped_no_default(context):
    """Wait to see drop database output."""
    user = context.conf['user']
    host = context.conf['host']
    database = '(none)'
    context.currentdb = None

    wrappers.expect_exact(context, 'Query OK, 0 rows affected', timeout=2)
    wrappers.wait_prompt(context, '{0}@{1}:{2}>'.format(user, host, database))
Пример #30
0
def step_send_help(context):
    """Send \?

    to see help.

    """
    context.cli.sendline('\\?')
    wrappers.expect_exact(
        context, context.conf['pager_boundary'] + '\r\n', timeout=5)
Пример #31
0
def step_see_small_results(context):
    wrappers.expect_pager(context, dedent("""\
        +---+\r
        | 1 |\r
        +---+\r
        | 1 |\r
        +---+\r
        """), timeout=5)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #32
0
def step_see_found(context):
    wrappers.expect_exact(context,
                          context.conf['pager_boundary'] + '\r' + dedent('''
            +-------+\r
            | found |\r
            +-------+\r
            | found |\r
            +-------+\r
        ''') + context.conf['pager_boundary'],
                          timeout=5)
Пример #33
0
def step_query_select_123456(context):
    context.cli.sendline('select 123456')
    wrappers.expect_pager(context, dedent("""\
        +--------+\r
        | 123456 |\r
        +--------+\r
        | 123456 |\r
        +--------+\r
        """), timeout=5)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #34
0
def step_see_image_pulled(context, image_name):
    """
    Expect to see image pulled.
    """
    wrappers.expect_exact(context, [
        'Downloaded newer image for ' + image_name,
        'Image is up to date for ' + image_name,
        'Pull complete',
        'Download complete'],
        timeout=180)
Пример #35
0
def step_confirm_destructive_command(context, confirmation, text):
    """Confirm destructive command."""
    wrappers.expect_exact(
        context,
        'You\'re about to run a destructive command.\r\nDo you want to proceed? (y/n):',
        timeout=2)
    context.cli.sendline(confirmation)
    wrappers.expect_exact(context, text, timeout=2)
    # we must exit the Click loop, or the feature will hang
    context.cli.sendline('n')
Пример #36
0
def step_see_null_selected(context):
    """Wait to see null output."""
    wrappers.expect_pager(
        context, dedent("""\
            +--------+\r
            | NULL   |\r
            +--------+\r
            | <null> |\r
            +--------+\r
            """), timeout=2)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #37
0
def step_see_null_selected(context):
    """Wait to see null output."""
    wrappers.expect_pager(
        context, dedent("""\
            +--------+\r
            | NULL   |\r
            +--------+\r
            | <null> |\r
            +--------+\r
            """), timeout=1)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #38
0
def step_edit_file(context):
    """Edit file with external editor."""
    context.editor_file_name = os.path.join(
        context.package_root, 'test_file_{0}.sql'.format(context.conf['vi']))
    if os.path.exists(context.editor_file_name):
        os.remove(context.editor_file_name)
    context.cli.sendline('\e {0}'.format(
        os.path.basename(context.editor_file_name)))
    wrappers.expect_exact(
        context, 'Entering Ex mode.  Type "visual" to go to Normal mode.', timeout=2)
    wrappers.expect_exact(context, ':', timeout=2)
Пример #39
0
def step_see_data_selected(context):
    """Wait to see select output."""
    wrappers.expect_pager(
        context, dedent("""\
            +-----+\r
            | x   |\r
            +-----+\r
            | yyy |\r
            +-----+\r
            """), timeout=1)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #40
0
def step_see_small_results(context):
    wrappers.expect_pager(context,
                          dedent("""\
        +---+\r
        | 1 |\r
        +---+\r
        | 1 |\r
        +---+\r
        """),
                          timeout=5)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #41
0
def step_edit_file(context):
    """Edit file with external editor."""
    context.editor_file_name = os.path.join(
        context.package_root, 'test_file_{0}.sql'.format(context.conf['vi']))
    if os.path.exists(context.editor_file_name):
        os.remove(context.editor_file_name)
    context.cli.sendline('\e {0}'.format(
        os.path.basename(context.editor_file_name)))
    wrappers.expect_exact(
        context, 'Entering Ex mode.  Type "visual" to go to Normal mode.', timeout=2)
    wrappers.expect_exact(context, '\r\n:', timeout=2)
Пример #42
0
def step_see_data_selected(context):
    """Wait to see select output."""
    wrappers.expect_pager(
        context, dedent("""\
            +-----+\r
            | x   |\r
            +-----+\r
            | yyy |\r
            +-----+\r
            """), timeout=2)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
def step_query_select_123456(context):
    context.cli.sendline('select 123456')
    wrappers.expect_pager(context,
                          dedent("""\
        +--------+\r
        | 123456 |\r
        +--------+\r
        | 123456 |\r
        +--------+\r
        """),
                          timeout=5)
    wrappers.expect_exact(context, '1 row in set', timeout=2)
Пример #44
0
def step_see_db_dropped_no_default(context):
    """Wait to see drop database output."""
    user = context.conf['user']
    host = context.conf['host']
    database = '(none)'
    context.currentdb = None

    wrappers.expect_exact(context, 'Query OK, 0 rows affected', timeout=2)
    wrappers.expect_exact(context, '{0}@{1}:{2}> '.format(
        user, host, database), timeout=5)

    context.atprompt = True
Пример #45
0
def step_see_found(context):
    wrappers.expect_exact(
        context,
        context.conf['pager_boundary'] + '\r' + dedent('''
            +------------+\r
            | ?column?   |\r
            |------------|\r
            | found      |\r
            +------------+\r
            SELECT 1\r
        ''') + context.conf['pager_boundary'],
        timeout=5
    )
Пример #46
0
def step_prepare_data(context):
    """Create table, insert a record."""
    context.cli.sendline('drop table if exists a;')
    wrappers.expect_exact(
        context, 'You\'re about to run a destructive command.\r\nDo you want to proceed? (y/n):', timeout=2)
    context.cli.sendline('y')

    wrappers.wait_prompt(context)
    context.cli.sendline(
        'create table a(x integer, y real, z numeric(10, 4));')
    wrappers.expect_pager(context, 'CREATE TABLE\r\n', timeout=2)
    context.cli.sendline('''insert into a(x, y, z) values(1, 1.0, 1.0);''')
    wrappers.expect_pager(context, 'INSERT 0 1\r\n', timeout=2)
Пример #47
0
def step_tee_ouptut(context):
    context.tee_file_name = os.path.join(
        context.package_root, 'tee_file_{0}.sql'.format(context.conf['vi']))
    if os.path.exists(context.tee_file_name):
        os.remove(context.tee_file_name)
    context.cli.sendline('\o {0}'.format(
        os.path.basename(context.tee_file_name)))
    wrappers.expect_exact(
        context, context.conf['pager_boundary'] + '\r\n', timeout=5)
    wrappers.expect_exact(context, "Writing to file", timeout=5)
    wrappers.expect_exact(
        context, context.conf['pager_boundary'] + '\r\n', timeout=5)
    wrappers.expect_exact(context, "Time", timeout=5)
Пример #48
0
def step_see_db_connected(context):
    """Wait to see drop database output."""
    wrappers.expect_exact(
        context, 'You are now connected to database "', timeout=2)
    wrappers.expect_exact(context, '"', timeout=2)
    wrappers.expect_exact(context, ' as user "{0}"'.format(
        context.conf['user']), timeout=2)
Пример #49
0
def step_wait_exit(context):
    """Make sure the cli exits."""
    wrappers.expect_exact(context, pexpect.EOF, timeout=5)
Пример #50
0
def step_see_help(context):
    for expected_line in context.fixture_data['help_commands.txt']:
        wrappers.expect_exact(context, expected_line + '\r\n', timeout=1)
Пример #51
0
def step_notee_output(context):
    context.cli.sendline('notee')
    wrappers.expect_exact(context, "Time", timeout=5)
Пример #52
0
def step_edit_quit(context):
    context.cli.sendline('x')
    wrappers.expect_exact(context, "written", timeout=2)
Пример #53
0
def step_see_db_created(context):
    """Wait to see create database output."""
    wrappers.expect_exact(context, 'Query OK, 1 row affected', timeout=2)
Пример #54
0
def step_edit_type_sql(context):
    context.cli.sendline('i')
    context.cli.sendline('select * from abc')
    context.cli.sendline('.')
    wrappers.expect_exact(context, ':', timeout=2)
Пример #55
0
def step_see_record_updated(context):
    """Wait to see update output."""
    wrappers.expect_exact(context, 'Query OK, 1 row affected', timeout=2)
Пример #56
0
def step_see_data_deleted(context):
    """Wait to see delete output."""
    wrappers.expect_exact(context, 'Query OK, 1 row affected', timeout=2)
Пример #57
0
def step_see_table_dropped(context):
    """Wait to see drop output."""
    wrappers.expect_exact(context, 'Query OK, 0 rows affected', timeout=2)
Пример #58
0
def step_see_named_query_executed(context):
    """
    Wait to see select output.
    """
    wrappers.expect_exact(context, '12345', timeout=1)
    wrappers.expect_exact(context, 'SELECT 1', timeout=1)