Пример #1
0
def test_hostname_three_arguments(MockAerohive):
    username = "******"
    password = "******"
    aerohive = MockAerohive()
    aerohive.addUser(username, password)
    port = aerohive.run("127.0.0.1")

    connection = pexpect.spawn("ssh -o UserKnownHostsFile=/dev/null \"" +
                               username + "@" + "127.0.0.1\" -p " + str(port),
                               timeout=5)
    connection.expect_exact("continue connecting (yes/no)? ")
    connection.sendline("yes")
    connection.expect_exact("assword: ")
    connection.sendline(password)
    connection.expect_exact(aerohive.prompt())
    connection.sendline("hostname example-1")
    connection.expect_exact("example-1#")

    connection.expect_exact("example-1#")
    connection.sendline("hostname example-2 random-text")
    #        example-1#hostname example-2 random-text
    error = "                             ^-- unknown keyword or invalid input"
    connection.expect_exact(error)

    connection.expect_exact(aerohive.prompt())
    connection.sendline("exit")
    connection.expect_exact("closed.")
    connection.expect_exact(pexpect.EOF)
def test_incomplete_command(command, MockAerohive):
    username = "******"
    password = "******"
    aerohive = MockAerohive()
    aerohive.addUser(username, password)
    port = aerohive.run("127.0.0.1")

    connection = pexpect.spawn("ssh -o UserKnownHostsFile=/dev/null \"" +
                               username + "@" + "127.0.0.1\" -p " + str(port),
                               timeout=5)
    connection.expect_exact("continue connecting (yes/no)? ")
    connection.sendline("yes")
    connection.expect_exact("assword: ")
    connection.sendline(password)
    connection.expect_exact(aerohive.prompt())
    connection.sendline(command)
    connection.expect_exact(INCOMPLETE_COMMAND)
    connection.expect_exact(aerohive.prompt())
    connection.sendline("exit")
    connection.expect_exact("closed.")
    connection.expect_exact(pexpect.EOF)
def test_completely_wrong(MockAerohive):
    username = "******"
    password = "******"
    aerohive = MockAerohive()
    aerohive.addUser(username, password)
    aerohive.commands.append(add_foobar(aerohive))

    connection = connect_set_prompt(aerohive, username, password, "example-1")

    connection.expect_exact("example-1#")
    connection.sendline("foobar foob1")
    #        example-1#foobar z
    error = "                 ^-- unknown keyword or invalid input"
    connection.expect_exact(error)

    connection.expect_exact(aerohive.prompt())
    connection.sendline("exit")
    connection.expect_exact("closed.")
    connection.expect_exact(pexpect.EOF)