示例#1
0
    def test_connect_does_not_prompt_password_when_ssh_raises_channel_exception(self):
        def raise_channel_exception_once(*args, **kwargs):
            if raise_channel_exception_once.should_raise_channel_exception:
                raise_channel_exception_once.should_raise_channel_exception = False
                raise ssh.ChannelException(2, 'Connect failed')
        raise_channel_exception_once.should_raise_channel_exception = True

        def generate_fake_client():
            fake_client = Fake('SSHClient', allows_any_call=True, expect_call=True)
            fake_client.provides('connect').calls(raise_channel_exception_once)
            return fake_client

        fake_ssh = Fake('ssh', allows_any_call=True)
        fake_ssh.provides('SSHClient').calls(generate_fake_client)
        # We need the real exceptions here to preserve the inheritence structure
        fake_ssh.SSHException = ssh.SSHException
        fake_ssh.ChannelException = ssh.ChannelException
        patched_connect = patch_object('fabric.network', 'ssh', fake_ssh)
        patched_password = patch_object('fabric.network', 'prompt_for_password', Fake('prompt_for_password', callable = True).times_called(0))
        try:
            connect('user', 'localhost', 22, HostConnectionCache())
        finally:
            # Restore ssh
            patched_connect.restore()
            patched_password.restore()
示例#2
0
    def test_connect_does_not_prompt_password_when_ssh_raises_channel_exception(
            self):
        def raise_channel_exception_once(*args, **kwargs):
            if raise_channel_exception_once.should_raise_channel_exception:
                raise_channel_exception_once.should_raise_channel_exception = False
                raise ssh.ChannelException(2, 'Connect failed')

        raise_channel_exception_once.should_raise_channel_exception = True

        def generate_fake_client():
            fake_client = Fake('SSHClient',
                               allows_any_call=True,
                               expect_call=True)
            fake_client.provides('connect').calls(raise_channel_exception_once)
            return fake_client

        fake_ssh = Fake('ssh', allows_any_call=True)
        fake_ssh.provides('SSHClient').calls(generate_fake_client)
        # We need the real exceptions here to preserve the inheritence structure
        fake_ssh.SSHException = ssh.SSHException
        fake_ssh.ChannelException = ssh.ChannelException
        patched_connect = patch_object('fabric.network', 'ssh', fake_ssh)
        patched_password = patch_object(
            'fabric.network', 'prompt_for_password',
            Fake('prompt_for_password', callable=True).times_called(0))
        try:
            connect('user', 'localhost', 22, HostConnectionCache())
        finally:
            # Restore ssh
            patched_connect.restore()
            patched_password.restore()
示例#3
0
def test_wrapped_column_has_sort_url():
    meta = Fake().has_attr(order_by="nu")
    table = Fake().has_attr(_meta=meta)
    column_a = Fake().has_attr(name="nu")
    column_b = Fake().has_attr(name="xi")

    # mock out url building, to avoid awakening django.
    table.provides("get_url").calls(lambda order_by: ["omicron", order_by])

    wrapped_column_a = WrappedColumn(table, column_a)
    wrapped_column_b = WrappedColumn(table, column_b)

    assert wrapped_column_a.sort_url == ["omicron", "-nu"]
    assert wrapped_column_b.sort_url == ["omicron", "xi"]
示例#4
0
def test_wrapped_column_has_sort_url():
    meta = Fake().has_attr(order_by="nu")
    table = Fake().has_attr(_meta=meta)
    column_a = Fake().has_attr(name="nu")
    column_b = Fake().has_attr(name="xi")

    # mock out url building, to avoid awakening django.
    table.provides("get_url").calls(lambda order_by: ["omicron", order_by])

    wrapped_column_a = WrappedColumn(table, column_a)
    wrapped_column_b = WrappedColumn(table, column_b)

    assert wrapped_column_a.sort_url == ["omicron", "-nu"]
    assert wrapped_column_b.sort_url == ["omicron", "xi"]
示例#5
0
 def generate_fake_client():
     fake_client = Fake('SSHClient', allows_any_call=True, expect_call=True)
     fake_client.provides('connect').calls(raise_channel_exception_once)
     return fake_client
示例#6
0
 def generate_fake_client():
     fake_client = Fake('SSHClient',
                        allows_any_call=True,
                        expect_call=True)
     fake_client.provides('connect').calls(raise_channel_exception_once)
     return fake_client