Esempio n. 1
0
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 == ''
Esempio n. 2
0
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 == ''
Esempio n. 3
0
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)
Esempio n. 4
0
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 == ''
Esempio n. 5
0
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',
        '',
    ])
Esempio n. 6
0
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'
Esempio n. 7
0
 def _watch():
     args = parser.parse_args(['watch', 'router2', '-n', '1', '-t', '10'])
     cli.setup(args)
     args.command(args)
Esempio n. 8
0
 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)