Exemple #1
0
def test_bpython(pystartup):
    parser = setup_parser()
    args = parser.parse_args(['shell', '--interface', 'bpython'])

    with patch('bpython.embed') as embed:
        Shell.main(args)

    _, kwargs = embed.call_args
    local = kwargs['locals_']
    assert 'n' in local.keys()
    assert local['foo'] == 42
    local['n'].disconnect()
Exemple #2
0
def test_plain_fallback(pystartup):
    parser = setup_parser()
    args = parser.parse_args(['shell', '--interface', 'bpython'])

    with patch('nameko.cli.shell.code') as code:
        Shell.main(args)

    _, kwargs = code.interact.call_args
    local = kwargs['local']
    assert 'n' in local.keys()
    assert local['foo'] == 42
    local['n'].disconnect()
Exemple #3
0
def test_uses_plain_when_not_tty(pystartup, rabbit_config, isatty):
    parser = setup_parser()
    args = parser.parse_args([
        'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY],
        '--interface', 'ipython'
    ])

    isatty.return_value = False

    with patch('nameko.cli.shell.code') as code:
        Shell.main(args)

    assert code.interact.called
Exemple #4
0
def test_basic(pystartup, rabbit_config):
    parser = setup_parser()
    args = parser.parse_args([
        'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY]
    ])

    with patch("nameko.cli.shell.code") as code:
        Shell.main(args)

    _, kwargs = code.interact.call_args
    local = kwargs['local']
    assert 'n' in local.keys()
    assert local['foo'] == 42
    local['n'].disconnect()
Exemple #5
0
def test_ipython(pystartup, rabbit_config):
    parser = setup_parser()
    args = parser.parse_args([
        'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY], '--interface',
        'ipython'
    ])

    with patch('IPython.embed') as embed:
        Shell.main(args)

    _, kwargs = embed.call_args
    local = kwargs['user_ns']
    assert 'n' in local.keys()
    assert local['foo'] == 42
    local['n'].disconnect()
Exemple #6
0
    def test_broker_as_param(self):

        amqp_uri = "amqp://broker/param"

        parser = setup_parser()
        args = parser.parse_args(['shell', '--broker', amqp_uri])

        with patch('nameko.cli.shell.ShellRunner') as shell_runner:
            Shell.main(args)

        expected_message = (
            "Broker: {}".format(amqp_uri)
        )
        (banner, _), _ = shell_runner.call_args
        assert expected_message in banner
Exemple #7
0
def test_plain_fallback(pystartup, rabbit_config):
    parser = setup_parser()
    args = parser.parse_args([
        'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY], '--interface',
        'bpython'
    ])

    with patch('nameko.cli.shell.code') as code:
        Shell.main(args)

    _, kwargs = code.interact.call_args
    local = kwargs['local']
    assert 'n' in local.keys()
    assert local['foo'] == 42
    local['n'].disconnect()
Exemple #8
0
    def test_broker_as_param(self):

        amqp_uri = "amqp://broker/param"

        parser = setup_parser()
        args = parser.parse_args(['shell', '--broker', amqp_uri])

        with patch('nameko.cli.shell.ShellRunner') as shell_runner:
            Shell.main(args)

        expected_message = (
            "Broker: {}".format(amqp_uri)
        )
        (banner, _), _ = shell_runner.call_args
        assert expected_message in banner
Exemple #9
0
def test_ipython(pystartup, rabbit_config):
    parser = setup_parser()
    args = parser.parse_args([
        'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY],
        '--interface', 'ipython'
    ])

    with patch('IPython.embed') as embed:
        Shell.main(args)

    _, kwargs = embed.call_args
    local = kwargs['user_ns']
    assert 'n' in local.keys()
    assert local['foo'] == 42
    local['n'].disconnect()
Exemple #10
0
def test_config(pystartup):
    parser = setup_parser()
    args = parser.parse_args(['shell', '--config', TEST_CONFIG_FILE])

    with patch('nameko.cli.shell.code') as code:
        Shell.main(args)

    _, kwargs = code.interact.call_args
    local = kwargs['local']
    assert 'n' in local.keys()
    assert local['n'].config == {
        WEB_SERVER_CONFIG_KEY: '0.0.0.0:8001',
        AMQP_URI_CONFIG_KEY: 'amqp://*****:*****@localhost',
        SERIALIZER_CONFIG_KEY: 'json'
    }
    local['n'].disconnect()
