def test_show(capsys, parser): args = parser.parse_args(['show', 'router1']) cli.setup(args) args.command(args) out, err = capsys.readouterr() assert out == dumps(args.settings.routers[0]) + '\n' assert err == ''
def test_check(capsys, parser): args = parser.parse_args(['check', 'router1']) cli.setup(args) rc = args.command(args) assert rc == 0 out, err = capsys.readouterr() assert out == '' assert err == ''
def test_edit(tmpdir, parser): path = tmpdir.join('edit1.json') path.write(data=json.dumps({'compile_rules': False}), ensure=True) args = parser.parse_args(['edit', 'router2', str(path)]) cli.setup(args) args.command(args) path = tmpdir.join('edit2.json') path.write(data=json.dumps({'compile_rules': True}), ensure=True) args = parser.parse_args(['edit', 'router2', str(path)]) cli.setup(args) args.command(args)
def test_list(capsys, parser): args = parser.parse_args(['list']) cli.setup(args) args.command(args) out, err = capsys.readouterr() assert out == '\n'.join([ 'router1', 'router2', 'router3', '', ]) assert err == ''
def test_eval(capsys, tmpdir, parser, requests_path): requests = tmpdir.join('requests.http') for request_path in requests_path.listdir(): requests.write(request_path.read(), ensure=True) args = parser.parse_args(['eval', '-r', str(requests)]) cli.setup(args) args.command(args) out, _ = capsys.readouterr() assert out == '\n'.join([ 'https://www.google.com', 'https://www.yahoo.com', 'http://dev.google.com', '', ])
def test_watch(capsys, tmpdir, parser): def _watch(): args = parser.parse_args(['watch', 'router2', '-n', '1', '-t', '10']) cli.setup(args) args.command(args) thd = threading.Thread(target=_watch) thd.start() time.sleep(1.0) path = tmpdir.join('edit1.json') path.write(data=json.dumps({'compile_rules': False}), ensure=True) args = parser.parse_args(['edit', 'router2', str(path)]) cli.setup(args) args.command(args) thd.join() out, _ = capsys.readouterr() assert out == 'router changed - router2\n'
def _watch(): args = parser.parse_args(['watch', 'router2', '-n', '1', '-t', '10']) cli.setup(args) args.command(args)
def _serve(): args = parser.parse_args(['serve']) cli.setup(args) with mock.patch('rump.cli.server_for') as patched: patched.return_value = server args.command(args)