Skip to content

Commit

Permalink
Merge pull request #451 from mattbennett/fix-banner-nameko-on-shell
Browse files Browse the repository at this point in the history
Fix banner nameko on shell
  • Loading branch information
mattbennett committed Jun 30, 2017
2 parents 428dd24 + 020a232 commit a6d2f84
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
14 changes: 9 additions & 5 deletions nameko/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,21 @@ def make_nameko_helper(config):


def main(args):
banner = 'Nameko Python %s shell on %s\nBroker: %s' % (
sys.version,
sys.platform,
args.broker.encode('utf-8'),
)

if args.config:
with open(args.config) as fle:
config = yaml.load(fle)
broker_from = " (from --config)"
else:
config = {AMQP_URI_CONFIG_KEY: args.broker}
broker_from = ""

banner = 'Nameko Python %s shell on %s\nBroker: %s%s' % (
sys.version,
sys.platform,
config[AMQP_URI_CONFIG_KEY],
broker_from
)

ctx = {}
ctx['n'] = make_nameko_helper(config)
Expand Down
47 changes: 47 additions & 0 deletions test/cli/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,50 @@ def test_config(pystartup, rabbit_config, tmpdir):
SERIALIZER_CONFIG_KEY: 'json'
}
local['n'].disconnect()


class TestBanner(object):

@pytest.yield_fixture(autouse=True)
def patch_nameko_helper(self):
with patch('nameko.cli.shell.make_nameko_helper'):
yield

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

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

0 comments on commit a6d2f84

Please sign in to comment.