Exemple #11
0
def test_bpython(pystartup, rabbit_config, isatty):
    parser = setup_parser()
    args = parser.parse_args([
        'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY],
        '--interface', 'bpython'
    ])

    isatty.return_value = True

    with patch('bpython.embed') as embed:
        Shell.main(args)

    _, kwargs = embed.call_args
    local = kwargs['locals_']
    assert 'n' in local.keys()
    assert local['foo'] == 42
    local['n'].disconnect()
Exemple #12
0
def test_bpython(pystartup, rabbit_config, isatty):
    parser = setup_parser()
    args = parser.parse_args([
        'shell', '--broker', rabbit_config[AMQP_URI_CONFIG_KEY], '--interface',
        'bpython'
    ])

    isatty.return_value = True

    with patch('bpython.embed') as embed:
        Shell.main(args)

    _, kwargs = embed.call_args
    local = kwargs['locals_']
    assert 'n' in local.keys()
    assert local['foo'] == 42
    local['n'].disconnect()
Exemple #13
0
    def test_broker_from_config(self, tmpdir):

        amqp_uri = "amqp://broker/config"

        config = tmpdir.join('config.yaml')
        config.write("""
            WEB_SERVER_ADDRESS: '0.0.0.0:8001'
            AMQP_URI: '{}'
            serializer: 'json'
        """.format(amqp_uri))

        parser = setup_parser()
        args = parser.parse_args(['shell', '--config', config.strpath])

        with patch('nameko.cli.shell.ShellRunner') as shell_runner:
            Shell.main(args)

        expected_message = ("Broker: {} (from --config)".format(amqp_uri))
        (banner, _), _ = shell_runner.call_args
        assert expected_message in banner
Exemple #14
0
    def test_broker_from_config(self, tmpdir):

        amqp_uri = "amqp://broker/config"

        config = tmpdir.join('config.yaml')
        config.write("""
            WEB_SERVER_ADDRESS: '0.0.0.0:8001'
            AMQP_URI: '{}'
            serializer: 'json'
        """.format(amqp_uri))

        parser = setup_parser()
        args = parser.parse_args(['shell', '--config', config.strpath])

        with patch('nameko.cli.shell.ShellRunner') as shell_runner:
            Shell.main(args)

        expected_message = (
            "Broker: {} (from --config)".format(amqp_uri)
        )
        (banner, _), _ = shell_runner.call_args
        assert expected_message in banner
Exemple #15
0
def test_config(pystartup, rabbit_config, tmpdir):

    config = tmpdir.join('config.yaml')
    config.write("""
        WEB_SERVER_ADDRESS: '0.0.0.0:8001'
        AMQP_URI: '{}'
        serializer: 'json'
    """.format(rabbit_config[AMQP_URI_CONFIG_KEY]))

    parser = setup_parser()
    args = parser.parse_args(['shell', '--config', config.strpath])

    with patch('nameko.cli.shell.code') as code:
        Shell.main(args)

    _, kwargs = code.interact.call_args
    local = kwargs['local']
    assert 'n' in local.keys()
    assert local['n'].config == {
        WEB_SERVER_CONFIG_KEY: '0.0.0.0:8001',
        AMQP_URI_CONFIG_KEY: rabbit_config[AMQP_URI_CONFIG_KEY],
        SERIALIZER_CONFIG_KEY: 'json'
    }
    local['n'].disconnect()
Exemple #16
0
def test_config(pystartup, rabbit_config, tmpdir):

    config = tmpdir.join('config.yaml')
    config.write("""
        WEB_SERVER_ADDRESS: '0.0.0.0:8001'
        AMQP_URI: '{}'
        serializer: 'json'
    """.format(rabbit_config[AMQP_URI_CONFIG_KEY]))

    parser = setup_parser()
    args = parser.parse_args(['shell', '--config', config.strpath])

    with patch('nameko.cli.shell.code') as code:
        Shell.main(args)

    _, kwargs = code.interact.call_args
    local = kwargs['local']
    assert 'n' in local.keys()
    assert local['n'].config == {
        WEB_SERVER_CONFIG_KEY: '0.0.0.0:8001',
        AMQP_URI_CONFIG_KEY: rabbit_config[AMQP_URI_CONFIG_KEY],
        SERIALIZER_CONFIG_KEY: 'json'
    }
    local['n'].disconnect()